Skip to content

Commit

Permalink
make tests pass with mc
Browse files Browse the repository at this point in the history
  • Loading branch information
fellen31 committed May 16, 2024
1 parent f08e5b1 commit 300be24
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ mod tests {
start: 1,
end: 100,
id: "".to_string(),
motifs: "CA".to_string(),
},
);
println!("Consensus: {}", cons.seq.unwrap());
Expand Down
6 changes: 6 additions & 0 deletions src/genotype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ mod tests {
start: 154654404,
end: 154654432,
id: String::from("test-repeat"),
motifs: "CA".to_string(),
};
let flanking = 2000;
let minlen = 5;
Expand Down Expand Up @@ -371,6 +372,7 @@ mod tests {
start: 154654404,
end: 154654432,
id: "TEST".to_string(),
motifs: "CA".to_string(),
};
let args = Cli {
bam: String::from("test_data/small-test-phased.bam"),
Expand Down Expand Up @@ -400,6 +402,7 @@ mod tests {
start: 154654404,
end: 154654432,
id: "TEST".to_string(),
motifs: "CA".to_string(),
};
let args = Cli {
bam: String::from("test_data/small-test-phased.bam"),
Expand Down Expand Up @@ -445,6 +448,7 @@ mod tests {
start: 154654404,
end: 154654432,
id: "TEST".to_string(),
motifs: "CA".to_string(),
};
let mut bam = parse_bam::create_bam_reader(&args.bam, &args.fasta);
let genotype = genotype_repeat(&repeat, &args, &mut bam);
Expand Down Expand Up @@ -474,6 +478,7 @@ mod tests {
start: 154654404,
end: 154654432,
id: "TEST".to_string(),
motifs: "CA".to_string(),
};
let mut bam = parse_bam::create_bam_reader(&args.bam, &args.fasta);
let genotype = genotype_repeat(&repeat, &args, &mut bam);
Expand Down Expand Up @@ -504,6 +509,7 @@ mod tests {
start: 154654404,
end: 154654432,
id: "TEST".to_string(),
motifs: "CA".to_string(),
};
let mut bam = parse_bam::create_bam_reader(&args.bam, &args.fasta);
let genotype = genotype_repeat(&repeat, &args, &mut bam);
Expand Down
36 changes: 23 additions & 13 deletions src/motif.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@ fn create_motif(seq: &str) -> String {
}

pub fn create_mc(motifs_string: &str, repeats: &str) -> String {
let motifs: Vec<String> = motifs_string.split(',').map(|s| s.to_string()).collect();

let mut motif_counts = vec![0; motifs.len()];
for motif in motifs.iter() {
let mut start = 0;
while let Some(index) = repeats[start..].find(motif) {
motif_counts[motifs.iter().position(|x| x == motif).unwrap()] += 1;
start += index + motif.len();
}
}
motif_counts.iter().map(|count| count.to_string()).collect::<Vec<String>>().join("_")
}
let motifs: Vec<String> = motifs_string.split(',').map(|s| s.to_string()).collect();

let mut motif_counts = vec![0; motifs.len()];
for motif in motifs.iter() {
let mut start = 0;
while let Some(index) = repeats[start..].find(motif) {
motif_counts[motifs.iter().position(|x| x == motif).unwrap()] += 1;
start += index + motif.len();
}
}
motif_counts.iter().map(|count| count.to_string()).collect::<Vec<String>>().join("_")
}

#[cfg(test)]
mod tests {
Expand All @@ -32,11 +31,22 @@ mod tests {
"(CAG)4(CGG)3(CAG)3"
);
}
#[test]
fn test_create_mc() {
let motifs = "ATG,CGT,GCA";
let repeat = "ATGCGTATGCGTAGCGT";
println!("{:?}", create_mc(&motifs, &repeat));
assert_eq!(
create_mc(&motifs, repeat), "2_3_0"
);
}
#[test]
fn test_create_mc_with_n() {
let motifs = "NCG";
let repeat = "ACGACGACGACG";

assert_eq!(
create_mc(&motifs, repeat), "3_1_0"
create_mc(&motifs, repeat), "4"
);
}
}
5 changes: 5 additions & 0 deletions src/parse_bam.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ fn test_get_overlapping_reads() {
start: 154654404,
end: 154654432,
id: "TEST".to_string(),
motifs: "CA".to_string(),
};
let unphased = false;
let mut bam = create_bam_reader(&bam, &fasta);
Expand All @@ -159,6 +160,7 @@ fn test_get_overlapping_reads_url1() {
start: 154654404,
end: 154654432,
id: "TEST".to_string(),
motifs: "CA".to_string(),
};
let unphased = false;
let mut bam = create_bam_reader(&bam, &fasta);
Expand All @@ -174,6 +176,7 @@ fn test_get_overlapping_reads_url2() {
start: 154654404,
end: 154654432,
id: "TEST".to_string(),
motifs: "CA".to_string(),
};
let unphased = false;
let mut bam = create_bam_reader(&bam, &fasta);
Expand All @@ -189,6 +192,7 @@ fn test_get_overlapping_reads_url3() {
start: 154654404,
end: 154654432,
id: "TEST".to_string(),
motifs: "CA".to_string(),
};
let unphased = false;
let mut bam = create_bam_reader(&bam, &fasta);
Expand All @@ -204,6 +208,7 @@ fn test_get_overlapping_reads_url4() {
start: 154654404,
end: 154654432,
id: "TEST".to_string(),
motifs: "CA".to_string(),
};
let unphased = false;
let mut bam = create_bam_reader(&bam, &fasta);
Expand Down
6 changes: 6 additions & 0 deletions src/phase_insertions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ mod tests {
start: 154654404,
end: 154654432,
id: "TEST".to_string(),
motifs: "CA".to_string(),
},
false,
);
Expand Down Expand Up @@ -374,6 +375,7 @@ mod tests {
start: 154654404,
end: 154654432,
id: "TEST".to_string(),
motifs: "CA".to_string(),
},
false,
);
Expand Down Expand Up @@ -414,6 +416,7 @@ mod tests {
start: 154654404,
end: 154654432,
id: "TEST".to_string(),
motifs: "CA".to_string(),
},
false,
);
Expand Down Expand Up @@ -457,6 +460,7 @@ mod tests {
start: 154654404,
end: 154654432,
id: "TEST".to_string(),
motifs: "CA".to_string(),
},
false,
);
Expand Down Expand Up @@ -498,6 +502,7 @@ mod tests {
start: 154654404,
end: 154654432,
id: "TEST_RFC1".to_string(),
motifs: "CA".to_string(),
},
false,
);
Expand Down Expand Up @@ -570,6 +575,7 @@ mod tests {
start: 154654404,
end: 154654432,
id: "TEST_RFC1".to_string(),
motifs: "CA".to_string(),
},
false,
);
Expand Down

0 comments on commit 300be24

Please sign in to comment.