extern crate regex;
extern crate statistical;
extern crate getopts;
use std::env;
use std::path::Path;
use std::collections::HashMap;
use getopts::Options;
use getopts::Matches;
pub mod io;
const VERSION: &'static str = env!("CARGO_PKG_VERSION");
static INVALID_ID :&'static str= "invalid_id";
static INVALID_SEQ :&'static str= "invalid_seq";
static INVALID_PLUS:&'static str= "invalid_plus";
static INVALID_QUAL:&'static str= "invalid_qual";
pub fn eexit() -> () {
println!("{}\n{}\n{}\n{}",INVALID_ID,INVALID_SEQ,INVALID_PLUS,INVALID_QUAL);
std::process::exit(1);
}
#[macro_export]
macro_rules! print (
($($arg:tt)*) => ({
use std::io::{self, Write};
if let Err(_) = write!(io::stdout(), $($arg)*) {
::std::process::exit(0);
}
})
);
pub fn fasten_base_options() -> Options{
let mut opts = Options::new();
opts.optflag("h", "help", "Print this help menu.");
opts.optopt("n","numcpus","Number of CPUs (default: 1)","INT");
opts.optflag("p","paired-end","The input reads are interleaved paired-end");
opts.optflag("","verbose","Print more status messages");
opts.optflag("","version","Print the version of Fasten and exit");
return opts;
}
pub fn fasten_base_options_matches(brief:&str, opts:Options) -> Matches{
let args: Vec<String> = env::args().collect();
let matches = opts.parse(&args[1..]).expect("ERROR: could not parse parameters");
if matches.opt_present("version") {
println!("Fasten v{}", &VERSION);
std::process::exit(0);
}
if matches.opt_present("h") {
let prog_name = Path::new(&args[0])
.file_stem().unwrap()
.to_str().unwrap();
println!("{}: {}\n\n{}",
&prog_name,
&brief,
&opts.usage(
&opts.short_usage(&prog_name)
),
);
std::process::exit(0);
}
return matches;
}
pub fn logmsg<S: AsRef<str>>(stringlike: S) {
let args: Vec<_> = env::args().collect();
let program = Path::file_name(Path::new(&args[0])).unwrap().to_str().unwrap();
let str_ref = stringlike.as_ref();
eprintln!("{}: {}", &program, str_ref);
}
pub fn reverse_complement(dna: &str) -> String {
let complement_map: HashMap<char, char> = [
('A', 'T'), ('T', 'A'), ('G', 'C'), ('C', 'G'),
('R', 'Y'), ('Y', 'R'), ('S', 'S'), ('W', 'W'),
('K', 'M'), ('M', 'K'), ('B', 'V'), ('V', 'B'),
('D', 'H'), ('H', 'D'), ('N', 'N'),
('a', 't'), ('t', 'a'), ('g', 'c'), ('c', 'g'),
('r', 'y'), ('y', 'r'), ('s', 's'), ('w', 'w'),
('k', 'm'), ('m', 'k'), ('b', 'v'), ('v', 'b'),
('d', 'h'), ('h', 'd'), ('n', 'n'),
]
.iter()
.cloned()
.collect();
dna.chars()
.rev()
.map(|base| complement_map.get(&base).cloned().unwrap_or('N')) .collect()
}