Commit 130f3759 authored by Floreal Cabanettes's avatar Floreal Cabanettes
Browse files

Do not use mails for standalone version: make treatments synchronous instead, Fixes #117

parent d69fba30
......@@ -58,7 +58,7 @@ class Functions:
fasta_file = None
try:
with open(os.path.join(res_dir, "." + type_f), "r") as save_name:
fasta_file = save_name.readline()
fasta_file = save_name.readline().strip("\n")
except IOError:
print(res_dir + ": Unable to load saved name for " + type_f, file=sys.stderr)
pass
......
#!/usr/bin/env python3
from dgenies import MODE
import os
import shutil
from math import sqrt
......@@ -762,12 +764,13 @@ class Paf:
o_fasta = "_._"
status="fail"
parts = os.path.basename(o_fasta).rsplit(".", 1)
Functions.send_fasta_ready(mailer=self.mailer,
job_name=self.id_job,
sample_name=parts[0],
ext=parts[1],
compressed=False,
path="download",
status=status)
if MODE == "webserver":
parts = os.path.basename(o_fasta).rsplit(".", 1)
Functions.send_fasta_ready(mailer=self.mailer,
job_name=self.id_job,
sample_name=parts[0],
ext=parts[1],
compressed=False,
path="download",
status=status)
return o_fasta
......@@ -34,7 +34,6 @@ dgenies.result.export.export_svg = function () {
dgenies.result.export.save_file(blob, "svg");
};
d3.boxplot.zoom.reset_scale(true, after);
};
dgenies.result.export.export_paf = function () {
......@@ -141,7 +140,7 @@ dgenies.result.export.export_no_association_file = function (to) {
})
};
dgenies.result.export.export_query_as_reference_fasta = function() {
dgenies.result.export.export_query_as_reference_fasta_webserver = function() {
dgenies.post(`/build-query-as-reference/${dgenies.result.id_res}`,
{},
function (data, success) {
......@@ -149,10 +148,32 @@ dgenies.result.export.export_query_as_reference_fasta = function() {
dgenies.notify("You will receive a mail soon with the link to download your Fasta file", "success")
}
else {
dgenies.notify(`An error has occurred. Please contact the support`, "fatal")
dgenies.notify(`An error has occurred. Please contact the support`, "danger")
}
});
}
};
dgenies.result.export.export_query_as_reference_fasta_standalone = function () {
dgenies.show_loading("Building file...", 180);
window.setTimeout(() => {
dgenies.post(`/build-query-as-reference/${dgenies.result.id_res}`,
{},
function (data, success) {
if (data["success"]) {
let export_div = $("div#export-pict");
export_div.html("");
export_div.append($("<a>").attr("href", `/get-query-as-reference/${dgenies.result.id_res}`)
.attr("download", `as_reference_${d3.boxplot.name_y}.fasta`)
.attr("id", "my-download").text("download"));
document.getElementById('my-download').click();
dgenies.hide_loading();
}
else {
dgenies.notify(`An error has occurred. Please contact the support`, "danger")
}
});
}, 0);
};
dgenies.result.export.export = function () {
let select = $("form#export select");
......@@ -180,7 +201,13 @@ dgenies.result.export.export = function () {
dgenies.result.export.export_no_association_file("target");
}
else if (selection === 8) {
dgenies.result.export.export_query_as_reference_fasta();
if (dgenies.result.mode === "webserver") {
dgenies.result.export.export_query_as_reference_fasta_webserver();
}
else {
dgenies.result.export.export_query_as_reference_fasta_standalone();
async = true;
}
}
else
dgenies.notify("Not supported yet!", "danger", 2000);
......
......@@ -350,7 +350,7 @@ def build_fasta(id_res):
if is_sorted and not query_fasta.endswith(".sorted"):
# Do the sort
Path(lock_query).touch()
if not compressed: # If compressed, it will took a long time, so not wait
if not compressed or MODE == "standalone": # If compressed, it will took a long time, so not wait
Path(lock_query + ".pending").touch()
thread = threading.Timer(1, Functions.sort_fasta, kwargs={
"job_name": id_res,
......@@ -361,17 +361,17 @@ def build_fasta(id_res):
"mailer": mailer
})
thread.start()
if not compressed:
if not compressed or MODE == "standalone":
i = 0
time.sleep(5)
while os.path.exists(lock_query) and i < 2:
while os.path.exists(lock_query) and (i < 2 or MODE == "standalone"):
i += 1
time.sleep(5)
os.remove(lock_query + ".pending")
if os.path.exists(lock_query):
return jsonify({"success": True, "status": 1, "status_message": "In progress"})
return jsonify({"success": True, "status": 2, "status_message": "Done",
"gzip": False})
"gzip": compressed})
else:
return jsonify({"success": True, "status": 1, "status_message": "In progress"})
elif is_sorted and os.path.exists(lock_query):
......@@ -399,18 +399,32 @@ def build_fasta(id_res):
"message": "Unable to get fasta file for query. Please contact us to report the bug"})
@app.route('/build-query-as-reference/<id_res>', methods=['POST'])
def get_query_as_reference(id_res):
def build_query_as_reference(id_res):
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)
thread = threading.Timer(0, paf.build_query_chr_as_reference)
thread.start()
if MODE == "webserver":
thread = threading.Timer(0, paf.build_query_chr_as_reference)
thread.start()
return True
return paf.build_query_chr_as_reference()
@app.route('/build-query-as-reference/<id_res>', methods=['POST'])
def post_query_as_reference(id_res):
build_query_as_reference(id_res)
return jsonify({"success": True})
@app.route('/get-query-as-reference/<id_res>', methods=['GET'])
def get_query_as_reference(id_res):
if MODE != "standalone":
return abort(404)
return send_file(build_query_as_reference(id_res))
@app.route('/download/<id_res>/<filename>')
def download_file(id_res, filename):
file_dl = os.path.join(APP_DATA, id_res, filename)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment