|
|
@@ -1,35 +1,49 @@
|
|
|
+use std::{fs::File, io::{BufReader, BufRead}};
|
|
|
+
|
|
|
use rust_htslib::{bam, bam::{Read, IndexedReader}};
|
|
|
use clap::Parser;
|
|
|
|
|
|
#[derive(Parser, Debug)]
|
|
|
#[command(author, version, about, long_about = None)]
|
|
|
struct Args {
|
|
|
- /// Name of the perso≥n to greet
|
|
|
+ /// bam file path
|
|
|
#[arg(short, long)]
|
|
|
bam: String,
|
|
|
|
|
|
- /// Number of times to greet
|
|
|
+ /// positions tsv path (seqname, start, end)
|
|
|
#[arg(short, long)]
|
|
|
- position: String,
|
|
|
+ positions: String,
|
|
|
}
|
|
|
|
|
|
fn main() {
|
|
|
let args = Args::parse();
|
|
|
let mut bam = bam::IndexedReader::from_path(&args.bam).unwrap();
|
|
|
|
|
|
- // /Turbine-pool/LAL-T_ChIP/BAM/525/merged.bam
|
|
|
- // /Turbine-pool/LAL-T_ChIP/BAM/885/merged.bam
|
|
|
- let start = 47239294;
|
|
|
- let end = 47239298;
|
|
|
+ let reader = BufReader::new(File::open(args.positions).unwrap());
|
|
|
+
|
|
|
+ let mut results: Vec<Result> = Vec::new();
|
|
|
+ for line in reader.lines() {
|
|
|
+ if let Ok(line) = line {
|
|
|
+ let mut split = line.split("\t");
|
|
|
+ results.extend(
|
|
|
+ fetch_ins(
|
|
|
+ &mut bam,
|
|
|
+ split.next().unwrap(),
|
|
|
+ split.next().unwrap().parse().unwrap(),
|
|
|
+ split.next().unwrap().parse().unwrap()
|
|
|
+ )
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- let results = fetch_ins(&mut bam, "chr1", start, end);
|
|
|
+ results.dedup();
|
|
|
|
|
|
for result in results {
|
|
|
println!("{}", result.tsv());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-#[derive(Debug)]
|
|
|
+#[derive(Debug, PartialEq)]
|
|
|
struct Result {
|
|
|
read_name: String,
|
|
|
seqname: String,
|
|
|
@@ -98,13 +112,6 @@ fn fetch_ins(bam: &mut IndexedReader, seqname: &str, start: u32, end: u32) -> Ve
|
|
|
inserted_seq,
|
|
|
depth: pileup.depth()
|
|
|
});
|
|
|
-
|
|
|
- // println!(
|
|
|
- // "{}\t{}:{}_{}ins[{}]\t{}",
|
|
|
- // String::from_utf8_lossy(alignment.record().qname()),
|
|
|
- // alignment.record().tid(), ref_pos, ref_pos + 1, inserted_seq,
|
|
|
- // pileup.depth()
|
|
|
- // );
|
|
|
},
|
|
|
_ => ()
|
|
|
}
|