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: ...@@ -58,7 +58,7 @@ class Functions:
fasta_file = None fasta_file = None
try: try:
with open(os.path.join(res_dir, "." + type_f), "r") as save_name: 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: except IOError:
print(res_dir + ": Unable to load saved name for " + type_f, file=sys.stderr) print(res_dir + ": Unable to load saved name for " + type_f, file=sys.stderr)
pass pass
......
#!/usr/bin/env python3 #!/usr/bin/env python3
from dgenies import MODE
import os import os
import shutil import shutil
from math import sqrt from math import sqrt
...@@ -762,6 +764,7 @@ class Paf: ...@@ -762,6 +764,7 @@ class Paf:
o_fasta = "_._" o_fasta = "_._"
status="fail" status="fail"
if MODE == "webserver":
parts = os.path.basename(o_fasta).rsplit(".", 1) parts = os.path.basename(o_fasta).rsplit(".", 1)
Functions.send_fasta_ready(mailer=self.mailer, Functions.send_fasta_ready(mailer=self.mailer,
job_name=self.id_job, job_name=self.id_job,
......
...@@ -34,7 +34,6 @@ dgenies.result.export.export_svg = function () { ...@@ -34,7 +34,6 @@ dgenies.result.export.export_svg = function () {
dgenies.result.export.save_file(blob, "svg"); dgenies.result.export.save_file(blob, "svg");
}; };
d3.boxplot.zoom.reset_scale(true, after); d3.boxplot.zoom.reset_scale(true, after);
}; };
dgenies.result.export.export_paf = function () { dgenies.result.export.export_paf = function () {
...@@ -141,7 +140,7 @@ dgenies.result.export.export_no_association_file = function (to) { ...@@ -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}`, dgenies.post(`/build-query-as-reference/${dgenies.result.id_res}`,
{}, {},
function (data, success) { function (data, success) {
...@@ -149,10 +148,32 @@ dgenies.result.export.export_query_as_reference_fasta = function() { ...@@ -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") dgenies.notify("You will receive a mail soon with the link to download your Fasta file", "success")
} }
else { 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 () { dgenies.result.export.export = function () {
let select = $("form#export select"); let select = $("form#export select");
...@@ -180,7 +201,13 @@ dgenies.result.export.export = function () { ...@@ -180,7 +201,13 @@ dgenies.result.export.export = function () {
dgenies.result.export.export_no_association_file("target"); dgenies.result.export.export_no_association_file("target");
} }
else if (selection === 8) { 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 else
dgenies.notify("Not supported yet!", "danger", 2000); dgenies.notify("Not supported yet!", "danger", 2000);
......
...@@ -350,7 +350,7 @@ def build_fasta(id_res): ...@@ -350,7 +350,7 @@ def build_fasta(id_res):
if is_sorted and not query_fasta.endswith(".sorted"): if is_sorted and not query_fasta.endswith(".sorted"):
# Do the sort # Do the sort
Path(lock_query).touch() 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() Path(lock_query + ".pending").touch()
thread = threading.Timer(1, Functions.sort_fasta, kwargs={ thread = threading.Timer(1, Functions.sort_fasta, kwargs={
"job_name": id_res, "job_name": id_res,
...@@ -361,17 +361,17 @@ def build_fasta(id_res): ...@@ -361,17 +361,17 @@ def build_fasta(id_res):
"mailer": mailer "mailer": mailer
}) })
thread.start() thread.start()
if not compressed: if not compressed or MODE == "standalone":
i = 0 i = 0
time.sleep(5) 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 i += 1
time.sleep(5) time.sleep(5)
os.remove(lock_query + ".pending") os.remove(lock_query + ".pending")
if os.path.exists(lock_query): if os.path.exists(lock_query):
return jsonify({"success": True, "status": 1, "status_message": "In progress"}) return jsonify({"success": True, "status": 1, "status_message": "In progress"})
return jsonify({"success": True, "status": 2, "status_message": "Done", return jsonify({"success": True, "status": 2, "status_message": "Done",
"gzip": False}) "gzip": compressed})
else: else:
return jsonify({"success": True, "status": 1, "status_message": "In progress"}) return jsonify({"success": True, "status": 1, "status_message": "In progress"})
elif is_sorted and os.path.exists(lock_query): elif is_sorted and os.path.exists(lock_query):
...@@ -399,18 +399,32 @@ def build_fasta(id_res): ...@@ -399,18 +399,32 @@ def build_fasta(id_res):
"message": "Unable to get fasta file for query. Please contact us to report the bug"}) "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 build_query_as_reference(id_res):
def get_query_as_reference(id_res):
paf_file = os.path.join(APP_DATA, id_res, "map.paf") paf_file = os.path.join(APP_DATA, id_res, "map.paf")
idx1 = os.path.join(APP_DATA, id_res, "query.idx") idx1 = os.path.join(APP_DATA, id_res, "query.idx")
idx2 = os.path.join(APP_DATA, id_res, "target.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 = Paf(paf_file, idx1, idx2, False, mailer=mailer, id_job=id_res)
paf.parse_paf(False, True) paf.parse_paf(False, True)
if MODE == "webserver":
thread = threading.Timer(0, paf.build_query_chr_as_reference) thread = threading.Timer(0, paf.build_query_chr_as_reference)
thread.start() 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}) 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>') @app.route('/download/<id_res>/<filename>')
def download_file(id_res, filename): def download_file(id_res, filename):
file_dl = os.path.join(APP_DATA, id_res, filename) file_dl = os.path.join(APP_DATA, id_res, filename)
......
Supports Markdown
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