def task_id_edit(_id=None): task_id_form = TaskIDForm() task_id_query = TaskId.objects.get_or_404(_id=_id) if task_id_form.validate_on_submit(): data = task_id_form.data data_count = Specie.objects(srr_id=data["srr_id"]).count() if data_count == 0: TaskId.objects(task_id=_id).update_one(set__srr_id=data["srr_id"]) TaskId.objects(task_id=_id).update_one(set__email=data["email"]) TaskId.objects(task_id=_id).update_one( set__task_time=datetime.now()) flash("edit done !", "ok") return redirect(url_for("admin.task_id_edit", _id=_id)) elif data_count == 1 and task_id_query.srr_id != data["srr_id"]: flash("this task is already exist !", "err") return redirect(url_for("admin.task_id_edit", _id=_id)) elif data_count == 1 and task_id_query.srr_id == data["srr_id"]: TaskId.objects(task_id=_id).update_one(set__email=data["email"]) TaskId.objects(task_id=_id).update_one( set__task_time=datetime.now()) flash("edit done !", "ok") return redirect(url_for("admin.task_id_edit", _id=_id)) return render_template("admin/task_id_edit.html", form=task_id_form, task_id=task_id_query)
def database(): database_form = DatabaseForm() if database_form.validate_on_submit(): data = database_form.data query = data["query"] res = [] each = {} if data["select"] == "specie": query_data = Specie.objects(kegg_id=query) for item in query_data: each["kegg_id"] = item.kegg_id each["specie_name"] = item.specie_name res.append(each) return render_template("home/database.html", form=database_form, res=res, type="specie") else: query_data = SrrTask.objects(_id__icontains=query) for item in query_data: each["_id"] = item._id each["kegg_id"] = item.kegg_id each["method"] = item.method res.append(each) query_data2 = SrrTask.objects(kegg_id=query) for item in query_data2: each["_id"] = item._id each["kegg_id"] = item.kegg_id each["method"] = item.method each["browse_link"] = item.browse_link res.append(each) return render_template("home/database.html", form=database_form, res=res, type="srr_task") return render_template("home/database.html", form=database_form, res=None, type=None)
def specie_edit(_id=None): specie_form = SpecieForm() specie_query = Specie.objects.get_or_404(kegg_id=_id) if specie_form.validate_on_submit(): data = specie_form.data old_path = specie_query.gff_path Specie.objects(kegg_id=_id).update_one( set__specie_name=data["specie_name"]) Specie.objects(kegg_id=_id).update_one(set__gff_path=data["save_path"]) if not os.path.exists(data["save_path"]): os.makedirs(data["save_path"]) os.system("mv " + old_path + " " + data["save_path"]) Specie.objects(kegg_id=_id).update_one(set__add_time=datetime.now()) flash("edit done !", "ok") return redirect(url_for("admin.specie_edit", _id=_id)) return render_template("admin/specie_edit.html", form=specie_form, specie=specie_query)
def specie_add(): specie_form = SpecieForm() if specie_form.validate_on_submit(): data = specie_form.data f = specie_form.gff_file.data filename = secure_filename(f.filename) save_path = os.path.join(data["save_path"], "gff_file", filename) if not os.path.exists(data["save_path"]): os.system("mkdir " + data["save_path"]) if not os.path.exists(os.path.join(data["save_path"], "gff_file")): os.system("mkdir " + os.path.join(data["save_path"], "gff_file")) f.save(save_path) new_specie = Specie(kegg_id=data["kegg_id"], specie_name=data["specie_name"], gff_path=data["save_path"], add_time=datetime.now()) new_specie.get_genes_from_file(save_path) new_specie.save() flash("this specie is added !", "ok") return redirect(url_for("admin.specie_add")) return render_template("admin/specie_add.html", form=specie_form)
def validate_kegg_id(self, field): kegg_id = field.data kegg_id_count = Specie.objects(kegg_id=kegg_id).count() if kegg_id_count > 0: raise ValidationError("WRONG! This specie is already exist !")
def specie(page=None): if page is None: page = 1 page_data = Specie.objects().paginate(page=page, per_page=10) return render_template("admin/specie.html", page_data=page_data)
def specie_gene(_id=None, page=None): if page is None: page = 1 specie_query = Specie.objects(kegg_id=_id).first() page_data = specie_query.paginate_field("genes", page=page, per_page=50) return render_template("admin/specie_gene.html", page_data=page_data)
def specie_del(_id=None): Specie.objects(kegg_id=_id).delete() flash("delete it done !", "ok") return redirect(url_for("admin.specie"))