From 408212b928293f55d4f5c8e0fa98c4701710d72d Mon Sep 17 00:00:00 2001 From: ASLeonard Date: Sun, 2 Oct 2022 13:07:57 +0200 Subject: [PATCH 1/7] add P-line generating path cmd --- misc/mgutils.js | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/misc/mgutils.js b/misc/mgutils.js index de6d65d..8b2cd38 100755 --- a/misc/mgutils.js +++ b/misc/mgutils.js @@ -1405,6 +1405,53 @@ function mg_cmd_genecopy(args) print("GC", g, out[g].join("\t")); } +function mg_cmd_path(args) +{ + if (args.length != 2) { + print("Usage: paste *.bed | mgutils.js path -"); + return; + } + var file, buf = new Bytes(); + var paths = []; + var samples = []; + file = new File(args[0]); + while (file.readline(buf) >= 0) { + var t = buf.toString(); + paths.push([]); + samples.push(t); + } + file.close(); + file = args[1] == "-"? new File() : new File(args[1]); + + var dict = {">":"+","<":"-"}; + + while (file.readline(buf) >= 0) { + var t = buf.toString().split("\t"); + for (var j = 5; j < t.length; j += 6) { + var index = ~~(j/6); //~~ is a way to get integer division + if (!paths[index].length) { + paths[index].push(t[3].substring(1)+"+"); + } + if (t[j] != ".") { + if (t[j][0] != "*") { + var nodes = t[j].split(":")[0].split(/(?=>|<)/g); + for (var n=0; n Date: Thu, 10 Nov 2022 11:59:59 +0100 Subject: [PATCH 2/7] add missing "*" overlap to path --- misc/mgutils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/misc/mgutils.js b/misc/mgutils.js index 8b2cd38..e22ba82 100755 --- a/misc/mgutils.js +++ b/misc/mgutils.js @@ -1448,7 +1448,7 @@ function mg_cmd_path(args) file.close(); for (var p=0; p Date: Mon, 21 Nov 2022 07:43:01 +0100 Subject: [PATCH 3/7] replace * with 0M for GraphAlinger use --- misc/mgutils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/misc/mgutils.js b/misc/mgutils.js index e22ba82..462eab3 100755 --- a/misc/mgutils.js +++ b/misc/mgutils.js @@ -1448,7 +1448,7 @@ function mg_cmd_path(args) file.close(); for (var p=0; p Date: Thu, 14 Nov 2024 15:04:58 +0100 Subject: [PATCH 4/7] improved pathing over samples --- misc/mgutils.js | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/misc/mgutils.js b/misc/mgutils.js index 02dc5b0..e756ec4 100755 --- a/misc/mgutils.js +++ b/misc/mgutils.js @@ -1383,6 +1383,9 @@ function mg_cmd_path(args) var file, buf = new Bytes(); var paths = []; var samples = []; + + var paths3 = {}; + file = new File(args[0]); while (file.readline(buf) >= 0) { var t = buf.toString(); @@ -1392,32 +1395,44 @@ function mg_cmd_path(args) file.close(); file = args[1] == "-"? new File() : new File(args[1]); - var dict = {">":"+","<":"-"}; + var strand_map = {"+":{">":"+","<":"-"},"-":{">":"-","<":"+"}}; while (file.readline(buf) >= 0) { var t = buf.toString().split("\t"); for (var j = 5; j < t.length; j += 6) { var index = ~~(j/6); //~~ is a way to get integer division if (!paths[index].length) { - paths[index].push(t[3].substring(1)+"+"); + paths[index].push(t[3].substring(1)+"+"); //add the source node } - if (t[j] != ".") { - if (t[j][0] != "*") { + if (t[j] != ".") { //skip if there is no mapping + var strand = t[j].split(":")[2] + var sample_ID = t[j].split(":")[3] + if (!(sample_ID in paths3)) { + paths3[sample_ID] = []; + } + paths3[sample_ID].push(t[3].substring(1)+strand_map[strand][">"]); + if (t[j][0] != "*") { //if it is a deletion, there are no nodes to iterate over var nodes = t[j].split(":")[0].split(/(?=>|<)/g); for (var n=0; n"]); } - paths[index].push(t[4].substring(1)+"+"); + paths[index].push(t[4].substring(1)+"+"); //add the sink node } } buf.destroy(); file.close(); - for (var p=0; p Date: Fri, 15 Nov 2024 12:45:42 +0100 Subject: [PATCH 5/7] jumping is still broken in general --- misc/mgutils.js | 49 +++++++++++++++++++++++-------------------------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/misc/mgutils.js b/misc/mgutils.js index e756ec4..244deba 100755 --- a/misc/mgutils.js +++ b/misc/mgutils.js @@ -1376,24 +1376,17 @@ function mg_cmd_genecopy(args) function mg_cmd_path(args) { - if (args.length != 2) { - print("Usage: paste *.bed | mgutils.js path -"); + if (args.length != 1) { + print("Usage: paste *.bed | mgutils.js path -"); return; } var file, buf = new Bytes(); var paths = []; - var samples = []; + var J_lines = new Set(); var paths3 = {}; - file = new File(args[0]); - while (file.readline(buf) >= 0) { - var t = buf.toString(); - paths.push([]); - samples.push(t); - } - file.close(); - file = args[1] == "-"? new File() : new File(args[1]); + file = args[1] == "-" ? new File() : new File(args[0]); var strand_map = {"+":{">":"+","<":"-"},"-":{">":"-","<":"+"}}; @@ -1401,37 +1394,41 @@ function mg_cmd_path(args) var t = buf.toString().split("\t"); for (var j = 5; j < t.length; j += 6) { var index = ~~(j/6); //~~ is a way to get integer division - if (!paths[index].length) { - paths[index].push(t[3].substring(1)+"+"); //add the source node - } if (t[j] != ".") { //skip if there is no mapping - var strand = t[j].split(":")[2] - var sample_ID = t[j].split(":")[3] + var strand = t[j].split(":")[2]; + var sample_ID = t[j].split(":")[3]; if (!(sample_ID in paths3)) { paths3[sample_ID] = []; + paths3[sample_ID].push(t[3].substring(1)+strand_map[strand][">"]+","); //add the source node } - paths3[sample_ID].push(t[3].substring(1)+strand_map[strand][">"]); + else { + paths3[sample_ID].push(","); + } if (t[j][0] != "*") { //if it is a deletion, there are no nodes to iterate over var nodes = t[j].split(":")[0].split(/(?=>|<)/g); for (var n=0; n"]); } - paths[index].push(t[4].substring(1)+"+"); //add the sink node + else { // handle non-mapped line + if (sample_ID in paths3 && !paths3[sample_ID].length) { + J_lines.add("J\t"+t[3].substring(1)+"\t+\t"+t[4].substring(1)+"\t+\t*"); + paths3[sample_ID].push(";"+t[4].substring(1)+">"); + } + } } } buf.destroy(); file.close(); - //for (var p=0; p Date: Mon, 18 Nov 2024 11:07:48 +0100 Subject: [PATCH 6/7] path output loads in bandage --- misc/mgutils.js | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/misc/mgutils.js b/misc/mgutils.js index 244deba..8835341 100755 --- a/misc/mgutils.js +++ b/misc/mgutils.js @@ -1385,10 +1385,11 @@ function mg_cmd_path(args) var J_lines = new Set(); var paths3 = {}; + var jumping = {}; file = args[1] == "-" ? new File() : new File(args[0]); - var strand_map = {"+":{">":"+","<":"-"},"-":{">":"-","<":"+"}}; + var strand_map = {"+":{">":"+","<":"-"},"-":{">":"+","<":"-"}}; while (file.readline(buf) >= 0) { var t = buf.toString().split("\t"); @@ -1400,9 +1401,16 @@ function mg_cmd_path(args) if (!(sample_ID in paths3)) { paths3[sample_ID] = []; paths3[sample_ID].push(t[3].substring(1)+strand_map[strand][">"]+","); //add the source node - } + } else { - paths3[sample_ID].push(","); + if (sample_ID in jumping && jumping[sample_ID]!=t[3].substring(1)) { + paths3[sample_ID].push(";"+t[3].substring(1)+strand_map[strand][">"]+","); + J_lines.add("J\t"+jumping[sample_ID]+"\t+\t"+t[3].substring(1)+"\t+\t*"); + delete jumping[sample_ID]; + } + else { + paths3[sample_ID].push(","); + } } if (t[j][0] != "*") { //if it is a deletion, there are no nodes to iterate over var nodes = t[j].split(":")[0].split(/(?=>|<)/g); @@ -1412,13 +1420,18 @@ function mg_cmd_path(args) } } paths3[sample_ID].push(t[4].substring(1)+strand_map[strand][">"]); + + jumping[sample_ID] = t[4].substring(1); } - else { // handle non-mapped line - if (sample_ID in paths3 && !paths3[sample_ID].length) { - J_lines.add("J\t"+t[3].substring(1)+"\t+\t"+t[4].substring(1)+"\t+\t*"); - paths3[sample_ID].push(";"+t[4].substring(1)+">"); - } - } + //else { // handle non-mapped line + //if (sample_ID in paths3 && !paths3[sample_ID].length) { + // J_lines.add("J\t"+t[3].substring(1)+"\t+\t"+t[4].substring(1)+"\t+\t*"); + // //paths3[sample_ID].push(";"+t[4].substring(1)+">"); + //} + // if (!(sample_ID in jumping)) { + // jumping[sample_ID] = t[3].substring(1); + // } + //} } } buf.destroy(); From b16d8cb129b0cc558a1b5c357d860f61e29192fe Mon Sep 17 00:00:00 2001 From: ASLeonard Date: Mon, 18 Nov 2024 12:00:31 +0100 Subject: [PATCH 7/7] clean up path command --- misc/mgutils.js | 44 ++++++++++++++++++-------------------------- 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/misc/mgutils.js b/misc/mgutils.js index 8835341..c6015d4 100755 --- a/misc/mgutils.js +++ b/misc/mgutils.js @@ -1384,7 +1384,7 @@ function mg_cmd_path(args) var paths = []; var J_lines = new Set(); - var paths3 = {}; + var paths = {}; var jumping = {}; file = args[1] == "-" ? new File() : new File(args[0]); @@ -1393,45 +1393,37 @@ function mg_cmd_path(args) while (file.readline(buf) >= 0) { var t = buf.toString().split("\t"); + var source = t[3], sink = t[4]; + for (var j = 5; j < t.length; j += 6) { var index = ~~(j/6); //~~ is a way to get integer division if (t[j] != ".") { //skip if there is no mapping - var strand = t[j].split(":")[2]; - var sample_ID = t[j].split(":")[3]; - if (!(sample_ID in paths3)) { - paths3[sample_ID] = []; - paths3[sample_ID].push(t[3].substring(1)+strand_map[strand][">"]+","); //add the source node + var [walk, length, strand, sample_ID, start_pos, end_pos] = t[j].split(":"); + if (!(sample_ID in paths)) { + paths[sample_ID] = []; + paths[sample_ID].push(source.substring(1)+strand_map[strand][">"]+","); //add the source node } else { - if (sample_ID in jumping && jumping[sample_ID]!=t[3].substring(1)) { - paths3[sample_ID].push(";"+t[3].substring(1)+strand_map[strand][">"]+","); - J_lines.add("J\t"+jumping[sample_ID]+"\t+\t"+t[3].substring(1)+"\t+\t*"); + if (sample_ID in jumping && jumping[sample_ID]!=source.substring(1)) { + paths[sample_ID].push(";"+source.substring(1)+strand_map[strand][">"]+","); + J_lines.add("J\t"+jumping[sample_ID]+"\t+\t"+source.substring(1)+"\t+\t*"); delete jumping[sample_ID]; } else { - paths3[sample_ID].push(","); + paths[sample_ID].push(","); } } - if (t[j][0] != "*") { //if it is a deletion, there are no nodes to iterate over - var nodes = t[j].split(":")[0].split(/(?=>|<)/g); + if (walk != "*") { //if it is a deletion, there are no nodes to iterate over + var nodes = walk.split(/(?=>|<)/g); for (var n=0; n"]); + paths[sample_ID].push(sink.substring(1)+strand_map[strand][">"]); - jumping[sample_ID] = t[4].substring(1); + jumping[sample_ID] = sink.substring(1); } - //else { // handle non-mapped line - //if (sample_ID in paths3 && !paths3[sample_ID].length) { - // J_lines.add("J\t"+t[3].substring(1)+"\t+\t"+t[4].substring(1)+"\t+\t*"); - // //paths3[sample_ID].push(";"+t[4].substring(1)+">"); - //} - // if (!(sample_ID in jumping)) { - // jumping[sample_ID] = t[3].substring(1); - // } - //} } } buf.destroy(); @@ -1440,8 +1432,8 @@ function mg_cmd_path(args) for (const J of J_lines) { print(J); } - for (var P in paths3) { - var path = paths3[P].join(""); + for (var P in paths) { + var path = paths[P].join(""); print("P",P,path,"0M"); } }