示例#1
0
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)
示例#2
0
def srr_task_nums(_id=None, page=None):
    if page is None:
        page = 1
    srr_task_query = SrrTask.objects(_id=_id).first()
    page_data = srr_task_query.paginate_field("srr_nums",
                                              page=page,
                                              per_page=50)
    return render_template("admin/srr_task_nums.html", page_data=page_data)
示例#3
0
def operon_predict(srr_list, kegg_id, soft, method, corr, srr_id):
    if len(srr_list) == 1:
        soft = "rockhopper"
    all_srr_list = []
    paired_or_not_list = []
    download_path_list = []
    i_iter = 0
    for con in srr_list:
        condition_path = os.path.join(path, srr_id, "fastq", "c" + str(i_iter))
        if not os.path.exists(condition_path):
            os.makedirs(condition_path)
        for rep in con:
            tmp_ = get_paired_or_singled(rep)
            if tmp_ == 0:
                soft = "rockhopper"
            paired_or_not_list.append(tmp_)
            all_srr_list.append(rep)
            download_path_list.append(condition_path)
        i_iter = i_iter + 1

    pool = Pool(process)
    _list = pool.starmap(srr_n_to_fastq, zip(all_srr_list, paired_or_not_list, download_path_list))
    pool.close()
    pool.join()
    kegg_path = download_annotation(kegg_id, path)
    browse_link = "http://" + "127.0.0.1" + "/JBrowse/?data=" + srr_id
    if soft == "rockhopper":
        condition_str = get_condition_str_rockhopper(download_path_list, paired_or_not_list, all_srr_list)
        rockhopper_path = os.path.join(path, "tools", "Rockhopper.jar")
        out_path = os.path.join(path, srr_id, "operon")
        os.system("java -Xmx3g -cp " + rockhopper_path + " Rockhopper -p " + str(process) + " -g " + kegg_path + " " +
                  condition_str + " -o " + out_path)
        extract_Synonym(kegg_path, out_path)
        get_operon(out_path)
        new_srr_task = SrrTask(_id=srr_id, kegg_id=kegg_id, operon_path="/instance/" + srr_id +
                               "/operon/operon.txt", method="rockhopper",
                               add_time=datetime.now(), bw_path="/instance/" + srr_id +
                               "/operon/operon.txt", browse_link=browse_link)
        new_srr_task.get_srr_nums(srr_list)
        new_srr_task.get_operons_from_file(os.path.join(out_path, "operon.txt"))
        new_srr_task.save()
        res2jbrowse(kegg_path, out_path, srr_id)
    else:
        input_path = os.path.join(path, "fastq")
        fna_path = os.path.join(kegg_path, kegg_id + ".fna")
        gff_path = os.path.join(kegg_path, kegg_id + ".gff")
        out_path = os.path.join(path, srr_id, "operon")
        print(input_path,fna_path,gff_path,out_path)
        if corr == "c_i_j":
            os.system("operondemmo -i " + input_path + " -g " + gff_path + " -f " + fna_path
                      + " -m " + method + " -p " + str(process) + " -t 0.6 " + " -o " + out_path)
        elif corr == "spearman":
            os.system("operondemmo -i " + input_path + " -g " + gff_path + " -f " + fna_path
                      + " -m " + method + " -p " + str(process) + " -t 0.6 " + " -o " + out_path + " --spearman")
        else:
            os.system("operondemmo -i " + input_path + " -g " + gff_path + " -f " + fna_path
                      + " -m " + method + " -p " + str(process) + " -t 0.6 " + " -o " + out_path + " --person")
        new_srr_task = SrrTask(_id=srr_id, kegg_id=kegg_id, operon_path="/instance/" + srr_id +
                               "/operon/operon.txt", method=method,
                               add_time=datetime.now(), bw_path="/instance/" + srr_id +
                               "/operon/operon.txt", browse_link=browse_link)
        new_srr_task.get_srr_nums(srr_list)
        new_srr_task.get_operons_from_file(os.path.join(out_path, "operon.txt"))
        new_srr_task.save()
        res2jbrowse(kegg_path, out_path, srr_id)
    task_query = TaskId.objects.get_or_404(srr_id=srr_id)
    msg = Message("OperondemmoDB Task", sender=sender, recipients=[task_query.email])
    msg.body = "your task link: " + self_link + "/task/" + task_query.task_id
    send_async_email(app, msg)
    print("send it OK")
