Thomas 4 лет назад
Родитель
Сommit
0eee5013a2
2 измененных файлов с 11 добавлено и 4 удалено
  1. 5 2
      index.js
  2. 6 2
      index.ts

+ 5 - 2
index.js

@@ -79,11 +79,14 @@ const clusterSam = (input_sam, threshold, minReads) => {
                 .map((e, i, a) => {
                 var _a, _b;
                 if (i === 0) {
+                    if (typeof posAll[name] === 'undefined')
+                        posAll[name] = {};
                     firstPos = e.position;
                 }
+                if (a.length === 1) {
+                    posAll[name][String(cluster)] = String(firstPos);
+                }
                 if (Math.abs(e.position - ((_a = a[i - 1]) === null || _a === void 0 ? void 0 : _a.position)) > threshold) {
-                    if (typeof posAll[name] === 'undefined')
-                        posAll[name] = {};
                     posAll[name][String(cluster)] = firstPos + '-' + ((_b = a[i - 1]) === null || _b === void 0 ? void 0 : _b.position);
                     cluster = cluster + 1;
                     firstPos = e.position;

+ 6 - 2
index.ts

@@ -93,10 +93,13 @@ const clusterSam = (
                     .sort((a, b) => a.position - b.position)
                     .map((e, i, a) => {
                         if(i === 0) {
+                            if(typeof posAll[name] === 'undefined') posAll[name] = {}
                             firstPos = e.position
                         }
+                        if (a.length === 1) {
+                            posAll[name][String(cluster)] = String(firstPos)
+                        }
                         if (Math.abs(e.position - a[i-1]?.position) > threshold) {
-                            if(typeof posAll[name] === 'undefined') posAll[name] = {}
                             posAll[name][String(cluster)] = firstPos + '-' + a[i-1]?.position
                             cluster = cluster + 1
                             firstPos = e.position
@@ -110,7 +113,8 @@ const clusterSam = (
             interface byClusters {
                 [key: string]: string[]
             }
-            let byClusters: byClusters = {}
+            let byClusters: byClusters = {}            
+            
             Object.keys(byReads).map(rname => {
                 const tmpClusterName = byReads[rname].sort().map(e => {
                     const splited = e.split(/@/)