Skip to content

Commit

Permalink
removed annoying print messages
Browse files Browse the repository at this point in the history
  • Loading branch information
“suchapalaver” committed Sep 29, 2021
1 parent 0125ec2 commit 7d9ff74
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub fn run(config: Config) -> Result<(), Box<dyn Error>> {

// 'N'
let n: u8 = 78;

// Create fasta file reader
let reader: fasta::Reader<std::io::BufReader<File>> =
fasta::Reader::from_file(&filepath).unwrap();
Expand All @@ -54,32 +54,33 @@ pub fn run(config: Config) -> Result<(), Box<dyn Error>> {
.for_each(|result| {
let seq: &[u8] = result.as_ref().unwrap().seq();

for i in 0..(seq.len() + 1).saturating_sub(k) {
for i in 0..(seq.len() + 1).saturating_sub(k) {
// Irradicate kmers containing 'N'
if !seq[i..i + k].contains(&n) {
// Make output kmers the lexicographically smaller of
// (kmer, reverse-complement)
*fasta_hash
.entry(min(seq[i..i + k].to_vec(), revcomp(&seq[i..i + k])))
.or_insert(0) += 1;
} else {}
// Make output kmers the lexicographically smaller of
// (kmer, reverse-complement)
*fasta_hash
.entry(min(seq[i..i + k].to_vec(), revcomp(&seq[i..i + k])))
.or_insert(0) += 1;
} else {
}
}
});

// PRINTING OUTPUT
eprintln!("Printing ...\n");

// Create handle and BufWriter for writing
// Create handle and BufWriter for writing
let handle = std::io::stdout();

let mut buf = BufWriter::new(handle);

fasta_hash.into_iter().for_each(|(k, f)|{
fasta_hash.into_iter().for_each(|(k, f)| {
// Write:
// >frequency across fasta file for both kmer and its reverse complement
// k-mer (lexicographically smaller of k-mer, reverse complement pair)
writeln!(buf, ">{}\n{}", f, str::from_utf8(&k).unwrap()).expect("Unable to write data");
});

buf.flush().unwrap();
eprintln!("Done\n");

Ok(())
}

0 comments on commit 7d9ff74

Please sign in to comment.