示例#4
0
def srr_task_del(_id=None):
    SrrTask.objects(_id=_id).delete()
    flash("delete it done !", "ok")
    return redirect(url_for("admin.srr_task"))
示例#5
0
def srr_task_edit(_id=None):
    srr_task_form = SrrTaskForm()
    srr_task_query = SrrTask.objects.get_or_404(_id=_id)
    old_bw_path = srr_task_query.bw_path
    old_operon_path = srr_task_query.operon_path
    if srr_task_form.validate_on_submit():
        data = srr_task_form.data
        SrrTask.objects(_id=_id).update_one(set__kegg_id=data["kegg_id"])
        SrrTask.objects(_id=_id).update_one(
            set__browse_link=data["browse_link"])
        SrrTask.objects(_id=_id).update_one(set__bw_path=data["bw_path"])
        SrrTask.objects(_id=_id).update_one(
            set__operon_path=data["operon_path"])
        SrrTask.objects(_id=_id).update_one(set__method=data["method"])
        SrrTask.objects(_id=_id).update_one(set__add_time=datetime.now())
        if not os.path.exists(data["bw_path"]):
            os.makedirs(data["bw_path"])
        os.system("mv " + old_bw_path + " " + data["bw_path"])
        if not os.path.exists(data["operon_path"]):
            os.makedirs(data["operon_path"])
        os.system("mv " + old_operon_path + " " + data["operon_path"])
        flash("edit done !", "ok")
        return redirect(url_for("admin.srr_task_edit", _id=_id))
    return render_template("admin/srr_task_edit.html",
                           form=srr_task_form,
                           srr_task=srr_task_query)
示例#6
0
def srr_task_add():
    srr_task_form = SrrTaskForm()
    if srr_task_form.condition_add.data:
        srr_task_form.condition.append_entry()
        return render_template("admin/srr_task_add.html", form=srr_task_form)
    i_iter = 0
    for con in srr_task_form.condition.entries:
        if con.condition_del.data:
            srr_task_form.condition.entries.pop(i_iter)
            return render_template("admin/srr_task_add.html",
                                   form=srr_task_form)
        if con.repeat_add.data:
            srr_task_form.condition.entries[i_iter].repeat.append_entry()
            return render_template("admin/srr_task_add.html",
                                   form=srr_task_form)
        j_iter = 0
        for rep in con.repeat.entries:
            if rep.repeat_del.data:
                srr_task_form.condition.entries[i_iter].repeat.entries.pop(
                    j_iter)
                return render_template("admin/srr_task_add.html",
                                       form=srr_task_form)
            j_iter = j_iter + 1
        i_iter = i_iter + 1

    if srr_task_form.validate_on_submit():
        data = srr_task_form.data
        all_srr = []
        srr_list = []
        for con in data["condition"]:
            srr_list.append([])
            for each in con["repeat"]:
                srr_list[-1].append(each['srr'])
                all_srr.append(each['srr'])
        all_srr = sorted(all_srr)
        srr_id = "-".join(all_srr)
        data_count = SrrTask.objects(_id=srr_id).count()
        if data_count == 1:
            flash("this srr_id is already exist !", "err")
            return redirect(url_for("admin.srr_task_add"))
        new_srr_task = SrrTask(_id=srr_id,
                               kegg_id=data["kegg_id"],
                               browse_link=data["browse_link"],
                               operon_path=data["operon_path"],
                               bw_path=data["bw_path"],
                               method=data["method"],
                               add_time=datetime.now())
        new_srr_task.get_srr_nums(srr_list)
        f = srr_task_form.operon_file.data
        filename = secure_filename(f.filename)
        save_path = os.path.join(data["operon_path"], "operon_file", filename)
        if not os.path.exists(path):
            os.system("mkdir " + path)
        if not os.path.exists(os.path.join(path, "operon_file")):
            os.system("mkdir " + os.path.join(path, "operon_file"))
        f.save(save_path)
        new_srr_task.get_operons_from_file(save_path)
        new_srr_task.save()
        flash("this srr_task is added !", "ok")
        return redirect(url_for("admin.srr_task_add"))
    return render_template("admin/srr_task_add.html", form=srr_task_form)
