1 | #include "muscle.h" |
---|
2 | #include <stdio.h> |
---|
3 | |
---|
4 | struct VALUE_OPT |
---|
5 | { |
---|
6 | const char *m_pstrName; |
---|
7 | const char *m_pstrValue; |
---|
8 | }; |
---|
9 | |
---|
10 | struct FLAG_OPT |
---|
11 | { |
---|
12 | const char *m_pstrName; |
---|
13 | bool m_bSet; |
---|
14 | }; |
---|
15 | |
---|
16 | static VALUE_OPT ValueOpts[] = |
---|
17 | { |
---|
18 | "in", 0, |
---|
19 | "in1", 0, |
---|
20 | "in2", 0, |
---|
21 | "out", 0, |
---|
22 | "MaxIters", 0, |
---|
23 | "MaxHours", 0, |
---|
24 | "GapOpen", 0, |
---|
25 | "GapOpen2", 0, |
---|
26 | "GapExtend", 0, |
---|
27 | "GapExtend2", 0, |
---|
28 | "GapAmbig", 0, |
---|
29 | "Center", 0, |
---|
30 | "SmoothScoreCeil", 0, |
---|
31 | "MinBestColScore", 0, |
---|
32 | "MinSmoothScore", 0, |
---|
33 | "ObjScore", 0, |
---|
34 | "SmoothWindow", 0, |
---|
35 | "RefineWindow", 0, |
---|
36 | "FromWindow", 0, |
---|
37 | "ToWindow", 0, |
---|
38 | "SaveWindow", 0, |
---|
39 | "WindowOffset", 0, |
---|
40 | "FirstWindow", 0, |
---|
41 | "AnchorSpacing", 0, |
---|
42 | "Log", 0, |
---|
43 | "LogA", 0, |
---|
44 | "MaxTrees", 0, |
---|
45 | "SUEFF", 0, |
---|
46 | "Distance", 0, |
---|
47 | "Distance1", 0, |
---|
48 | "Distance2", 0, |
---|
49 | "Weight", 0, |
---|
50 | "Weight1", 0, |
---|
51 | "Weight2", 0, |
---|
52 | "Cluster", 0, |
---|
53 | "Cluster1", 0, |
---|
54 | "Cluster2", 0, |
---|
55 | "Root1", 0, |
---|
56 | "Root2", 0, |
---|
57 | "Tree1", 0, |
---|
58 | "Tree2", 0, |
---|
59 | "UseTree", 0, |
---|
60 | "UseTree_NoWarn", 0, |
---|
61 | "DiagLength", 0, |
---|
62 | "DiagMargin", 0, |
---|
63 | "DiagBreak", 0, |
---|
64 | "Hydro", 0, |
---|
65 | "HydroFactor", 0, |
---|
66 | "SPScore", 0, |
---|
67 | "SeqType", 0, |
---|
68 | "MaxMB", 0, |
---|
69 | "ComputeWeights", 0, |
---|
70 | "MaxSubFam", 0, |
---|
71 | "ScoreFile", 0, |
---|
72 | "TermGaps", 0, |
---|
73 | "FASTAOut", 0, |
---|
74 | "CLWOut", 0, |
---|
75 | "CLWStrictOut", 0, |
---|
76 | "HTMLOut", 0, |
---|
77 | "MSFOut", 0, |
---|
78 | "PHYIOut", 0, |
---|
79 | "PHYSOut", 0, |
---|
80 | "Matrix", 0, |
---|
81 | "DistMx1", 0, |
---|
82 | "DistMx2", 0, |
---|
83 | "Weight", 0, |
---|
84 | }; |
---|
85 | static int ValueOptCount = sizeof(ValueOpts)/sizeof(ValueOpts[0]); |
---|
86 | |
---|
87 | static FLAG_OPT FlagOpts[] = |
---|
88 | { |
---|
89 | "LE", false, |
---|
90 | "SP", false, |
---|
91 | "SV", false, |
---|
92 | "SPN", false, |
---|
93 | "Core", false, |
---|
94 | "NoCore", false, |
---|
95 | "Diags1", false, |
---|
96 | "Diags2", false, |
---|
97 | "Diags", false, |
---|
98 | "Quiet", false, |
---|
99 | "MSF", false, |
---|
100 | "Verbose", false, |
---|
101 | "Anchors", false, |
---|
102 | "NoAnchors", false, |
---|
103 | "Refine", false, |
---|
104 | "RefineW", false, |
---|
105 | "SW", false, |
---|
106 | "Profile", false, |
---|
107 | "PPScore", false, |
---|
108 | "ClusterOnly", false, |
---|
109 | "Brenner", false, |
---|
110 | "Dimer", false, |
---|
111 | "clw", false, |
---|
112 | "clwstrict", false, |
---|
113 | "HTML", false, |
---|
114 | "Version", false, |
---|
115 | "Stable", false, |
---|
116 | "Group", false, |
---|
117 | "FASTA", false, |
---|
118 | "ProfDB", false, |
---|
119 | "PAS", false, |
---|
120 | "PHYI", false, |
---|
121 | "PHYS", false, |
---|
122 | "TomHydro", false, |
---|
123 | "MakeTree", false, |
---|
124 | }; |
---|
125 | static int FlagOptCount = sizeof(FlagOpts)/sizeof(FlagOpts[0]); |
---|
126 | |
---|
127 | static bool TestSetFlagOpt(const char *Arg) |
---|
128 | { |
---|
129 | for (int i = 0; i < FlagOptCount; ++i) |
---|
130 | if (!stricmp(Arg, FlagOpts[i].m_pstrName)) |
---|
131 | { |
---|
132 | FlagOpts[i].m_bSet = true; |
---|
133 | return true; |
---|
134 | } |
---|
135 | return false; |
---|
136 | } |
---|
137 | |
---|
138 | static bool TestSetValueOpt(const char *Arg, const char *Value) |
---|
139 | { |
---|
140 | for (int i = 0; i < ValueOptCount; ++i) |
---|
141 | if (!stricmp(Arg, ValueOpts[i].m_pstrName)) |
---|
142 | { |
---|
143 | if (0 == Value) |
---|
144 | { |
---|
145 | fprintf(stderr, "Option -%s must have value\n", Arg); |
---|
146 | exit(EXIT_NotStarted); |
---|
147 | } |
---|
148 | ValueOpts[i].m_pstrValue = strsave(Value); |
---|
149 | return true; |
---|
150 | } |
---|
151 | return false; |
---|
152 | } |
---|
153 | |
---|
154 | bool FlagOpt(const char *Name) |
---|
155 | { |
---|
156 | for (int i = 0; i < FlagOptCount; ++i) |
---|
157 | if (!stricmp(Name, FlagOpts[i].m_pstrName)) |
---|
158 | return FlagOpts[i].m_bSet; |
---|
159 | Quit("FlagOpt(%s) invalid", Name); |
---|
160 | return false; |
---|
161 | } |
---|
162 | |
---|
163 | const char *ValueOpt(const char *Name) |
---|
164 | { |
---|
165 | for (int i = 0; i < ValueOptCount; ++i) |
---|
166 | if (!stricmp(Name, ValueOpts[i].m_pstrName)) |
---|
167 | return ValueOpts[i].m_pstrValue; |
---|
168 | Quit("ValueOpt(%s) invalid", Name); |
---|
169 | return 0; |
---|
170 | } |
---|
171 | |
---|
172 | void ProcessArgVect(int argc, char *argv[]) |
---|
173 | { |
---|
174 | for (int iArgIndex = 0; iArgIndex < argc; ) |
---|
175 | { |
---|
176 | const char *Arg = argv[iArgIndex]; |
---|
177 | if (Arg[0] != '-') |
---|
178 | { |
---|
179 | fprintf(stderr, "Command-line option \"%s\" must start with '-'\n", Arg); |
---|
180 | exit(EXIT_NotStarted); |
---|
181 | } |
---|
182 | const char *ArgName = Arg + 1; |
---|
183 | if (TestSetFlagOpt(ArgName)) |
---|
184 | { |
---|
185 | ++iArgIndex; |
---|
186 | continue; |
---|
187 | } |
---|
188 | |
---|
189 | char *Value = 0; |
---|
190 | if (iArgIndex < argc - 1) |
---|
191 | Value = argv[iArgIndex+1]; |
---|
192 | if (TestSetValueOpt(ArgName, Value)) |
---|
193 | { |
---|
194 | iArgIndex += 2; |
---|
195 | continue; |
---|
196 | } |
---|
197 | fprintf(stderr, "Invalid command line option \"%s\"\n", ArgName); |
---|
198 | Usage(); |
---|
199 | exit(EXIT_NotStarted); |
---|
200 | } |
---|
201 | } |
---|
202 | |
---|
203 | void ProcessArgStr(const char *ArgStr) |
---|
204 | { |
---|
205 | const int MAX_ARGS = 64; |
---|
206 | char *argv[MAX_ARGS]; |
---|
207 | |
---|
208 | if (0 == ArgStr) |
---|
209 | return; |
---|
210 | |
---|
211 | // Modifiable copy |
---|
212 | char *StrCopy = strsave(ArgStr); |
---|
213 | |
---|
214 | int argc = 0; |
---|
215 | bool bInArg = false; |
---|
216 | char *Str = StrCopy; |
---|
217 | while (char c = *Str) |
---|
218 | { |
---|
219 | if (isspace(c)) |
---|
220 | { |
---|
221 | *Str = 0; |
---|
222 | bInArg = false; |
---|
223 | } |
---|
224 | else if (!bInArg) |
---|
225 | { |
---|
226 | bInArg = true; |
---|
227 | if (argc >= MAX_ARGS) |
---|
228 | Quit("Too many args in MUSCLE_CMDLINE"); |
---|
229 | argv[argc++] = Str; |
---|
230 | } |
---|
231 | Str++; |
---|
232 | } |
---|
233 | ProcessArgVect(argc, argv); |
---|
234 | free(StrCopy); |
---|
235 | } |
---|
236 | |
---|
237 | void ListFlagOpts() |
---|
238 | { |
---|
239 | for (int i = 0; i < FlagOptCount; ++i) |
---|
240 | Log("%s %d\n", FlagOpts[i].m_pstrName, FlagOpts[i].m_bSet); |
---|
241 | } |
---|