示例#1
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")
示例#2
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)