Skip to content

Commit

Permalink
Add in --version (#10)
Browse files Browse the repository at this point in the history
* making moves to streamline arg parsing and add in --version

* refactored getopts

* m
  • Loading branch information
lskatz authored Mar 17, 2022
1 parent 3cb5439 commit cfffc1c
Show file tree
Hide file tree
Showing 20 changed files with 83 additions and 149 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fasten"
version = "0.4.3"
version = "0.4.4"
authors = ["Lee Katz <[email protected]>"]
#license-file = "LICENSE"
license = "MIT"
Expand Down
10 changes: 2 additions & 8 deletions src/bin/fasten_clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ extern crate threadpool;
use std::fs::File;
use std::io::BufReader;
use std::io::BufRead;
use std::env;

use threadpool::ThreadPool;
use std::sync::mpsc::channel;

use fasten::fasten_base_options;
use fasten::fasten_base_options_matches;
//use fasten::logmsg;

#[test]
Expand Down Expand Up @@ -128,7 +128,6 @@ D>C1'02C+=I@IEFHC7&-E5',I?E*33E/@3#68B%\"!B-/2%(G=*@D052IA!('7-*$+A6>.$89,-CG71=
}

fn main(){
let args: Vec<String> = env::args().collect();
let mut opts = fasten_base_options();

// invisible option but maybe we can expose it:
Expand All @@ -140,12 +139,7 @@ fn main(){
opts.optopt("","min-avg-quality","Minimum average quality for each read","FLOAT");
opts.optopt("","min-trim-quality","Trim the edges of each read until a nucleotide of at least X quality is found","INT");

let matches = opts.parse(&args[1..]).expect("ERROR: could not parse parameters");

if matches.opt_present("h") {
println!("{}", opts.usage(&opts.short_usage(&args[0])));
std::process::exit(0);
}
let matches = fasten_base_options_matches("Trims and filters reads", opts);

let mut min_length :usize = 0;
if matches.opt_present("min-length") {
Expand Down
13 changes: 3 additions & 10 deletions src/bin/fasten_combine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ use std::io::stdin;
//use std::io::BufRead;
use std::collections::HashMap;

use std::env;
use std::f32;

use fasten::fasten_base_options;
use fasten::fasten_base_options_matches;
use fastq::{Parser, Record};
use fasten::logmsg;

Expand All @@ -51,7 +51,6 @@ const TEN: f32 = 10.0;
const READ_SEPARATOR :char = '~';

fn main(){
let args: Vec<String> = env::args().collect();
let mut opts = fasten_base_options();

// make a string of characters like !"#...GHI to represent all quals
Expand All @@ -72,15 +71,9 @@ fn main(){
format!("Minimum quality character (default: {})", default_phred_min_char).as_str(),
"CHAR");

let matches = opts.parse(&args[1..]).expect("Parsing parameters");
let description:String = format!("Collapse identical reads into single reads, recalculating quality values. If paired end, then each set of reads must be identical to be collapsed. Warning: due to multiple reads collapsing into one, read identifiers will be reconstituted. NOTE: range of quality scores is {}", qual_range_string);
let matches = fasten_base_options_matches(&description, opts);

if matches.opt_present("h") {
println!("Collapse identical reads into single reads, recalculating quality values. If paired end, then each set of reads must be identical to be collapsed. Warning: due to multiple reads collapsing into one, read identifiers will be reconstituted.");
println!("{}",opts.usage(&opts.short_usage(&args[0])));
println!("NOTE: range of quality scores is {}", qual_range_string);
std::process::exit(0);
}

let max_qual_char:char = matches.opt_default("max-qual-char", &default_phred_max_char.to_string())
.unwrap_or(String::from(default_phred_max_char))
.parse()
Expand Down
15 changes: 5 additions & 10 deletions src/bin/fasten_convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,12 @@ extern crate bam;
use bam::RecordReader;

use fasten::fasten_base_options;
use fasten::fasten_base_options_matches;
use fasten::logmsg;

use std::io::stdin;
use fastq::{Parser, Record};

use std::env;

use std::sync::mpsc::channel;

/// Struct that can handle paired end reads
Expand Down Expand Up @@ -123,16 +122,12 @@ fn test_fastq_to () {
*/

fn main(){
let args: Vec<String> = env::args().collect();
let mut opts = fasten_base_options();
opts.optopt("i", "in-format", "The input format for stdin", "FORMAT");
opts.optopt("o", "out-format", "The output format for stdin", "FORMAT");
opts.optopt("i", "in-format", "The input format for stdin. FORMAT can be: fastq, fasta, sam.", "FORMAT");
opts.optopt("o", "out-format", "The output format for stdin. See --in-format for FORMAT options.", "FORMAT");

let matches = opts.parse(&args[1..]).expect("ERROR: could not parse parameters");
if matches.opt_present("help") {
println!("{} FORMAT can be: fastq, fasta, sam\n", opts.usage(&opts.short_usage(&args[0])));
std::process::exit(0);
}
let description:String = format!("Converts between sequence formats.");
let matches = fasten_base_options_matches(&description, opts);

let paired_end = matches.opt_present("paired-end");

Expand Down
11 changes: 3 additions & 8 deletions src/bin/fasten_kmer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ extern crate getopts;

use std::io::BufReader;
use std::io::BufRead;
use std::env;
use std::io::stdin;
use std::io::Stdin;

use fasten::fasten_base_options;
use fasten::fasten_base_options_matches;
use fasten::logmsg;

use std::collections::HashMap;
Expand Down Expand Up @@ -85,20 +85,15 @@ fn test_kmer_counting_4mers () {
}

fn main(){
let args: Vec<String> = env::args().collect();
let mut opts = fasten_base_options();

// script-specific options
let default_k:usize = 21;
opts.optopt("k","kmer-length",&format!("The size of the kmer (default: {})",default_k),"INT");
opts.optflag("r","revcomp", "Count kmers on the reverse complement strand too");

let matches = opts.parse(&args[1..]).expect("ERROR: could not parse parameters");

if matches.opt_present("help") {
println!("Counts kmers.\n{}", opts.usage(&opts.short_usage(&args[0])));
std::process::exit(0);
}
let matches = fasten_base_options_matches("Counts kmers.", opts);

if matches.opt_present("paired-end") {
logmsg("WARNING: --paired-end is not utilized in this script");
}
Expand Down
10 changes: 2 additions & 8 deletions src/bin/fasten_metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ use std::io::BufReader;
use std::io::BufRead;
use std::f32;

use std::env;

use fasten::fasten_base_options;
use fasten::fasten_base_options_matches;
use fasten::logmsg;

#[test]
Expand All @@ -53,19 +52,14 @@ fn test_average_quality () {
}

fn main(){
let args: Vec<String> = env::args().collect();
let mut opts = fasten_base_options();

// script-specific options
opts.optflag("","each-read","Print the metrics for each read. This creates very large output");
opts.optopt("","distribution","Print the distribution for each metric. Must supply either 'normal' or 'nonparametric'","STRING");

let matches = opts.parse(&args[1..]).expect("ERROR: could not parse parameters");
let matches = fasten_base_options_matches("Gives read metrics on a read set.", opts);

if matches.opt_present("help") {
println!("Gives read metrics on a read set.\n{}", opts.usage(&opts.short_usage(&args[0])));
std::process::exit(0);
}
if matches.opt_present("paired-end") {
logmsg("WARNING: --paired-end is not utilized in this script");
}
Expand Down
9 changes: 2 additions & 7 deletions src/bin/fasten_mutate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,21 @@ extern crate rand;
use std::fs::File;
use std::io::BufReader;
use std::io::BufRead;
use std::env;

use rand::distributions::{IndependentSample, Range};

use fasten::fasten_base_options;
use fasten::fasten_base_options_matches;
use fasten::logmsg;


fn main(){
let args: Vec<String> = env::args().collect();
let mut opts = fasten_base_options();
// Options specific to this script
opts.optopt("s", "snps", "Number of SNPs (point mutations) to include per read.", "INT");
opts.optflag("m", "mark", "lowercase all reads but uppercase the SNPs (not yet implemented)");

let matches = opts.parse(&args[1..]).expect("ERROR: could not parse parameters");
if matches.opt_present("help") {
println!("Mutates reads. There is no mutation model; only randomness.\n{}", opts.usage(&opts.short_usage(&args[0])));
std::process::exit(0);
}
let matches = fasten_base_options_matches("Mutates reads. There is no mutation model; only randomness.", opts);

if matches.opt_present("paired-end") {
logmsg("WARNING: --paired-end is not utilized in this script");
Expand Down
12 changes: 2 additions & 10 deletions src/bin/fasten_pe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,19 @@ extern crate fasten;
extern crate regex;

use fasten::fasten_base_options;
use fasten::fasten_base_options_matches;
use fasten::logmsg;
use regex::Regex;

use std::fs::File;
use std::io::BufReader;
use std::io::BufRead;
use std::env;

fn main() {
let args: Vec<String> = env::args().collect();
let mut opts = fasten_base_options();
//opts.optopt("c","check-first","How many deflines to check to make sure the input is paired-end","INT");
opts.optflag("","print-reads","Print each read. Useful for Unix pipes.");
let matches = opts.parse(&args[1..]).expect("ERROR: could not parse parameters");
let matches = fasten_base_options_matches("Determine paired-end-ness in an interleaved file. Exit code of 0 indicates PE. Exit code > 0 indicates SE.", opts);

if matches.opt_present("help") {
println!("Determine paired-end-ness in an interleaved file. Exit code of 0 indicates PE. Exit code > 0 indicates SE.\n{}",
opts.usage(&opts.short_usage(&args[0]))
);
std::process::exit(0);
}
if matches.opt_present("paired-end") {
logmsg("WARNING: --paired-end was supplied but this script is supposed to determine whether the input is paired-end.");
}
Expand Down
9 changes: 2 additions & 7 deletions src/bin/fasten_progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,18 @@ extern crate fasten;
use std::fs::File;
use std::io::BufReader;
use std::io::BufRead;
use std::env;

use fasten::fasten_base_options;
use fasten::fasten_base_options_matches;

fn main(){
let args: Vec<String> = env::args().collect();
let mut opts = fasten_base_options();
// Options specific to this script
opts.optopt("","id","Progress identifier. Default: unnamed","STRING");
opts.optopt("","update-every","Update progress every n reads.","INT");
opts.optflag("p","print","Print the reads back to stdout");

let matches = opts.parse(&args[1..]).expect("ERROR: could not parse parameters");
if matches.opt_present("help") {
println!("Prints a progress meter for number of fastq entries.\n{}", opts.usage(&opts.short_usage(&args[0])));
std::process::exit(0);
}
let matches = fasten_base_options_matches("Prints a progress meter for number of fastq entries", opts);

let print_reads:bool = matches.opt_present("print");

Expand Down
11 changes: 3 additions & 8 deletions src/bin/fasten_quality_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,19 @@ extern crate getopts;
use std::fs::File;
use std::io::BufReader;
use std::io::BufRead;
use std::env;

use fasten::fasten_base_options;
use fasten::fasten_base_options_matches;
use fasten::logmsg;

fn main(){
let args: Vec<String> = env::args().collect();
let mut opts = fasten_base_options();

// script-specific options
opts.optopt("m","max-quality","The maximum quality at which a base will be transformed to 'N'","INT");

let matches = opts.parse(&args[1..]).expect("ERROR: could not parse parameters");

if matches.opt_present("help") {
println!("Transforms any low-quality base to 'N'\n{}", opts.usage(&opts.short_usage(&args[0])));
std::process::exit(0);
}
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");
}
Expand Down
10 changes: 2 additions & 8 deletions src/bin/fasten_randomize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,16 @@ extern crate rand;
use std::fs::File;
use std::io::BufReader;
use std::io::BufRead;
use std::env;

use rand::{Rng,thread_rng};

use fasten::fasten_base_options;
use fasten::fasten_base_options_matches;

fn main(){
let args: Vec<String> = env::args().collect();
let opts = fasten_base_options();
//script-specific flags

let matches = opts.parse(&args[1..]).expect("Error: could not parse parameters");
if matches.opt_present("help") {
println!("Create random reads from stdin.\n{}", opts.usage(&opts.short_usage(&args[0])));
std::process::exit(0);
}
let matches = fasten_base_options_matches("Create random reads from stdin.", opts);

let lines_per_read :u32={
if matches.opt_present("paired-end") {
Expand Down
9 changes: 2 additions & 7 deletions src/bin/fasten_regex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,22 @@ extern crate threadpool;
use std::fs::File;
use std::io::BufReader;
use std::io::BufRead;
use std::env;

use regex::Regex;
use threadpool::ThreadPool;
use std::sync::mpsc::channel;

use fasten::fasten_base_options;
use fasten::fasten_base_options_matches;

fn main(){
let args: Vec<String> = env::args().collect();
let mut opts = fasten_base_options();
// Options specific to this script
opts.optopt("r","regex","Regular expression (default: '.')","STRING");
opts.optopt("w","which","Which field to match on? ID, SEQ, QUAL. Default: SEQ","String");
//opts.optflag("e","exclude","Exclude these reads instead of including them");

let matches = opts.parse(&args[1..]).expect("ERROR: could not parse parameters");
if matches.opt_present("help") {
println!("Filter reads based on a regular expression.\n{}", opts.usage(&opts.short_usage(&args[0])));
std::process::exit(0);
}
let matches = fasten_base_options_matches("Filter reads based on a regular expression.", opts);

let (tx, rx):(std::sync::mpsc::Sender<String>,std::sync::mpsc::Receiver<String>) = channel();

Expand Down
9 changes: 2 additions & 7 deletions src/bin/fasten_replace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,21 @@ extern crate regex;
use std::fs::File;
use std::io::BufReader;
use std::io::BufRead;
use std::env;

use regex::Regex;

use fasten::fasten_base_options;
use fasten::fasten_base_options_matches;
use fasten::logmsg;

fn main(){
let args: Vec<String> = env::args().collect();
let mut opts = fasten_base_options();
// Options specific to this script
opts.optopt("f","find","Regular expression (default: '.')","STRING");
opts.optopt("r","replace","String to replace each match","STRING");
opts.optopt("w","which","Which field to match on? ID, SEQ, QUAL. Default: SEQ","STRING");

let matches = opts.parse(&args[1..]).expect("ERROR: could not parse parameters");
if matches.opt_present("help") {
println!("Streaming editor for fastq data using a find/replace.\n{}", opts.usage(&opts.short_usage(&args[0])));
std::process::exit(0);
}
let matches = fasten_base_options_matches("Streaming editor for fastq data using a find/replace.", opts);

if matches.opt_present("paired-end") {
logmsg("WARNING: --paired-end is not utilized in this script");
Expand Down
Loading

0 comments on commit cfffc1c

Please sign in to comment.