Thomas il y a 2 ans
Parent
commit
ee59a6eea4
3 fichiers modifiés avec 363 ajouts et 62 suppressions
  1. 251 18
      Cargo.lock
  2. 2 0
      Cargo.toml
  3. 110 44
      src/main.rs

+ 251 - 18
Cargo.lock

@@ -47,7 +47,7 @@ version = "1.0.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b"
 dependencies = [
- "windows-sys",
+ "windows-sys 0.48.0",
 ]
 
 [[package]]
@@ -57,9 +57,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "180abfa45703aebe0093f79badacc01b8fd4ea2e35118747e5811127f926e188"
 dependencies = [
  "anstyle",
- "windows-sys",
+ "windows-sys 0.48.0",
 ]
 
+[[package]]
+name = "autocfg"
+version = "1.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
+
 [[package]]
 name = "bio-types"
 version = "1.0.0"
@@ -189,6 +195,62 @@ version = "1.0.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
 
+[[package]]
+name = "console"
+version = "0.15.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c926e00cc70edefdc64d3a5ff31cc65bb97a3460097762bd23afb4d8145fccf8"
+dependencies = [
+ "encode_unicode",
+ "lazy_static",
+ "libc",
+ "unicode-width",
+ "windows-sys 0.45.0",
+]
+
+[[package]]
+name = "crossbeam-channel"
+version = "0.5.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200"
+dependencies = [
+ "cfg-if",
+ "crossbeam-utils",
+]
+
+[[package]]
+name = "crossbeam-deque"
+version = "0.8.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ce6fd6f855243022dcecf8702fef0c297d4338e226845fe067f6341ad9fa0cef"
+dependencies = [
+ "cfg-if",
+ "crossbeam-epoch",
+ "crossbeam-utils",
+]
+
+[[package]]
+name = "crossbeam-epoch"
+version = "0.9.15"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ae211234986c545741a7dc064309f67ee1e5ad243d0e48335adc0484d960bcc7"
+dependencies = [
+ "autocfg",
+ "cfg-if",
+ "crossbeam-utils",
+ "memoffset",
+ "scopeguard",
+]
+
+[[package]]
+name = "crossbeam-utils"
+version = "0.8.16"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294"
+dependencies = [
+ "cfg-if",
+]
+
 [[package]]
 name = "curl-sys"
 version = "0.4.63+curl-8.1.2"