示例#7
0
def srr_task(page=None):
    if page is None:
        page = 1
    page_data = SrrTask.objects().paginate(page=page, per_page=10)
    return render_template("admin/srr_task.html", page_data=page_data)
示例#8
0
def index():
    submit_form = SubmitForm()
    if submit_form.condition_add.data:
        submit_form.condition.append_entry()
        return render_template("home/index.html", form=submit_form)
    i_iter = 0
    for con in submit_form.condition.entries:
        if con.condition_del.data:
            submit_form.condition.entries.pop(i_iter)
            return render_template("home/index.html", form=submit_form)
        if con.repeat_add.data:
            submit_form.condition.entries[i_iter].repeat.append_entry()
            return render_template("home/index.html", form=submit_form)
        j_iter = 0
        for rep in con.repeat.entries:
            if rep.repeat_del.data:
                submit_form.condition.entries[i_iter].repeat.entries.pop(j_iter)
                return render_template("home/index.html", form=submit_form)
            j_iter = j_iter + 1
        i_iter = i_iter + 1
    auto = ""
    if submit_form.kegg_auto.data:
        auto = "y"
    if submit_form.kegg_not_auto.data:
        auto = "n"
    if submit_form.validate_on_submit():
        data = submit_form.data
        srr_list = []
        all_srr = []
        for con in data["condition"]:
            srr_list.append([])
            for each in con["repeat"]:
                srr_list[-1].append(each['srr'])
                all_srr.append(each['srr'])
        all_srr = sorted(all_srr)
        srr_id = "-".join(all_srr)
        data_count = SrrTask.objects(_id=srr_id).count()
        if data_count == 1:
            return redirect(url_for("home.srr_id", _id=srr_id))

        new_task_id = TaskId(task_id=str(uuid.uuid1()), srr_id=srr_id, email=data["email"], task_time=datetime.now())
        new_task_id.save()

        if submit_form.gff_file.data is not None:
            gff = submit_form.gff_file.data
            gff_filename = secure_filename(gff.filename)
            gff_path = os.path.join(path, data["kegg_id"], gff_filename)
            if not os.path.exists(path):
                os.system("mkdir " + path)
            if not os.path.exists(os.path.join(path, data["kegg_id"])):
                os.system("mkdir " + os.path.join(path, data["kegg_id"]))
            gff.save(gff_path)
            fna = submit_form.fna_file.data
            fna_filename = secure_filename(fna.filename)
            fna_path = os.path.join(path, data["kegg_id"], fna_filename)
            if not os.path.exists(os.path.join(path, data["kegg_id"])):
                os.system("mkdir " + os.path.join(path, data["kegg_id"]))
            fna.save(fna_path)

        kegg_id = data["kegg_id"]
        soft = data["software_select"]
        method = data["method_select"]
        corr = data["correlation_select"]

        executor.submit(operon_predict, srr_list, kegg_id, soft, method, corr, srr_id)

        return redirect(url_for("home.wait"))

    return render_template("home/index.html", form=submit_form, auto=auto)
示例#9
0
def srr_task_operon(_id=None, page=None):
    if page is None:
        page = 1
    srr_task_query = SrrTask.objects(_id=_id).first()
    page_data = srr_task_query.paginate_field("operon", page=page, per_page=50)
    return render_template("home/srr_task_operon.html", page_data=page_data)