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

Add export no match queries to target

parent 30d440b6
......@@ -11,7 +11,7 @@ dgenies.result.export.get_svg = function () {
dgenies.result.export.save_file = function(blob, format) {
dgenies.hide_loading();
saveAs(blob, `map_${d3.boxplot.name_y}_to_${d3.boxplot.name_x}.${format}`);
}
};
dgenies.result.export.export_png = function() {
dgenies.show_loading("Building files...", 180);
......@@ -126,6 +126,20 @@ dgenies.result.export.export_association_table = function () {
document.getElementById('my-download').click();
};
dgenies.result.export.export_no_association_file = function () {
dgenies.post("/no-assoc/" + dgenies.result.id_res,
{},
function (data, success) {
if (!data["empty"]) {
let blob = new Blob([data["file_content"]], {type: "text/plain"});
saveAs(blob, `nomatches_${d3.boxplot.name_y}_to_${d3.boxplot.name_x}.txt`);
}
else {
dgenies.notify("No contigs in query have None match with any target!", "success")
}
})
};
dgenies.result.export.export = function () {
let select = $("form#export select");
let selection = parseInt(select.val());
......@@ -145,6 +159,9 @@ dgenies.result.export.export = function () {
else if (selection === 5) {
dgenies.result.export.export_association_table();
}
else if (selection === 6) {
dgenies.result.export.export_no_association_file();
}
else
dgenies.notify("Not supported yet!", "danger", 2000);
if (!async)
......
......@@ -99,6 +99,31 @@ class Paf:
keep_lines[cls].append(line)
return keep_lines
@staticmethod
def load_index(index):
with open(index, "r") as idx_q_f:
abs_start = {}
abs_current_start = 0
c_len = 0
name = idx_q_f.readline().strip("\n")
order = []
contigs = {}
reversed = {}
for line in idx_q_f:
parts = line.strip("\n").split("\t")
id_c = parts[0]
len_c = int(parts[1])
if len(parts) > 2:
reversed[id_c] = parts[2] == "1"
else:
reversed[id_c] = False
order.append(id_c)
abs_start[id_c] = abs_current_start
contigs[id_c] = len_c
c_len += len_c
abs_current_start += len_c
return name, order, contigs, reversed, abs_start, abs_current_start, c_len
def parse_paf(self, merge_index=True, noise=True):
min_idy = 10000000000
max_idy = -10000000000
......@@ -108,51 +133,18 @@ class Paf:
"2": [],
"3": []
}
q_abs_start = {}
q_abs_current_start = 0
q_len = 0
try:
with open(self.idx_q, "r") as idx_q_f:
name_q = idx_q_f.readline().strip("\n")
q_order = []
q_contigs = {}
q_reversed = {}
for line in idx_q_f:
parts = line.strip("\n").split("\t")
id_c = parts[0]
len_c = int(parts[1])
if len(parts) > 2:
q_reversed[id_c] = parts[2] == "1"
else:
q_reversed[id_c] = False
q_order.append(id_c)
q_abs_start[id_c] = q_abs_current_start
q_contigs[id_c] = len_c
q_len += len_c
q_abs_current_start += len_c
name_q, q_order, q_contigs, q_reversed, q_abs_start, q_abs_current_start, q_len = self.load_index(
self.idx_q)
if merge_index:
q_contigs, q_order = self.parse_index(q_order, q_contigs, q_len)
except IOError:
self.error = "Index file does not exist for query!"
return False
t_abs_start = {}
t_abs_current_start = 0
t_len = 0
try:
with open(self.idx_t, "r") as idx_t_f:
name_t = idx_t_f.readline().strip("\n")
t_order = []
t_contigs = {}
for line in idx_t_f:
parts = line.strip("\n").split("\t")
id_c = parts[0]
len_c = int(parts[1])
t_order.append(id_c)
t_abs_start[id_c] = t_abs_current_start
t_contigs[id_c] = len_c
t_len += len_c
t_abs_current_start += len_c
name_t, t_order, t_contigs, t_reversed, t_abs_start, t_abs_current_start, t_len = self.load_index(
self.idx_t)
if merge_index:
t_contigs, t_order = self.parse_index(t_order, t_contigs, t_len)
except IOError:
......@@ -495,3 +487,16 @@ class Paf:
else:
content += "%s\t%s\t%s\n" % (contig, "None", strand)
return content
def build_list_no_assoc(self):
"""
Build list of queries that match with None target
:return: content of the file
"""
name, contigs_list, contigs, reversed, abs_start, abs_current_start, c_len = self.load_index(self.idx_q)
with open(self.paf, "r") as paf:
for line in paf:
query_name = line.strip("\n").split("\t")[0]
if query_name in contigs_list:
contigs_list.remove(query_name)
return "\n".join(contigs_list) + "\n"
......@@ -388,6 +388,32 @@ def qt_assoc(id_res):
abort(404)
@app.route('/no-assoc/<id_res>', methods=['POST'])
def no_assoc(id_res):
"""
Get contigs that match with None target
:param id_res: id of the result
"""
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()
empty = file_content == "\n"
return jsonify({
"file_content": file_content,
"empty": empty
})
abort(404)
@app.route("/ask-upload", methods=['POST'])
def ask_upload():
try:
......
......@@ -42,6 +42,7 @@
<option value="3">Paf file</option>
<option value="4">Query Fasta</option>
<option value="5">Association table</option>
<option value="6">No match queries</option>
</select>
</form>
</div>
......
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