Skip to content

Commit

Permalink
reworked usage and -h behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
bjmt committed May 3, 2019
1 parent efa6caa commit a6cdb59
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ The following binaries are created:
bin/seqgen Generate a random string
bin/shuffler Shuffle a string or sequences inside a fasta file

Run these without any arguments or with the -h flag to see usage.
Run these with the -h flag to see usage.


countfa
Expand Down
4 changes: 3 additions & 1 deletion src/countfa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ int main(int argc, char **argv) {
seqfile.open(optarg);
if (seqfile.bad()) {
cerr << "Error: file not found" << endl;
cerr << "Run countfa -h to see usage." << endl;
exit(EXIT_FAILURE);
}
has_file = true;
Expand All @@ -140,7 +141,8 @@ int main(int argc, char **argv) {

if (!has_file) {
if (isatty(STDIN_FILENO)) {
usage();
cerr << "Error: missing input" << endl;
cerr << "Run countfa -h to see usage." << endl;
exit(EXIT_FAILURE);
}
do_countfa(cin);
Expand Down
7 changes: 6 additions & 1 deletion src/countlets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ int main(int argc, char **argv) {
seqfile.open(optarg);
if (seqfile.bad()) {
cerr << "Error: file not found" << endl;
cerr << "Run countlets -h to see usage." << endl;
exit(EXIT_FAILURE);
}
has_file = true;
Expand All @@ -117,6 +118,7 @@ int main(int argc, char **argv) {
outfile.open(optarg);
if (outfile.bad()) {
cerr << "Error: could not create outfile" << endl;
cerr << "Run countlets -h to see usage." << endl;
exit(EXIT_FAILURE);
}
has_out = true;
Expand All @@ -134,12 +136,14 @@ int main(int argc, char **argv) {

if (k < 1) {
cerr << "Error: k must be greater than 0" << endl;
cerr << "Run countlets -h to see usage." << endl;
exit(EXIT_FAILURE);
}

if (!has_file) {
if (isatty(STDIN_FILENO)) {
usage();
cerr << "Error: missing input" << endl;
cerr << "Run countlets -h to see usage." << endl;
exit(EXIT_FAILURE);
}
}
Expand Down Expand Up @@ -180,6 +184,7 @@ int main(int argc, char **argv) {

if (alph.length() < 1) {
cerr << "Error: could not parse -a option" << endl;
cerr << "Run countlets -h to see usage." << endl;
exit(EXIT_FAILURE);
}

Expand Down
7 changes: 7 additions & 0 deletions src/countwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ int main(int argc, char **argv) {
infile.open(optarg);
if (infile.bad()) {
cerr << "Error: file not found" << endl;
cerr << "Run countwin -h to see usage." << endl;
exit(EXIT_FAILURE);
}
has_file = true;
Expand All @@ -112,6 +113,7 @@ int main(int argc, char **argv) {
outfile.open(optarg);
if (outfile.bad()) {
cerr << "Error: could not create outfile" << endl;
cerr << "Run countwin -h to see usage." << endl;
exit(EXIT_FAILURE);
}
has_out = true;
Expand Down Expand Up @@ -150,12 +152,14 @@ int main(int argc, char **argv) {

if (k < 1) {
cerr << "Error: k must be greater than 0" << endl;
cerr << "Run countwin -h to see usage." << endl;
exit(EXIT_FAILURE);
}

if (!has_file) {
if (isatty(STDIN_FILENO)) {
cerr << "Error: missing input" << endl;
cerr << "Run countwin -h to see usage." << endl;
exit(EXIT_FAILURE);
}
}
Expand All @@ -170,6 +174,7 @@ int main(int argc, char **argv) {
} else {
if (window < k) {
cerr << "Error: window size must be equal to or greater than k" << endl;
cerr << "Run countwin -h to see usage." << endl;
exit(EXIT_FAILURE);
}
}
Expand All @@ -178,6 +183,7 @@ int main(int argc, char **argv) {

if (step < 1 || step > window) {
cerr << "Error: step size must be between 1 and window size" << endl;
cerr << "Run countwin -h to see usage." << endl;
exit(EXIT_FAILURE);
}

Expand All @@ -204,6 +210,7 @@ int main(int argc, char **argv) {
STOP = START + seq.length() - 1;
if (seq.length() < k) {
cerr << "Error: sequence cannot be smaller than k" << endl;
cerr << "Run countwin -h to see usage." << endl;
exit(EXIT_FAILURE);
}
counts = count_klets(vector<char>(seq.begin(), seq.end()), klets, lets_uniq, k, alphlen);
Expand Down
6 changes: 5 additions & 1 deletion src/seqgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ int main(int argc, char **argv) {
size_t last, next;

if (argc == 1) {
usage();
cerr << "Error: missing alphabet and sequence length" << endl;
cerr << "Run seqgen -h to see usage." << endl;
return 0;
}

Expand All @@ -70,6 +71,7 @@ int main(int argc, char **argv) {
outfile.open(optarg);
if (outfile.bad()) {
cerr << "Error: could not create outfile" << endl;
cerr << "Run seqgen -h to see usage." << endl;
exit(EXIT_FAILURE);
}
has_out = true;
Expand All @@ -95,6 +97,7 @@ int main(int argc, char **argv) {

if (seqlen < 1) {
cerr << "Error: please input a desired sequence length above 0" << endl;;
cerr << "Run seqgen -h to see usage." << endl;
exit(EXIT_FAILURE);
}

Expand All @@ -113,6 +116,7 @@ int main(int argc, char **argv) {

if (alphlen < 1) {
cerr << "Error: could not parse sequence alphabet" << endl;
cerr << "Run seqgen -h to see usage." << endl;
exit(EXIT_FAILURE);
}

Expand Down
7 changes: 6 additions & 1 deletion src/shuffler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ int main(int argc, char **argv) {
seqfile.open(optarg);
if (seqfile.bad()) {
cerr << "Error: file not found" << endl;
cerr << "Run shuffler -h to see usage." << endl;
exit(EXIT_FAILURE);
}
has_file = true;
Expand All @@ -226,6 +227,7 @@ int main(int argc, char **argv) {
outfile.open(optarg);
if (outfile.bad()) {
cerr << "Error: could not create outfile" << endl;
cerr << "Run shuffler -h to see usage." << endl;
exit(EXIT_FAILURE);
}
has_out = true;
Expand Down Expand Up @@ -254,17 +256,20 @@ int main(int argc, char **argv) {
}

if (!has_file && isatty(STDIN_FILENO)) {
usage();
cerr << "Error: missing input" << endl;
cerr << "Run shuffler -h to see usage." << endl;
exit(EXIT_FAILURE);
}

if (k < 1) {
cerr << "Error: k must be greater than 0" << endl;
cerr << "Run shuffler -h to see usage." << endl;
exit(EXIT_FAILURE);
}

if (use_linear && use_markov) {
cerr << "Error: only use one of -l and -m flags" << endl;
cerr << "Run shuffler -h to see usage." << endl;
exit(EXIT_FAILURE);
}

Expand Down

0 comments on commit a6cdb59

Please sign in to comment.