extern crate fasten;
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;
fn main(){
let mut opts = fasten_base_options();
opts.optopt("r","reads","Number of reads or pairs of reads to keep, default: 10","INT");
opts.optopt("b","bases","Number of bases to keep, default: 0 (zero for no limit).","INT");
let matches = fasten_base_options_matches("Keep first N reads or bases", opts);
let max_reads: usize = {
if matches.opt_present("reads") {
matches.opt_str("reads")
.expect("ERROR parsing reads parameter")
.parse()
.expect("ERROR parsing reads as an integer")
} else {
10
}
};
let max_bases: usize = {
if matches.opt_present("bases") {
matches.opt_str("bases")
.expect("ERROR parsing bases parameter")
.parse()
.expect("ERROR parsing bases as an integer")
} else {
0
}
};
let lines_per_read={
if matches.opt_present("paired-end") {
8
}else{
4
}
};
let my_file = File::open("/dev/stdin").expect("Could not open file");
let my_buffer=BufReader::new(my_file);
let mut line_counter =0;
let mut entry = String::new();
let mut bases_counter=0;
let mut reads_counter=0;
for line in my_buffer.lines() {
let line=line.expect("ERROR: did not get a line");
line_counter+=1;
entry.push_str(&line);
entry.push_str("\n");
let mod_line = line_counter % lines_per_read;
match mod_line {
2 => {
bases_counter += line.len();
},
0 => {
reads_counter+=1;
if max_bases > 0 && bases_counter > max_bases {
break;
}
if reads_counter > max_reads {
break;
}
print!("{}",entry);
entry = String::new();
},
_ => {
}
}
}
}