Skip to content

Commit 2082f58

Browse files
committed
Program now runs according to command line arguments.
1 parent 7a1c04b commit 2082f58

File tree

3 files changed

+63
-11
lines changed

3 files changed

+63
-11
lines changed

hw3/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
all:
2-
g++ -o out readFile.cpp writeToFile.cpp needleman_wunsch.cpp smith_waterman.cpp main.cpp
2+
g++ -o allalign readFile.cpp writeToFile.cpp needleman_wunsch.cpp smith_waterman.cpp main.cpp

hw3/README.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Type "make" to compile source files.
2+
Type "./allalign <NECESSARY OPTIONS>" to run the program.

hw3/main.cpp

+60-10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <string>
33
#include <bits/stdc++.h>
44
#include "unistd.h"
5+
#include <getopt.h>
56

67
using namespace std;
78

@@ -12,19 +13,68 @@ int needleman_wunsch(string sequence1Name, string sequence1, string sequence2Nam
1213
int gapopen, int gapext, int matchScore, int mismatchPenalty);
1314

1415
int main(int argc, char *argv[]) {
15-
if (argc < 2) {
16-
fprintf(stderr, "usage: ./out <textFileName patternFileName>\n");
17-
return -1;
18-
}
16+
int c;
17+
string mode;
18+
string fileName;
19+
int gapopen;
20+
int gapext;
21+
while (1) {
22+
static struct option long_options[] = {
23+
{"mode", required_argument, 0, 'm'},
24+
{"input", required_argument, 0, 'i'},
25+
{"gapopen", required_argument, 0, 'o'},
26+
{"gapext", required_argument, 0, 'e'},
27+
{0, 0, 0, 0}
28+
};
29+
/* getopt_long stores the option index here. */
30+
int option_index = 0;
31+
32+
c = getopt_long (argc, argv, "m:i:o:e:",
33+
long_options, &option_index);
34+
35+
/* Detect the end of the options. */
36+
if (c == -1)
37+
break;
38+
39+
switch (c) {
40+
case 'm':
41+
mode = optarg;
42+
break;
43+
44+
case 'i':
45+
fileName = optarg;
46+
break;
1947

20-
vector<string> sequences = readFile(argv[1]);
48+
case 'o':
49+
gapopen = atoi(optarg);
50+
break;
2151

22-
int gapopen = -5;
23-
int gapext = -2;
52+
case 'e':
53+
gapext = atoi(optarg);
54+
break;
55+
case '?':
56+
/* getopt_long already printed an error message. */
57+
return 1;
58+
break;
59+
60+
default:
61+
abort ();
62+
}
63+
}
64+
65+
vector<string> sequences = readFile(fileName);
66+
2467
int matchScore = 2;
2568
int mismatchPenalty = -3;
26-
27-
needleman_wunsch(sequences[0], sequences[1], sequences[2], sequences[3], gapopen, gapext, matchScore, mismatchPenalty);
69+
if(mode.compare("global") == 0){
70+
needleman_wunsch(sequences[0], sequences[1], sequences[2], sequences[3], 0, gapopen, matchScore, mismatchPenalty);
71+
} else if(mode.compare("aglobal") == 0){
72+
needleman_wunsch(sequences[0], sequences[1], sequences[2], sequences[3], gapopen, gapext, matchScore, mismatchPenalty);
73+
} else if(mode.compare("local") == 0){
74+
smith_waterman(sequences[0], sequences[1], sequences[2], sequences[3], 0, gapopen, matchScore, mismatchPenalty);
75+
} else if(mode.compare("alocal") == 0){
76+
smith_waterman(sequences[0], sequences[1], sequences[2], sequences[3], gapopen, gapext, matchScore, mismatchPenalty);
77+
}
2878

29-
smith_waterman(sequences[0], sequences[1], sequences[2], sequences[3], gapopen, gapext, matchScore, mismatchPenalty);
79+
return 0;
3080
}

0 commit comments

Comments
 (0)