|
|
@@ -334,12 +334,17 @@ impl Contig {
|
|
|
write_fai(&fasta_path);
|
|
|
|
|
|
let reads_path = format!("{contig_dir}/reads.fa");
|
|
|
- let n_reads = self.supporting_records.clone().into_iter().map(|r| {
|
|
|
- (
|
|
|
- String::from_utf8(r.qname().to_vec()).unwrap(),
|
|
|
- String::from_utf8(r.seq().as_bytes()).unwrap(),
|
|
|
- )
|
|
|
- }).collect();
|
|
|
+ let n_reads = self
|
|
|
+ .supporting_records
|
|
|
+ .clone()
|
|
|
+ .into_iter()
|
|
|
+ .map(|r| {
|
|
|
+ (
|
|
|
+ String::from_utf8(r.qname().to_vec()).unwrap(),
|
|
|
+ String::from_utf8(r.seq().as_bytes()).unwrap(),
|
|
|
+ )
|
|
|
+ })
|
|
|
+ .collect();
|
|
|
write_fasta(&reads_path, &n_reads);
|
|
|
|
|
|
let bam_path = format!("{contig_dir}/{}.bam", self.id);
|
|
|
@@ -349,12 +354,32 @@ impl Contig {
|
|
|
match &self.contig_ref {
|
|
|
ContigRef::Chimeric((a, b)) => {
|
|
|
let d = vec![
|
|
|
- (self.id.clone(), a.query_start, a.query_end, format!("{}:{}-{}", a.target_name.clone().unwrap(), a.target_start, a.target_end)),
|
|
|
- (self.id.clone(), b.query_start, b.query_end, format!("{}:{}-{}", b.target_name.clone().unwrap(), b.target_start, b.target_end))
|
|
|
+ (
|
|
|
+ self.id.clone(),
|
|
|
+ a.query_start,
|
|
|
+ a.query_end,
|
|
|
+ format!(
|
|
|
+ "{}:{}-{}",
|
|
|
+ a.target_name.clone().unwrap(),
|
|
|
+ a.target_start,
|
|
|
+ a.target_end
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ (
|
|
|
+ self.id.clone(),
|
|
|
+ b.query_start,
|
|
|
+ b.query_end,
|
|
|
+ format!(
|
|
|
+ "{}:{}-{}",
|
|
|
+ b.target_name.clone().unwrap(),
|
|
|
+ b.target_start,
|
|
|
+ b.target_end
|
|
|
+ ),
|
|
|
+ ),
|
|
|
];
|
|
|
write_bed(&bed_path, &d)?;
|
|
|
- },
|
|
|
- _ => ()
|
|
|
+ }
|
|
|
+ _ => (),
|
|
|
}
|
|
|
|
|
|
Ok(())
|
|
|
@@ -438,7 +463,16 @@ pub fn write_bed(path: &str, d: &Vec<(String, i32, i32, String)>) -> Result<()>
|
|
|
let file = File::create(path).unwrap();
|
|
|
let mut writer = BufWriter::new(file);
|
|
|
for (chr, start, end, value) in d.iter() {
|
|
|
- let row = format!("{}\n", vec![chr.to_string(), start.to_string(), end.to_string(), value.to_string()].join("\t"));
|
|
|
+ let row = format!(
|
|
|
+ "{}\n",
|
|
|
+ vec![
|
|
|
+ chr.to_string(),
|
|
|
+ start.to_string(),
|
|
|
+ end.to_string(),
|
|
|
+ value.to_string()
|
|
|
+ ]
|
|
|
+ .join("\t")
|
|
|
+ );
|
|
|
writer.write_all(row.as_bytes())?;
|
|
|
}
|
|
|
Ok(())
|
|
|
@@ -482,7 +516,11 @@ pub fn write_fasta(fasta_path: &str, d: &Vec<(String, String)>) {
|
|
|
}
|
|
|
|
|
|
pub fn write_fai(path: &str) {
|
|
|
- let mut faidx = Command::new("samtools").arg("faidx").arg(path).spawn().expect("Samtools faidx failed to start");
|
|
|
+ let mut faidx = Command::new("samtools")
|
|
|
+ .arg("faidx")
|
|
|
+ .arg(path)
|
|
|
+ .spawn()
|
|
|
+ .expect("Samtools faidx failed to start");
|
|
|
faidx.wait().unwrap();
|
|
|
}
|
|
|
|
|
|
@@ -536,8 +574,6 @@ pub fn create_bam(ref_path: &str, reads_path: &str, bam_path: &str) -> Result<()
|
|
|
Ok(())
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
#[cfg(test)]
|
|
|
mod tests {
|
|
|
use super::*;
|