Commit a2caf67d authored by Floreal Cabanettes's avatar Floreal Cabanettes
Browse files

Add export to PAF format

parent 03729af2
......@@ -35,6 +35,15 @@ dgenies.result.export.export_svg = function () {
};
dgenies.result.export.export_paf = function () {
let export_div = $("div#export-pict");
export_div.html("");
export_div.append($("<a>").attr("href", `/paf/${d3.boxplot.id_res}`)
.attr("download", `map_${d3.boxplot.name_y}_to_${d3.boxplot.name_x}.paf`).attr("id", "my-download").text("download"));
dgenies.hide_loading();
document.getElementById('my-download').click();
};
dgenies.result.export.export = function () {
let select = $("form#export select");
let selection = parseInt(select.val());
......@@ -45,6 +54,8 @@ dgenies.result.export.export = function () {
dgenies.result.export.export_svg();
else if (selection === 2)
dgenies.result.export.export_png();
else if (selection === 3)
dgenies.result.export.export_paf();
else
dgenies.notify("Not supported yet!", "error", 2000);
dgenies.hide_loading();
......
......@@ -5,7 +5,7 @@ import time
import datetime
import shutil
import re
from flask import Flask, render_template, request, url_for, jsonify, session
from flask import Flask, render_template, request, url_for, jsonify, session, Response, abort
from flask_mail import Mail
from lib.paf import Paf
from config_reader import AppConfigReader
......@@ -27,6 +27,7 @@ sqlite_file = os.path.join(app_folder, "database.sqlite")
config_reader = AppConfigReader()
UPLOAD_FOLDER = config_reader.get_upload_folder()
APP_DATA = config_reader.get_app_data()
app_title = "D-GENIES - Dotplot for Genomes Interactive, E-connected and Speedy"
......@@ -145,6 +146,29 @@ def result(id_res):
return response
def get_file(file): # pragma: no cover
try:
# Figure out how flask returns static files
# Tried:
# - render_template
# - send_file
# This should not be so non-obvious
return open(file).read()
except IOError as exc:
return str(exc)
@app.route("/paf/<id_res>", methods=['GET'])
def download_paf(id_res):
map_file = os.path.join(APP_DATA, id_res, "map.paf.sorted")
if not os.path.exists(map_file):
map_file = os.path.join(APP_DATA, id_res, "map.paf")
if not os.path.exists(map_file):
abort(404)
content = get_file(map_file)
return Response(content, mimetype="text/plain")
# Get graph (ajax request)
@app.route('/get_graph', methods=['POST'])
def get_graph():
......
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