Пример #1
0
def get_viewer_html(id_res):
    """
    Get HTML file with offline interactive viewer inside

    :param id_res: job id
    :type id_res: str
    """
    paf = os.path.join(APP_DATA, id_res, "map.paf")
    idx1 = os.path.join(APP_DATA, id_res, "query.idx")
    idx2 = os.path.join(APP_DATA, id_res, "target.idx")

    paf = Paf(paf, idx1, idx2)

    if paf.parsed:
        res = paf.get_d3js_data()
        res["success"] = True
        percents = paf.get_summary_stats()
        with open(
                os.path.join(app_folder, "static", "js",
                             "dgenies-offline-result.min.js"), "r") as js_min:
            js = js_min.read()
        with open(
                os.path.join(app_folder, "static", "css",
                             "dgenies-offline-result.min.css"),
                "r") as css_min:
            css = css_min.read()
        return render_template("map_offline.html",
                               json=json.dumps(res),
                               version=VERSION,
                               js=js,
                               css=css,
                               percents=percents)
    return abort(403)
Пример #2
0
def summary(id_res):
    """
    Get Dot plot summary data

    :param id_res: job id
    :type id_res: str
    """
    paf_file = os.path.join(APP_DATA, id_res, "map.paf")
    idx1 = os.path.join(APP_DATA, id_res, "query.idx")
    idx2 = os.path.join(APP_DATA, id_res, "target.idx")
    try:
        paf = Paf(paf_file, idx1, idx2, False)
    except FileNotFoundError:
        return jsonify({"success": False, "message": "Unable to load data!"})
    percents = None
    s_status = "waiting"  # Accepted values: waiting, done, fail
    status_file = os.path.join(APP_DATA, id_res, ".summarize")
    fail_file = status_file + ".fail"
    if not os.path.exists(status_file):  # The job is finished or not started
        if not os.path.exists(
                fail_file
        ):  # The job has not started yet or has successfully ended
            percents = paf.get_summary_stats()
            if percents is None:  # The job has not started yet
                Path(status_file).touch()
                thread = threading.Timer(0,
                                         paf.build_summary_stats,
                                         kwargs={"status_file": status_file})
                thread.start()
            else:  # The job has successfully ended
                s_status = "done"
        else:  # The job has failed
            s_status = "fail"

    if s_status == "waiting":  # The job is running
        # Check if the job end in the next 30 seconds
        nb_iter = 0
        while os.path.exists(status_file) and not os.path.exists(
                fail_file) and nb_iter < 10:
            time.sleep(3)
            nb_iter += 1
        if not os.path.exists(status_file):  # The job has ended
            percents = paf.get_summary_stats()
            if percents is None:  # The job has failed
                s_status = "fail"
            else:  # The job has successfully ended
                s_status = "done"

    if s_status == "fail":
        return jsonify({
            "success":
            False,
            "message":
            "Build of summary failed. Please contact us to report the bug"
        })
    return jsonify({"success": True, "percents": percents, "status": s_status})
Пример #3
0
def build_query_as_reference(id_res):
    """
    Build fasta of query with contigs order like reference

    :param id_res: job id
    :type id_res: str
    """
    paf_file = os.path.join(APP_DATA, id_res, "map.paf")
    idx1 = os.path.join(APP_DATA, id_res, "query.idx")
    idx2 = os.path.join(APP_DATA, id_res, "target.idx")
    paf = Paf(paf_file, idx1, idx2, False, mailer=mailer, id_job=id_res)
    paf.parse_paf(False, True)
    if MODE == "webserver":
        thread = threading.Timer(0, paf.build_query_chr_as_reference)
        thread.start()
        return True
    return paf.build_query_chr_as_reference()
Пример #4
0
def free_noise(id_res):
    """
    Remove noise from the dot plot

    :param id_res: job id
    :type id_res: str
    """
    paf_file = os.path.join(APP_DATA, id_res, "map.paf")
    idx1 = os.path.join(APP_DATA, id_res, "query.idx")
    idx2 = os.path.join(APP_DATA, id_res, "target.idx")
    paf = Paf(paf_file, idx1, idx2, False)
    paf.parse_paf(noise=request.form["noise"] == "1")
    if paf.parsed:
        res = paf.get_d3js_data()
        res["success"] = True
        return jsonify(res)
    return jsonify({"success": False, "message": paf.error})
