|
|
@@ -1,7 +1,5 @@
|
|
|
use log::warn;
|
|
|
-use rust_htslib::bam::{
|
|
|
- ext::BamRecordExtensions, record::Aux, IndexedReader, Read, Record,
|
|
|
-};
|
|
|
+use rust_htslib::bam::{ext::BamRecordExtensions, record::Aux, IndexedReader, Read, Record};
|
|
|
use std::collections::HashMap;
|
|
|
|
|
|
pub fn primary_record(bam: &mut IndexedReader, record: Record) -> Record {
|
|
|
@@ -126,10 +124,10 @@ pub fn get_all_positions(
|
|
|
bam_path: &str,
|
|
|
// bam: &mut IndexedReader,
|
|
|
) -> anyhow::Result<Vec<(String, u32, u32)>> {
|
|
|
- let mut bam = rust_htslib::bam::IndexedReader::from_path(bam_path).unwrap();
|
|
|
- let header = bam.header().to_owned();
|
|
|
let mut positions = Vec::new();
|
|
|
let qname = record.qname();
|
|
|
+ let mut bam = rust_htslib::bam::IndexedReader::from_path(bam_path).unwrap();
|
|
|
+ let header = bam.header().to_owned();
|
|
|
let contig = String::from_utf8(header.tid2name(record.tid().try_into()?).to_vec())?;
|
|
|
positions.push((
|
|
|
contig,
|
|
|
@@ -150,7 +148,7 @@ pub fn get_all_positions(
|
|
|
// let cigar_str = *parts.get(3).unwrap();
|
|
|
// let end = calculate_end_position(start, cigar_str).unwrap();
|
|
|
|
|
|
- bam.fetch((chr, start, start + 1))?;
|
|
|
+ bam.fetch((chr, start - 2, start + 2))?;
|
|
|
let mut founded = false;
|
|
|
for record in bam.records().flatten() {
|
|
|
if qname == record.qname() {
|
|
|
@@ -163,8 +161,10 @@ pub fn get_all_positions(
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- positions.sort_by(|a, b| a.1.cmp(&b.1));
|
|
|
- positions.sort_by(|a, b| a.0.cmp(&b.0));
|
|
|
+ positions.sort_by(|a, b| a.0.cmp(&b.0).then(a.1.cmp(&b.1)));
|
|
|
+
|
|
|
+ // positions.sort_by(|a, b| a.1.cmp(&b.1));
|
|
|
+ // positions.sort_by(|a, b| a.0.cmp(&b.0));
|
|
|
positions.dedup();
|
|
|
Ok(positions)
|
|
|
}
|