@@ -224,7 +286,7 @@ dependencies = [
 [[package]]
 name = "desc_sequence"
 version = "0.1.0"
-source = "git+https://git.t0m4.fr/Thomas/desc_sequence.git#56be6c949c82541337e85e16a45d8cd49d37c18c"
+source = "git+https://git.t0m4.fr/Thomas/desc_sequence.git#4906ed08906c2cc2798a94069dd000a6bad56fb9"
 dependencies = [
  "bwa",
  "duct",
@@ -249,6 +311,12 @@ version = "1.8.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91"
 
+[[package]]
+name = "encode_unicode"
+version = "0.3.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f"
+
 [[package]]
 name = "errno"
 version = "0.3.1"
@@ -257,7 +325,7 @@ checksum = "4bcfec3a70f97c962c307b2d2c56e358cf1d00b558d74262b5f929ee8cc7e73a"
 dependencies = [
  "errno-dragonfly",
  "libc",
- "windows-sys",
+ "windows-sys 0.48.0",
 ]
 
 [[package]]
@@ -311,6 +379,15 @@ version = "0.4.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
 
+[[package]]
+name = "hermit-abi"
+version = "0.2.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7"
+dependencies = [
+ "libc",
+]
+
 [[package]]
 name = "hermit-abi"
 version = "0.3.1"
@@ -349,27 +426,52 @@ version = "0.2.6"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "9007da9cacbd3e6343da136e98b0d2df013f553d35bdec8b518f07bea768e19c"
 
+[[package]]
+name = "indicatif"
+version = "0.17.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8ff8cc23a7393a397ed1d7f56e6365cba772aba9f9912ab968b03043c395d057"
+dependencies = [
+ "console",
+ "instant",
+ "number_prefix",
+ "portable-atomic",
+ "rayon",
+ "unicode-width",
+]
+
 [[package]]
 name = "indl_finder"
 version = "0.1.0"
 dependencies = [
  "clap",
  "desc_sequence",
+ "indicatif",
  "itertools",
  "merge_sequences",
  "rand",
+ "rayon",
  "rust-htslib 0.42.0",
 ]
 
+[[package]]
+name = "instant"
+version = "0.1.12"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c"
+dependencies = [
+ "cfg-if",
+]
+
 [[package]]
 name = "io-lifetimes"
 version = "1.0.11"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2"
 dependencies = [
- "hermit-abi",
+ "hermit-abi 0.3.1",
  "libc",
- "windows-sys",
+ "windows-sys 0.48.0",
 ]
 
 [[package]]
@@ -378,10 +480,10 @@ version = "0.4.7"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "adcf93614601c8129ddf72e2d5633df827ba6551541c6d8c59520a371475be1f"
 dependencies = [
- "hermit-abi",
+ "hermit-abi 0.3.1",
  "io-lifetimes",
  "rustix",
- "windows-sys",
+ "windows-sys 0.48.0",
 ]
 
 [[package]]
@@ -456,6 +558,15 @@ version = "2.5.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
 
+[[package]]
+name = "memoffset"
+version = "0.9.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c"
+dependencies = [
+ "autocfg",
+]
+
 [[package]]
 name = "merge_sequences"
 version = "1.0.0"
@@ -470,6 +581,22 @@ dependencies = [
  "rustc_version",
 ]
 
+[[package]]
+name = "num_cpus"
+version = "1.15.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b"
+dependencies = [
+ "hermit-abi 0.2.6",
+ "libc",
+]
+
+[[package]]
+name = "number_prefix"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3"
+
 [[package]]
 name = "once_cell"
 version = "1.18.0"
@@ -505,7 +632,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "0ae859aa07428ca9a929b936690f8b12dc5f11dd8c6992a18ca93919f28bc177"
 dependencies = [
  "libc",
- "windows-sys",
+ "windows-sys 0.48.0",
 ]
 
 [[package]]
@@ -520,6 +647,12 @@ version = "0.3.27"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964"
 
+[[package]]
+name = "portable-atomic"
+version = "1.3.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "767eb9f07d4a5ebcb39bbf2d452058a93c011373abf6832e24194a1c3f004794"
+
 [[package]]
 name = "ppv-lite86"
 version = "0.2.17"
@@ -580,6 +713,28 @@ dependencies = [
  "getrandom",
 ]
 
+[[package]]
+name = "rayon"
+version = "1.7.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1d2df5196e37bcc87abebc0053e20787d73847bb33134a69841207dd0a47f03b"
+dependencies = [
+ "either",
+ "rayon-core",
+]
+
+[[package]]
+name = "rayon-core"
+version = "1.11.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4b8f95bd6966f5c87776639160a66bd8ab9895d9d4ab01ddba9fc60661aebe8d"
+dependencies = [
+ "crossbeam-channel",
+ "crossbeam-deque",
+ "crossbeam-utils",
+ "num_cpus",
+]
+
 [[package]]
 name = "regex"
 version = "1.8.4"
@@ -661,7 +816,7 @@ dependencies = [
  "io-lifetimes",
  "libc",
  "linux-raw-sys",
- "windows-sys",
+ "windows-sys 0.48.0",
 ]
 
 [[package]]
@@ -670,6 +825,12 @@ version = "1.0.12"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "4f3208ce4d8448b3f3e7d168a73f5e0c43a61e32930de3bceeccedb388b6bf06"
 
+[[package]]
+name = "scopeguard"
+version = "1.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
+
 [[package]]
 name = "semver"
 version = "0.1.20"
@@ -812,6 +973,12 @@ dependencies = [
  "tinyvec",
 ]
 
+[[package]]
+name = "unicode-width"
+version = "0.1.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b"
+
 [[package]]
 name = "url"
 version = "2.4.0"
@@ -863,13 +1030,37 @@ version = "0.4.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
 
+[[package]]
+name = "windows-sys"
+version = "0.45.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0"
+dependencies = [
+ "windows-targets 0.42.2",
+]
+
 [[package]]
 name = "windows-sys"
 version = "0.48.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
 dependencies = [
- "windows-targets",
+ "windows-targets 0.48.0",
+]
+
+[[package]]
+name = "windows-targets"
+version = "0.42.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071"
+dependencies = [
+ "windows_aarch64_gnullvm 0.42.2",
+ "windows_aarch64_msvc 0.42.2",
+ "windows_i686_gnu 0.42.2",
+ "windows_i686_msvc 0.42.2",
+ "windows_x86_64_gnu 0.42.2",
+ "windows_x86_64_gnullvm 0.42.2",
+ "windows_x86_64_msvc 0.42.2",
 ]
 
 [[package]]
@@ -878,51 +1069,93 @@ version = "0.48.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5"
 dependencies = [
- "windows_aarch64_gnullvm",
- "windows_aarch64_msvc",
- "windows_i686_gnu",
- "windows_i686_msvc",
- "windows_x86_64_gnu",
- "windows_x86_64_gnullvm",
- "windows_x86_64_msvc",
+ "windows_aarch64_gnullvm 0.48.0",
+ "windows_aarch64_msvc 0.48.0",
+ "windows_i686_gnu 0.48.0",
+ "windows_i686_msvc 0.48.0",
+ "windows_x86_64_gnu 0.48.0",
+ "windows_x86_64_gnullvm 0.48.0",
+ "windows_x86_64_msvc 0.48.0",
 ]
 
+[[package]]
+name = "windows_aarch64_gnullvm"
+version = "0.42.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8"
+
 [[package]]
 name = "windows_aarch64_gnullvm"
 version = "0.48.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc"
 
+[[package]]
+name = "windows_aarch64_msvc"
+version = "0.42.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43"
+
 [[package]]
 name = "windows_aarch64_msvc"
 version = "0.48.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3"
 
+[[package]]
+name = "windows_i686_gnu"
+version = "0.42.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f"
+
 [[package]]
 name = "windows_i686_gnu"
 version = "0.48.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241"
 
+[[package]]
+name = "windows_i686_msvc"
+version = "0.42.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060"
+
 [[package]]
 name = "windows_i686_msvc"
 version = "0.48.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00"
 
+[[package]]
+name = "windows_x86_64_gnu"
+version = "0.42.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36"
+
 [[package]]
 name = "windows_x86_64_gnu"
 version = "0.48.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1"
 
+[[package]]
+name = "windows_x86_64_gnullvm"
+version = "0.42.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3"
+
 [[package]]
 name = "windows_x86_64_gnullvm"
 version = "0.48.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953"
 
+[[package]]
+name = "windows_x86_64_msvc"
+version = "0.42.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0"
+
 [[package]]
 name = "windows_x86_64_msvc"
 version = "0.48.0"

+ 2 - 0
Cargo.toml

@@ -12,3 +12,5 @@ merge_sequences  = { git = "https://github.com/Dr-TSteimle/merge_sequences" }
 desc_sequence    = { git = "https://git.t0m4.fr/Thomas/desc_sequence.git" }
 rand = "0.8.5"
 itertools = "0.10.5"
+rayon = "1.7.0"
+indicatif = {version = "0.17.5", features = ["rayon"]}

+ 110 - 44
src/main.rs

@@ -1,12 +1,14 @@
-use std::{io::{BufReader, BufRead}, fs::File, collections::HashMap, cmp};
+use std::{io::{BufReader, BufRead}, fs::File, collections::HashMap, cmp, sync::{Mutex}};
 
 use rust_htslib::{bam, bam::{Read, IndexedReader}};
 use clap::Parser;
 use rand::{thread_rng, seq::SliceRandom};
-use itertools::Itertools;
-
+use indicatif::{ProgressBar, ParallelProgressIterator};
+use std::io::Write;
 use merge_sequences::*;
 use desc_sequence::*;
+use rayon::{prelude::*, ThreadPoolBuilder};
+
 #[derive(Parser, Debug)]
 #[command(author, version, about, long_about = None)]
 struct Args {
@@ -17,31 +19,88 @@ struct Args {
     /// positions tsv path (seqname, start, end)
     #[arg(short, long)]
     positions: String,
+
+    /// output tsv path
+    #[arg(short, long)]
+    output: String,
+
+    /// output tsv path
+    #[arg(short, long)]
+    genome: String,
 }
 
 fn main() {
     let args = Args::parse();
-    let mut bam = bam::IndexedReader::from_path(&args.bam).unwrap();
 
-    let reader = BufReader::new(File::open(args.positions).unwrap());
+    let input_file = File::open(args.positions).unwrap();
 
-    for line in reader.lines() {
+    let pb = ProgressBar::new(input_file.metadata().unwrap().len());
+    
+    let ii = &mut pb.wrap_read(input_file);
+
+    let reader = BufReader::new(ii);
+
+    let mut ranges: HashMap<usize, (String, i64, i64)> = HashMap::new();
+    for (n, line) in reader.lines().enumerate() {
         if let Ok(line) = line {
             let mut split = line.split("\t");
-            select_reads(
-                &mut bam, 
-                (split.next().unwrap(), 
-                split.next().unwrap().parse().unwrap(),
-                split.next().unwrap().parse().unwrap())
+            
+            ranges.insert(
+                n, (
+                    split.next().unwrap().to_string(), 
+                    split.next().unwrap().parse().unwrap(),
+                    split.next().unwrap().parse().unwrap()
+                )
             );
         }
     }
+
+    let chunk_size = 100;
+    let ranges: Vec<(String, i64, i64)> = ranges.into_iter().map(|(_, e)| e).collect();
+    
+    let mut file = File::create(args.output).unwrap();
+    writeln!(file, "ALT\tn_reads\tdepth").unwrap();
+    let mutex = Mutex::new(file);
+
+    let n_chunks = ranges.len() / chunk_size;
+
+    ThreadPoolBuilder::new().num_threads(15).build_global().unwrap();
+
+    ranges.par_chunks(chunk_size)
+    .progress_count(n_chunks as u64)
+    .for_each(|ranges_chunk| {
+        let aligner = BwaAlign::init(&args.genome);
+        let mut bam = bam::IndexedReader::from_path(&args.bam).unwrap();
+        let mut res: Vec<(String, (i32, i32))> = Vec::new();
+        for (seqname, start, end) in ranges_chunk {
+            let r = select_reads(
+                &mut bam,
+                (seqname, *start, *end),
+                &aligner
+            );
+            res.extend(r.iter().map(|(k, v)| (k.to_string(), *v)).collect::<Vec<(String, (i32, i32))>>());
+        }
+
+        let mut file = mutex.lock().unwrap();
+        res.iter().for_each(|(alt, (n, d))| {
+            writeln!(file, "{}\t{}\t{}", alt, n, d).unwrap();
+        });
+
+    });
 }
 
-fn select_reads(bam: &mut IndexedReader, range: (&str, i64, i64)) {
-    let merge_dist = 1;
+fn select_reads(bam: &mut IndexedReader, range: (&str, i64, i64), aligner: &BwaAlign) -> HashMap<String, (i32, i32)> {
+    let merge_dist = 5;
     let _ = bam.fetch(range);
-    
+
+    let mut depths: HashMap<u32, u32> = HashMap::new();
+    for p in bam.pileup() {
+        let pileup = p.unwrap();
+        depths.insert(pileup.pos(), pileup.depth());
+    }
+
+    let _ = bam.fetch(range);
+
     let mut seqs = Vec::new();
 
     for read in bam.records() {
@@ -103,38 +162,46 @@ fn select_reads(bam: &mut IndexedReader, range: (&str, i64, i64)) {
             grouped.insert(0, (seq.2, seq.3, vec![seq.0], vec![seq.4]));
         }
     }
+ 
+    let mut results = Vec::new(); 
+    for (_k, group) in grouped {
+        if group.3.len() > 1 {
+            let res = rec_merger(group.3, 15, 2, 1 as i8);
 
-    grouped.iter().for_each(|(k, e)| {
-        println!("{}", k);
-        println!("{:?}", e);
-    });
-
-    println!("=====================================");
-
-    let aligner = BwaAlign::init("/home/thomas/NGS/tools/arriba_v2.1.0/hg38viral.fa");
-    for (k, group) in grouped {
-        println!("{}", k);
-        let res = rec_merger(group.3, 15, 2, 1 as i8);
-
-        res.iter().for_each(|s| {
-            let r = aligner.get_ref_positions_indel(&s.as_string());
-            println!("{:?}", r);
-        });
-
-        
+            res.iter().for_each(|s| {
+                let r = aligner.get_ref_positions_indel(&s.as_string());
+                results.push((group.2.clone(), s.as_string(), r));
+            });
+        } else if group.3.len() >  0 {
+            let u = group.3.first().unwrap();
+            
+            let r = aligner.get_ref_positions_indel(&u.as_string());
+            results.push((group.2.clone(), u.as_string(), r));
+        }
     }
+    
+    let mut indels: HashMap<String, (i32, i32)> = HashMap::new();
+    results
+    .into_iter()
+    .filter(|p| p.0.len() > 1 && p.2.len() >= 1)
+    .for_each(|e| {
+        e.2.iter().for_each(|em| {
+            let k = format!("{}_{}:{}-{}", em.0, em.1, em.2, em.3);
+            if let Some(val) = indels.get_mut(&k) {
+                val.0 = val.0 + e.0.len() as i32;
+            } else {
+                let depth = if let Some(v) = depths.get(&(em.2 as u32)) {
+                    *v
+                } else {
+                    0
+                };
+                
+                indels.insert(k, (e.0.len() as i32, depth as i32));
+            }
+        });
+    });
 
-    // 
-    // for s in res.iter() {
-    //     println!("{}", &s.as_string());
-    //     let r = aligner.get_ref_positions_indel(&s.as_string());
-
-    //     r.iter().for_each(|e| {
-    //         println!("{:?}", e);
-    //     })
-
-    // }
-
+    indels
 }
 
 pub fn rec_merger(mut seqs: Vec<DNAString>, kmer_len: usize, max_mismatches: i8, max_consecutive_mismatches: i8) -> Vec<DNAString> {
@@ -150,7 +217,6 @@ pub fn rec_merger(mut seqs: Vec<DNAString>, kmer_len: usize, max_mismatches: i8,
         match re {
             Some(res) => {
                 merged.push(res.0.clone());
-                // res.1.append(&mut vec![res.0]);
                 seqs = res.1;
             },
             None => {