|
|
@@ -5,7 +5,7 @@ use noodles_fasta as fasta;
|
|
|
use rust_htslib::bam::{self, Record};
|
|
|
use std::{
|
|
|
collections::{HashMap, VecDeque},
|
|
|
- fmt,
|
|
|
+ fmt::{self, format},
|
|
|
fs::{self, File},
|
|
|
io::{BufWriter, Write},
|
|
|
process::{Command, Stdio},
|
|
|
@@ -345,6 +345,18 @@ impl Contig {
|
|
|
let bam_path = format!("{contig_dir}/{}.bam", self.id);
|
|
|
create_bam(&fasta_path, &reads_path, &bam_path)?;
|
|
|
|
|
|
+ let bed_path = format!("{contig_dir}/contig.bed");
|
|
|
+ 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))
|
|
|
+ ];
|
|
|
+ write_bed(&bed_path, &d)?;
|
|
|
+ },
|
|
|
+ _ => ()
|
|
|
+ }
|
|
|
+
|
|
|
Ok(())
|
|
|
}
|
|
|
|
|
|
@@ -422,6 +434,16 @@ fn group_mappings(mappings: &mut Vec<Mapping>) -> Result<Vec<Vec<Mapping>>> {
|
|
|
Ok(alignments)
|
|
|
}
|
|
|
|
|
|
+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"));
|
|
|
+ writer.write_all(row.as_bytes())?;
|
|
|
+ }
|
|
|
+ Ok(())
|
|
|
+}
|
|
|
+
|
|
|
// unique
|
|
|
pub fn write_fastq(fastq_path: &str, d: &Vec<Record>) -> Result<()> {
|
|
|
let file = File::create(fastq_path)?;
|
|
|
@@ -438,7 +460,6 @@ pub fn write_fastq(fastq_path: &str, d: &Vec<Record>) -> Result<()> {
|
|
|
Ok(())
|
|
|
}
|
|
|
|
|
|
-// unique
|
|
|
pub fn write_fasta(fasta_path: &str, d: &Vec<(String, String)>) {
|
|
|
let file = File::create(fasta_path).unwrap();
|
|
|
let mut writer = fasta::writer::Builder::default().build_with_writer(file);
|