extern crate fasten;
extern crate statistical;
extern crate getopts;
use std::fs::File;
use std::io::BufReader;
use std::io::BufRead;
use fasten::fasten_base_options;
use fasten::fasten_base_options_matches;
use fasten::logmsg;
fn main(){
let mut opts = fasten_base_options();
opts.optopt("m","max-quality","The maximum quality at which a base will be transformed to 'N'","INT");
let matches = fasten_base_options_matches("Transforms any low-quality base to 'N'.", opts);
if matches.opt_present("paired-end") {
logmsg("WARNING: --paired-end is not utilized in this script");
}
let max_quality_offset :u8={
if matches.opt_present("max-quality") {
matches.opt_str("max-quality")
.expect("ERROR: could not understand parameter --max-quality")
.parse()
.expect("ERROR: --max-quality is not an INT")
} else {
0
}
};
let max_quality :u8 = max_quality_offset + 33;
let filename = "/dev/stdin";
let my_file = File::open(&filename).expect("Could not open file");
let my_buffer=BufReader::new(my_file);
let mut num_lines=0;
let mut current_id :String = String::new();
let mut current_seq :String = String::new();
for line in my_buffer.lines() {
num_lines+=1;
match num_lines % 4 {
1 => {
current_id = line.expect("ERROR reading id line");
}
2 => {
current_seq = line.expect("ERROR reading seq line");
}
0 => {
let current_qual_cigar = line.expect("ERROR reading qual line");
let mut seq_chars = current_seq.chars();
let mut new_seq =String::new();
let mut new_qual=String::new();
for current_qual in current_qual_cigar.chars() {
let current_nt=seq_chars.next().expect("ERROR: could not get the next nt in the sequence");
let phred = current_qual as u8;
if phred < max_quality {
new_seq.push('N');
new_qual.push('!');
} else {
new_seq.push(current_nt);
new_qual.push(current_qual);
}
}
println!("{}\n{}\n+\n{}",¤t_id,new_seq,new_qual);
}
_ => { }
};
}
}