Пример #5
0
def get_graph():
    """
    Get dot plot data for a job
    """
    id_f = request.form["id"]
    paf = os.path.join(APP_DATA, id_f, "map.paf")
    idx1 = os.path.join(APP_DATA, id_f, "query.idx")
    idx2 = os.path.join(APP_DATA, id_f, "target.idx")

    paf = Paf(paf, idx1, idx2)

    if paf.parsed:
        valid = os.path.join(APP_DATA, id_f, ".valid")
        if not os.path.exists(valid):
            Path(valid).touch()
        res = paf.get_d3js_data()
        res["success"] = True
        return jsonify(res)
    return jsonify({"success": False, "message": paf.error})
Пример #6
0
def no_assoc(id_res):
    """
    Get contigs that match with None target

    :param id_res: job id
    :type id_res: str
    """
    res_dir = os.path.join(APP_DATA, id_res)
    if os.path.exists(res_dir) and os.path.isdir(res_dir):
        paf_file = os.path.join(APP_DATA, id_res, "map.paf")
        idx1 = os.path.join(APP_DATA, id_res, "query.idx")
        idx2 = os.path.join(APP_DATA, id_res, "target.idx")
        try:
            paf = Paf(paf_file, idx1, idx2, False)
        except FileNotFoundError:
            print("Unable to load data!")
            abort(404)
            return False
        file_content = paf.build_list_no_assoc(request.form["to"])
        empty = file_content == "\n"
        return jsonify({"file_content": file_content, "empty": empty})
    abort(404)
Пример #7
0
def qt_assoc(id_res):
    """
    Query - Target association TSV file

    :param id_res:
    :return:
    """
    res_dir = os.path.join(APP_DATA, id_res)
    if os.path.exists(res_dir) and os.path.isdir(res_dir):
        paf_file = os.path.join(APP_DATA, id_res, "map.paf")
        idx1 = os.path.join(APP_DATA, id_res, "query.idx")
        idx2 = os.path.join(APP_DATA, id_res, "target.idx")
        try:
            paf = Paf(paf_file, idx1, idx2, False)
            paf.parse_paf(False)
        except FileNotFoundError:
            print("Unable to load data!")
            abort(404)
            return False
        csv_content = paf.build_query_on_target_association_file()
        return Response(csv_content, mimetype="text/plain")
    abort(404)
Пример #8
0
def sort_graph(id_res):
    """
    Sort dot plot to referene

    :param id_res: job id
    :type id_res: str
    """
    if not os.path.exists(os.path.join(APP_DATA, id_res, ".all-vs-all")):
        paf_file = os.path.join(APP_DATA, id_res, "map.paf")
        idx1 = os.path.join(APP_DATA, id_res, "query.idx")
        idx2 = os.path.join(APP_DATA, id_res, "target.idx")
        paf = Paf(paf_file, idx1, idx2, False)
        paf.sort()
        if paf.parsed:
            res = paf.get_d3js_data()
            res["success"] = True
            return jsonify(res)
        return jsonify({"success": False, "message": paf.error})
    return jsonify({
        "success": False,
        "message": "Sort is not available for All-vs-All mode"
    })
Пример #9
0
def reverse_contig(id_res):
    """
    Reverse contig order

    :param id_res: job id
    :type id_res: str
    """
    contig_name = request.form["contig"]
    if not os.path.exists(os.path.join(APP_DATA, id_res, ".all-vs-all")):
        paf_file = os.path.join(APP_DATA, id_res, "map.paf")
        idx1 = os.path.join(APP_DATA, id_res, "query.idx")
        idx2 = os.path.join(APP_DATA, id_res, "target.idx")
        paf = Paf(paf_file, idx1, idx2, False)
        paf.reverse_contig(contig_name)
        if paf.parsed:
            res = paf.get_d3js_data()
            res["success"] = True
            return jsonify(res)
        return jsonify({"success": False, "message": paf.error})
    return jsonify({
        "success": False,
        "message": "Sort is not available for All-vs-All mode"
    })
Пример #10
0
plotdots = snakemake.params["pixels"]

paths = []
idxs = []
for i in (snakemake.input["query"], snakemake.input["reference"]):
    dir = os.path.dirname(i)
    file = os.path.basename(i)
    print(f'Indexing {dir}/{file}...')
    (success, numctgs, err) = index_file(dir, file, file + ".idx")
    if not success:
        print(err)
        sys.exit(-1)
    else:
        paths.append(dir)
        idxs.append(file)

# Load data structures

paf_file = snakemake.input["paf"]
idx1 = os.path.join(paths[0], idxs[0])
idx2 = os.path.join(paths[1], idxs[1])
paf = Paf(paf_file, idx1, idx2, False)
paf.sort()

# Calculate values for matrix
asize1 = map(sum, Index.load(idx1)[2])
asize2 = map(sum, Index.load(idx2)[2])

awinsize1 = asize1 / plotdots
awinsize2 = asize2 / plotdots