|
|
@@ -227,17 +227,18 @@ impl BwaAlign {
|
|
|
|
|
|
if a.len() == 1 {
|
|
|
let record = a.iter().next().unwrap();
|
|
|
- let (deletions, insertions) = find_deletion_insertion_ranges(record.pos() as u32 + 1, Cigar::new_from_str(&format!("{}", record.cigar())), record.is_reverse());
|
|
|
- let contig = self.bwa_tid_contig(record.tid() as usize);
|
|
|
- deletions.iter().for_each(|(s, e)| {
|
|
|
- all_ranges.push(("deletion".to_string(), contig.to_string(), *s as i32, *e as i32));
|
|
|
- });
|
|
|
- insertions.iter().for_each(|(s, e)| {
|
|
|
- let s = *s as i32;
|
|
|
- let e = *e as i32;
|
|
|
- all_ranges.push(("insertion".to_string(), contig.to_string(), s, e ));
|
|
|
- });
|
|
|
-
|
|
|
+ if record.pos() > 0 {
|
|
|
+ let (deletions, insertions) = find_deletion_insertion_ranges(record.pos() as u32 + 1, Cigar::new_from_str(&format!("{}", record.cigar())), record.is_reverse());
|
|
|
+ let contig = self.bwa_tid_contig(record.tid() as usize);
|
|
|
+ deletions.iter().for_each(|(s, e)| {
|
|
|
+ all_ranges.push(("deletion".to_string(), contig.to_string(), *s as i32, *e as i32));
|
|
|
+ });
|
|
|
+ insertions.iter().for_each(|(s, e)| {
|
|
|
+ let s = *s as i32;
|
|
|
+ let e = *e as i32;
|
|
|
+ all_ranges.push(("insertion".to_string(), contig.to_string(), s, e ));
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
all_ranges
|
|
|
@@ -331,8 +332,11 @@ pub fn format_seq(name: &str, sequence: &str, line_size: usize) -> String {
|
|
|
}
|
|
|
|
|
|
pub fn find_deletion_insertion_ranges(start_position: u32, cigar: Cigar, is_rc: bool) -> (Vec<(u32, u32)>, Vec<(u32, u32)>) {
|
|
|
+
|
|
|
let cigar = if is_rc { cigar.expand().chars().rev().collect::<Vec<char>>() } else { cigar.expand().chars().collect::<Vec<char>>() };
|
|
|
|
|
|
+ println!("{}", start_position);
|
|
|
+ println!("{:?}", cigar);
|
|
|
// :-)
|
|
|
let mut position = start_position;
|
|
|
let mut deletion_ranges = Vec::new();
|
|
|
@@ -579,4 +583,15 @@ mod tests {
|
|
|
println!("{:?}", res);
|
|
|
|
|
|
}
|
|
|
+ #[test]
|
|
|
+ fn deletion_2() {
|
|
|
+ let ref_path = "/home/thomas/NGS/ref/hg19.fa";
|
|
|
+
|
|
|
+ let sequence = "CATCCTGTGGGCAGACAGACAAGCGGATGCC";
|
|
|
+
|
|
|
+ let aligner = BwaAlign::init(ref_path);
|
|
|
+ let res = aligner.get_ref_positions_indel(&sequence);
|
|
|
+ println!("{:?}", res);
|
|
|
+
|
|
|
+ }
|
|
|
}
|