File: options.cpp

package info (click to toggle)
muscle 3.60-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,384 kB
  • ctags: 2,079
  • sloc: cpp: 26,452; xml: 185; makefile: 101
file content (233 lines) | stat: -rw-r--r-- 4,645 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#include "muscle.h"
#include <stdio.h>

struct VALUE_OPT
	{
	const char *m_pstrName;
	const char *m_pstrValue;
	};

struct FLAG_OPT
	{
	const char *m_pstrName;
	bool m_bSet;
	};

static VALUE_OPT ValueOpts[] =
	{
	"in",				0,
	"in1",				0,
	"in2",				0,
	"out",				0,
	"MaxIters",			0,
	"MaxHours",			0,
	"GapOpen",			0,
	"GapOpen2",			0,
	"GapExtend",		0,
	"GapExtend2",		0,
	"GapAmbig",			0,
	"Center",			0,
	"SmoothScoreCeil",	0,
	"MinBestColScore",	0,
	"MinSmoothScore",	0,
	"ObjScore",			0,
	"SmoothWindow",		0,
	"RefineWindow",		0,
	"FromWindow",		0,
	"ToWindow",			0,
	"SaveWindow",		0,
	"WindowOffset",		0,
	"FirstWindow",		0,
	"AnchorSpacing",	0,
	"Log",				0,
	"LogA",				0,
	"MaxTrees",			0,
	"SUEFF",			0,
	"Distance1",		0,
	"Distance2",		0,
	"Weight1",			0,
	"Weight2",			0,
	"Cluster1",			0,
	"Cluster2",			0,
	"Root1",			0,
	"Root2",			0,
	"Tree1",			0,
	"Tree2",			0,
	"UseTree",			0,
	"UseTree_NoWarn",	0,
	"DiagLength",		0,
	"DiagMargin",		0,
	"DiagBreak",		0,
	"Hydro",			0,
	"HydroFactor",		0,
	"SPScore",			0,
	"SeqType",			0,
	"MaxMB",			0,
	"ComputeWeights",	0,
	"MaxSubFam",		0,
	"ScoreFile",		0,
	"TermGaps",			0,
	"FASTAOut",			0,
	"CLWOut",			0,
	"CLWStrictOut",		0,
	"HTMLOut",			0,
	"MSFOut",			0,
	"PHYIOut",			0,
	"PHYSOut",			0,
	"Matrix",			0,
	};
static int ValueOptCount = sizeof(ValueOpts)/sizeof(ValueOpts[0]);

static FLAG_OPT FlagOpts[] =
	{
	"LE",					false,
	"SP",					false,
	"SV",					false,
	"SPN",					false,
	"Core",					false,
	"NoCore",				false,
	"Diags1",				false,
	"Diags2",				false,
	"Diags",				false,
	"Quiet",				false,
	"MSF",					false,
	"Verbose",				false,
	"Anchors",				false,
	"NoAnchors",			false,
	"Refine",				false,
	"RefineW",				false,
	"SW",					false,
	"Profile",				false,
	"PPScore",				false,
	"Cluster",				false,
	"Brenner",				false,
	"Dimer",				false,
	"clw",					false,
	"clwstrict",			false,
	"HTML",					false,
	"Version",				false,
	"Stable",				false,
	"Group",				false,
	"FASTA",				false,
	"ProfDB",				false,
	"PAS",					false,
	"PHYI",					false,
	"PHYS",					false,
	};
static int FlagOptCount = sizeof(FlagOpts)/sizeof(FlagOpts[0]);

static bool TestSetFlagOpt(const char *Arg)
	{
	for (int i = 0; i < FlagOptCount; ++i)
		if (!stricmp(Arg, FlagOpts[i].m_pstrName))
			{
			FlagOpts[i].m_bSet = true;
			return true;
			}
	return false;
	}

static bool TestSetValueOpt(const char *Arg, const char *Value)
	{
	for (int i = 0; i < ValueOptCount; ++i)
		if (!stricmp(Arg, ValueOpts[i].m_pstrName))
			{
			if (0 == Value)
				{
				fprintf(stderr, "Option -%s must have value\n", Arg);
				exit(EXIT_NotStarted);
				}
			ValueOpts[i].m_pstrValue = strsave(Value);
			return true;
			}
	return false;
	}

bool FlagOpt(const char *Name)
	{
	for (int i = 0; i < FlagOptCount; ++i)
		if (!stricmp(Name, FlagOpts[i].m_pstrName))
			return FlagOpts[i].m_bSet;
	Quit("FlagOpt(%s) invalid", Name);
	return false;
	}

const char *ValueOpt(const char *Name)
	{
	for (int i = 0; i < ValueOptCount; ++i)
		if (!stricmp(Name, ValueOpts[i].m_pstrName))
			return ValueOpts[i].m_pstrValue;
	Quit("ValueOpt(%s) invalid", Name);
	return 0;
	}

void ProcessArgVect(int argc, char *argv[])
	{
	for (int iArgIndex = 0; iArgIndex < argc; )
		{
		const char *Arg = argv[iArgIndex];
		if (Arg[0] != '-')
			{
			fprintf(stderr, "Command-line option \"%s\" must start with '-'\n", Arg);
			exit(EXIT_NotStarted);
			}
		const char *ArgName = Arg + 1;
		if (TestSetFlagOpt(ArgName))
			{
			++iArgIndex;
			continue;
			}
		
		char *Value = 0;
		if (iArgIndex < argc - 1)
			Value = argv[iArgIndex+1];
		if (TestSetValueOpt(ArgName, Value))
			{
			iArgIndex += 2;
			continue;
			}
		fprintf(stderr, "Invalid command line option \"%s\"\n", ArgName);
		Usage();
		exit(EXIT_NotStarted);
		}
	}

void ProcessArgStr(const char *ArgStr)
	{
	const int MAX_ARGS = 64;
	char *argv[MAX_ARGS];

	if (0 == ArgStr)
		return;

// Modifiable copy
	char *StrCopy = strsave(ArgStr);

	int argc = 0;
	bool bInArg = false;
	char *Str = StrCopy;
	while (char c = *Str)
		{
		if (isspace(c))
			{
			*Str = 0;
			bInArg = false;
			}
		else if (!bInArg)
			{
			bInArg = true;
			if (argc >= MAX_ARGS)
				Quit("Too many args in MUSCLE_CMDLINE");
			argv[argc++] = Str;
			}
		Str++;
		}
	ProcessArgVect(argc, argv);
	free(StrCopy);
	}

void ListFlagOpts()
	{
	for (int i = 0; i < FlagOptCount; ++i)
		Log("%s %d\n", FlagOpts[i].m_pstrName, FlagOpts[i].m_bSet);
	}