Thomas %!s(int64=4) %!d(string=hai) anos
pai
achega
e543272e66
Modificáronse 2 ficheiros con 37 adicións e 6 borrados
  1. 16 3
      index.js
  2. 21 3
      index.ts

+ 16 - 3
index.js

@@ -68,22 +68,35 @@ const clusterSam = (input_sam, threshold, minReads) => {
             });
         }, console.log);
         let byReads = {};
+        let posAll = {};
         Object
             .keys(byContigs)
             .map(name => {
             let cluster = 0;
+            let firstPos = 0;
             byContigs[name]
                 .sort((a, b) => a.position - b.position)
                 .map((e, i, a) => {
-                var _a;
-                cluster = Math.abs(e.position - ((_a = a[i - 1]) === null || _a === void 0 ? void 0 : _a.position)) > threshold ? cluster + 1 : cluster;
+                var _a, _b;
+                if (i === 0) {
+                    firstPos = e.position;
+                }
+                if (Math.abs(e.position - ((_a = a[i - 1]) === null || _a === void 0 ? void 0 : _a.position)) > threshold) {
+                    posAll[name][String(cluster)] = firstPos + '-' + ((_b = a[i - 1]) === null || _b === void 0 ? void 0 : _b.position);
+                    cluster = cluster + 1;
+                    firstPos = e.position;
+                }
+                // cluster = Math.abs(e.position - a[i-1]?.position) > threshold ? cluster + 1 : cluster
                 const clutserName = cluster + '@' + name;
                 byReads[e.rname] = Array.isArray(byReads[e.rname]) ? [...new Set([...byReads[e.rname], clutserName])] : [clutserName];
             });
         });
         let byClusters = {};
         Object.keys(byReads).map(rname => {
-            const tmpClusterName = byReads[rname].sort().join('<--->');
+            const tmpClusterName = byReads[rname].sort().map(e => {
+                const splited = e.split(/@/);
+                return splited[1] + ':' + posAll[splited[1]][splited[0]] + '(' + splited[0] + ')';
+            }).join('<--->');
             byClusters[tmpClusterName] = Array.isArray(byClusters[tmpClusterName]) ? [...new Set([...byClusters[tmpClusterName], rname])] : [rname];
         });
         Object.keys(byClusters).map(e => byClusters[e].length < minReads ? delete byClusters[e] : null);

+ 21 - 3
index.ts

@@ -77,15 +77,30 @@ const clusterSam = (
                 [key: string]: string[]
             }
             let byReads: byReads = {}
-
+            interface posObj {
+                [key: string]: string
+            }
+            interface posAll {
+                [key: string]: posObj
+            }
+            let posAll: posAll = {}
             Object
                 .keys(byContigs)
                 .map(name => {
                     let cluster = 0
+                    let firstPos = 0
                     byContigs[name]
                     .sort((a, b) => a.position - b.position)
                     .map((e, i, a) => {
-                        cluster = Math.abs(e.position - a[i-1]?.position) > threshold ? cluster + 1 : cluster
+                        if(i === 0) {
+                            firstPos = e.position
+                        }
+                        if (Math.abs(e.position - a[i-1]?.position) > threshold) {
+                            posAll[name][String(cluster)] = firstPos + '-' + a[i-1]?.position
+                            cluster = cluster + 1
+                            firstPos = e.position
+                        }
+                        // cluster = Math.abs(e.position - a[i-1]?.position) > threshold ? cluster + 1 : cluster
                         const clutserName = cluster + '@' + name
                         byReads[e.rname] = Array.isArray(byReads[e.rname]) ? [... new Set([...byReads[e.rname], clutserName])] : [clutserName]
                     })
@@ -96,7 +111,10 @@ const clusterSam = (
             }
             let byClusters: byClusters = {}
             Object.keys(byReads).map(rname => {
-                const tmpClusterName = byReads[rname].sort().join('<--->')
+                const tmpClusterName = byReads[rname].sort().map(e => {
+                    const splited = e.split(/@/)
+                    return splited[1] + ':' + posAll[splited[1]][splited[0]] + '(' + splited[0] + ')'
+                }).join('<--->')
                 byClusters[tmpClusterName] = Array.isArray(byClusters[tmpClusterName]) ? [... new Set([...byClusters[tmpClusterName], rname])] : [rname]
             })