|
1 | 1 | use std::error::Error; |
2 | | -use std::collections::{vec_deque, HashMap, BTreeMap, btree_map}; |
| 2 | +use std::collections::{HashMap, BTreeMap, btree_map}; |
3 | 3 | use std::str; |
4 | 4 |
|
5 | 5 | use itertools::Itertools; |
@@ -40,10 +40,10 @@ impl VarIndex { |
40 | 40 | }) |
41 | 41 | } |
42 | 42 |
|
43 | | - pub fn range(&self, chrom: &[u8], pos: u32) -> btree_map::Range<u32, Variant> { |
44 | | - // TODO error handling |
45 | | - let records = self.inner.get(chrom).expect("CHROM name not found in matching VCF."); |
46 | | - records.range(pos.saturating_sub(self.max_dist)..pos + self.max_dist) |
| 43 | + pub fn range(&self, chrom: &[u8], pos: u32) -> Option<btree_map::Range<u32, Variant>> { |
| 44 | + self.inner.get(chrom).map( |
| 45 | + |recs| recs.range(pos.saturating_sub(self.max_dist)..pos + self.max_dist) |
| 46 | + ) |
47 | 47 | } |
48 | 48 | } |
49 | 49 |
|
@@ -81,9 +81,11 @@ pub fn match_variants( |
81 | 81 |
|
82 | 82 | let var = try!(Variant::new(&mut rec, &mut i)); |
83 | 83 | let matching = var.alleles.iter().map(|a| { |
84 | | - for (_, v) in index.range(chrom, pos) { |
85 | | - if let Some(id) = var.matches(v, a, max_dist, max_len_diff) { |
86 | | - return id as i32; |
| 84 | + if let Some(range) = index.range(chrom, pos) { |
| 85 | + for (_, v) in range { |
| 86 | + if let Some(id) = var.matches(v, a, max_dist, max_len_diff) { |
| 87 | + return id as i32; |
| 88 | + } |
87 | 89 | } |
88 | 90 | } |
89 | 91 | -1 |
|
0 commit comments