|
|
@@ -352,20 +352,20 @@ impl SequencesGraph {
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
pub struct Sam {
|
|
|
- query_name : String,
|
|
|
- query_range: Range<usize>,
|
|
|
- ref_name : String,
|
|
|
- ref_pos : i64,
|
|
|
- ref_range : Range<usize>,
|
|
|
- sequence : String,
|
|
|
- ref_sequence: String,
|
|
|
- ref_cigar : String,
|
|
|
+ pub query_name : String,
|
|
|
+ pub query_range: Range<usize>,
|
|
|
+ pub ref_name : String,
|
|
|
+ pub ref_pos : i64,
|
|
|
+ pub ref_range : Range<usize>,
|
|
|
+ pub sequence : String,
|
|
|
+ pub ref_sequence: String,
|
|
|
+ pub ref_cigar : String,
|
|
|
}
|
|
|
|
|
|
impl Sam {
|
|
|
pub fn new(query_name: String, flag: i32, ref_name: String, ref_pos: i64, cigar: String, sequence: String, fa: &Fasta) -> Self {
|
|
|
let mut sequence = sequence;
|
|
|
- let (mut ref_range, mut query_range, ref_cigar) = matched_range(&cigar, &flag, &mut sequence);
|
|
|
+ let (mut ref_range, query_range, ref_cigar) = matched_range(&cigar, &flag, &mut sequence);
|
|
|
|
|
|
|
|
|
if is_reverse(flag) {
|
|
|
@@ -385,13 +385,13 @@ impl Sam {
|
|
|
}
|
|
|
#[derive(Debug, Clone)]
|
|
|
pub struct NeoContig {
|
|
|
- sequence_id: usize,
|
|
|
- name: String,
|
|
|
- contig : String,
|
|
|
- alignments : Vec<Sam>,
|
|
|
- sequences: HashMap<NodeIndex, String>,
|
|
|
- sequences_names: HashMap<NodeIndex, String>,
|
|
|
- stretch : Vec<(NodeIndex, i32)>,
|
|
|
+ pub sequence_id: usize,
|
|
|
+ pub name: String,
|
|
|
+ pub contig : String,
|
|
|
+ pub alignments : Vec<Sam>,
|
|
|
+ pub sequences: HashMap<NodeIndex, String>,
|
|
|
+ pub sequences_names: HashMap<NodeIndex, String>,
|
|
|
+ pub stretch : Vec<(NodeIndex, i32)>,
|
|
|
}
|
|
|
|
|
|
impl NeoContig {
|
|
|
@@ -408,9 +408,10 @@ impl NeoContig {
|
|
|
|
|
|
let mut alignments: Vec<Sam> = Vec::new();
|
|
|
stdout.split("\n").for_each(|line|{
|
|
|
+ println!("{:?}", line);
|
|
|
if line.len() > 9 {
|
|
|
if &line[0..9] == "sequence_" {
|
|
|
- // println!("{:?}", line);
|
|
|
+
|
|
|
let mut qname: Option<String> = None;
|
|
|
let mut flag: Option<i32> = None;
|
|
|
let mut rname: Option<String> = None;
|
|
|
@@ -448,7 +449,7 @@ impl NeoContig {
|
|
|
|
|
|
// ref 1
|
|
|
if self.alignments.len() > 0 {
|
|
|
- let mut ref_spaces = " ".repeat(self.alignments[0].query_range.start).as_bytes().to_vec();
|
|
|
+ let ref_spaces = " ".repeat(self.alignments[0].query_range.start).as_bytes().to_vec();
|
|
|
|
|
|
// ref sequence
|
|
|
let mut l = ref_spaces.clone();
|
|
|
@@ -457,14 +458,14 @@ impl NeoContig {
|
|
|
let mut filtered_ref: Vec<u8> = self.alignments[0].ref_sequence
|
|
|
.as_bytes()
|
|
|
.iter().enumerate()
|
|
|
- .filter(|(i, c)| ref_cigar[*i] == b"M"[0])
|
|
|
- .map(|(i, c)| *c)
|
|
|
+ .filter(|(i, _)| ref_cigar[*i] == b"M"[0])
|
|
|
+ .map(|(_, c)| *c)
|
|
|
.collect();
|
|
|
l.append(&mut filtered_ref);
|
|
|
lines.push(l);
|
|
|
|
|
|
// match pipes
|
|
|
- let mut match_pipes = self.alignments[0].ref_cigar.as_bytes().iter().filter(|c| **c == b"M"[0]).map(|c| b"|"[0])
|
|
|
+ let mut match_pipes = self.alignments[0].ref_cigar.as_bytes().iter().filter(|c| **c == b"M"[0]).map(|_| b"|"[0])
|
|
|
.collect::<Vec<u8>>();
|
|
|
|
|
|
let mut l = ref_spaces.clone();
|
|
|
@@ -482,7 +483,7 @@ impl NeoContig {
|
|
|
}
|
|
|
|
|
|
// Contig
|
|
|
- let mut contig = format!("{} - denovo assembled contig (cov = {})",
|
|
|
+ let contig = format!("{} - denovo assembled contig (cov = {})",
|
|
|
self.contig,
|
|
|
self.sequences.len()
|
|
|
).as_bytes().to_vec();
|
|
|
@@ -507,10 +508,10 @@ impl NeoContig {
|
|
|
// other ref
|
|
|
if self.alignments.len() > 1 {
|
|
|
|
|
|
- let mut ref_spaces = " ".repeat(self.alignments[1].query_range.start).as_bytes().to_vec();
|
|
|
+ let ref_spaces = " ".repeat(self.alignments[1].query_range.start).as_bytes().to_vec();
|
|
|
|
|
|
// match pipes
|
|
|
- let mut match_pipes = self.alignments[1].ref_cigar.as_bytes().iter().filter(|c| **c == b"M"[0]).map(|c| b"|"[0])
|
|
|
+ let mut match_pipes = self.alignments[1].ref_cigar.as_bytes().iter().filter(|c| **c == b"M"[0]).map(|_| b"|"[0])
|
|
|
.collect::<Vec<u8>>();
|
|
|
let mut l = ref_spaces.clone();
|
|
|
l.append(&mut match_pipes);
|
|
|
@@ -532,8 +533,8 @@ impl NeoContig {
|
|
|
let mut filtered_ref: Vec<u8> = self.alignments[1].ref_sequence
|
|
|
.as_bytes()
|
|
|
.iter().enumerate()
|
|
|
- .filter(|(i, c)| ref_cigar[*i] == b"M"[0])
|
|
|
- .map(|(i, c)| *c)
|
|
|
+ .filter(|(i, _)| ref_cigar[*i] == b"M"[0])
|
|
|
+ .map(|(_, c)| *c)
|
|
|
.collect();
|
|
|
l.append(&mut filtered_ref);
|
|
|
lines.push(l);
|
|
|
@@ -598,7 +599,7 @@ fn matched_range (cigar: &str, flag: &i32, matched_seq: &mut str) -> (Range<usiz
|
|
|
let mut ref_pos = 0;
|
|
|
let mut ref_cigar_string = "".to_string();
|
|
|
|
|
|
- let mut pos = 0;
|
|
|
+ // let mut pos = 0;
|
|
|
|
|
|
let mut first_m = true;
|
|
|
let n_op = cigar.split("").filter(|c| all_op.contains(c)).count();
|
|
|
@@ -644,7 +645,7 @@ fn matched_range (cigar: &str, flag: &i32, matched_seq: &mut str) -> (Range<usiz
|
|
|
let toadd = f.repeat(current_add);
|
|
|
ref_cigar_string.push_str(&toadd);
|
|
|
}
|
|
|
- pos += current_add;
|
|
|
+ // pos += current_add;
|
|
|
}
|
|
|
},
|
|
|
}
|
|
|
@@ -751,13 +752,3 @@ fn match_tol (s1: &[u8], s2: &[u8], max_consecutive: usize, max_diffs: usize) ->
|
|
|
false
|
|
|
}
|
|
|
}
|
|
|
-#[cfg(test)]
|
|
|
-mod tests {
|
|
|
- use super::*;
|
|
|
-
|
|
|
- #[test]
|
|
|
- fn it_works() {
|
|
|
- // let result = add(2, 2);
|
|
|
- // assert_eq!(result, 4);
|
|
|
- }
|
|
|
-}
|