Thomas преди 2 години
родител
ревизия
9f2efc09d7
променени са 1 файла, в които са добавени 5 реда и са изтрити 2 реда
  1. 5 2
      src/lib.rs

+ 5 - 2
src/lib.rs

@@ -128,13 +128,16 @@ pub fn range_depths(
 ) -> Result<Vec<u32>> {
     bam.fetch((chr, start, stop))?;
 
-    let mut depths = Vec::new();
+    let mut depths = Vec::with_capacity((stop - start) as usize);
+    depths.fill(0);
 
     for p in bam.pileup() {
         let pileup = p.context(format!("eRR"))?;
         let rstart = pileup.pos() as i32;
         if rstart >= start && rstart < stop {
-            depths.push(pileup.depth());
+            // depths.push(pileup.depth());
+            let v = depths.get_mut((rstart - start) as usize).unwrap();
+            *v = pileup.depth();
         } else if rstart >= stop {
             break;
         }