Commit 1a4f342d authored by Floreal Cabanettes's avatar Floreal Cabanettes
Browse files

Add hide noise functionality

parent 37af6051
dgenies = {};
dgenies.loading = "#loading";
dgenies.noise = true;
dgenies.notify = function (text, type="warning", delay=5000) {
$.notify({
......
......@@ -5,6 +5,7 @@ dgenies.result.controls = {};
dgenies.result.controls.init = function () {
$("#sort-contigs").click(dgenies.result.controls.launch_sort_contigs);
$("#hide-noise").click(dgenies.result.controls.launch_hide_noise);
$("form#select-zone input.submit").click(dgenies.result.controls.select_zone);
$("form#export select").change(dgenies.result.export.export);
};
......@@ -33,6 +34,32 @@ dgenies.result.controls.launch_sort_contigs = function () {
}, 0);
};
dgenies.result.controls.launch_hide_noise = function () {
d3.boxplot.zoom.reset_scale();
window.setTimeout(() => {
dgenies.show_loading("Building...");
window.setTimeout(() => {
dgenies.post(`/freenoise/${dgenies.result.id_res}`,
{noise: dgenies.noise ? 0 : 1},
function (data) {
if (data["success"]) {
dgenies.noise = !dgenies.noise;
$("#hide-noise").val(dgenies.noise ? "Hide noise" : "Show noise");
dgenies.reset_loading_message();
window.setTimeout(() => {
d3.boxplot.launch(data, true);
}, 0);
}
else {
dgenies.hide_loading();
dgenies.notify(data["message"] || "An error occurred! Please contact us to report the bug", "danger");
}
}
);
}, 0);
}, 0);
};
dgenies.result.controls.select_zone = function() {
let contig_select = $("#select-contig").find(":selected");
let target_select = $("#select-target").find(":selected");
......
......@@ -5,6 +5,7 @@ import shutil
from math import sqrt
from numpy import mean
from pathlib import Path
from matplotlib import pyplot as plt
class Paf:
......@@ -76,7 +77,28 @@ class Paf:
new_index_c, new_index_o = self.__flush_blocks(index_c, new_index_c, new_index_o, current_block)
return new_index_c, new_index_o
def parse_paf(self, merge_index=True):
@staticmethod
def remove_noise(lines, noise_limit):
keep_lines = {
"0": [],
"1": [],
"2": [],
"3": []
}
for cls, c_lines in lines.items():
for line in c_lines:
print(line)
x1 = line[0]
x2 = line[1]
y1 = line[2]
y2 = line[3]
idy = line[4]
len_m = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2))
if len_m >= noise_limit:
keep_lines[cls].append(line)
return keep_lines
def parse_paf(self, merge_index=True, noise=True):
min_idy = 10000000000
max_idy = -10000000000
lines = {
......@@ -138,6 +160,7 @@ class Paf:
len_q = q_abs_current_start
len_t = t_abs_current_start
lines_lens = []
try:
with open(self.paf, "r") as paf_file:
......@@ -159,6 +182,8 @@ class Paf:
y2 = int(parts[3]) + q_abs_start[v1]
x1 = int(parts[7 if strand == 1 else 8]) + t_abs_start[v6]
x2 = int(parts[8 if strand == 1 else 7]) + t_abs_start[v6]
len_m = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2))
lines_lens.append(len_m)
if idy < self.limit_idy[0]:
class_idy = "0"
elif idy < self.limit_idy[1]:
......@@ -172,6 +197,22 @@ class Paf:
self.error = "PAF file does not exist!"
return False
if not noise:
counts, bins, bars = plt.hist(lines_lens, bins=1000)
counts = list(counts)
max_value = max(counts)
max_index = counts.index(max_value)
limit_index = -1
print(max_value, max_index)
for i in range(max_index, len(counts)):
if counts[i] < max_value / 100:
print("pass")
limit_index = i
break
print(limit_index)
if limit_index > -1:
lines = self.remove_noise(lines, bins[limit_index])
self.parsed = True
self.len_q = len_q
self.len_t = len_t
......
......@@ -10,3 +10,4 @@ biopython==1.70
python-crontab==2.2.*
psutil==5.4.*
tendo==0.2.*
matplotlib==2.1.*
......@@ -209,6 +209,20 @@ def sort_graph(id_res):
return jsonify({"success": False, "message": "Sort is not available for All-vs-All mode"})
@app.route('/freenoise/<id_res>', methods=['POST'])
def free_noise(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)
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})
@app.route('/get-fasta-query/<id_res>', methods=['POST'])
def build_fasta(id_res):
res_dir = os.path.join(app_data, id_res)
......
......@@ -64,6 +64,7 @@
<p><label>Regions delimiters:<br/>
<input type="range" min="0" max="5" value="2" step="1" id="chroms-limits"/></label></p>
<p><input type="button" id="sort-contigs" value="Sort contigs"/></p>
<p><input type="button" id="hide-noise" value="Hide noise"/></p>
</form>
</div>
</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