コード例 #1
0
///////////////////////////////////////////////////////////////////////////////
// Parse the command line arguments.
///////////////////////////////////////////////////////////////////////////////
bool phmm_interface::parse( int argc, char** argv ) {

	// Create the command line parser and build in its required parameters.
	ParseCommandLine* parser = new ParseCommandLine( "phmm" );
	parser->addParameterDescription( "seq 1", "The name of a file containing the first input sequence." );
	parser->addParameterDescription( "seq 2", "The name of a file containing the second input sequence." );
	parser->addParameterDescription( "out file", "The name of a file containing the output sequence." );

	// Add the Maximum Likelihood option.
	vector<string> alignmentOptions;
	alignmentOptions.push_back( "-M" );
	alignmentOptions.push_back( "-m" );
	alignmentOptions.push_back( "--maxlikelihood" );
	parser->addOptionFlagsNoParameters( alignmentOptions, "Specify that program should output a maximum likelihood alignment. Default is to output pairwise probabilities." );

	// Add the log probabilities option.
	vector<string> probOptions;
	probOptions.push_back( "-L" );
	probOptions.push_back( "-l" );
	probOptions.push_back( "--logprobability" );
	parser->addOptionFlagsNoParameters( probOptions, "Specify that program should output probabilities as logs (base 10). Default is to output probabilties." );



	// Parse the command line into pieces.
	parser->parseLine( argc, argv );

	// Get required parameters from the parser.
	if( !parser->isError() ) {
		seq1 = parser->getParameter( 1 );
		seq2 = parser->getParameter( 2 );
		outfile = parser->getParameter( 3 );
	}

	// Get the maximum likelihood option.
	if( !parser->isError() ) { ML = parser->contains( alignmentOptions ); }

	// Get the log probability option.
	if( !parser->isError() ) { LP = parser->contains( probOptions ); }


	// Delete the parser and return whether the parser encountered an error.
	bool noError = ( parser->isError() == false );
	delete parser;
	return noError;
}
コード例 #2
0
///////////////////////////////////////////////////////////////////////////////
// Parse the command line arguments.
///////////////////////////////////////////////////////////////////////////////
bool designInterface::parse( int argc, char** argv ) {
	char description[256];

	// Create the command line parser and build in its required parameters.
	ParseCommandLine* parser = new ParseCommandLine( "design" );
	parser->addParameterDescription( string("ct structure file"), string("The input ct file which describes the structure to design. The sequence in the ct file will be ignored.") );
	//parser->addParameterDescription( "output sequence file", "The file to which the resulting designed sequence is written." );

	//parser->addParameterDescription( "defect threshold", "The maximum allowed ensemble defect per nucleotide." );
	vector<string> defectOptions;
	defectOptions.push_back( "-e" );
	defectOptions.push_back( "--error" );
	parser->addOptionFlagsWithParameters( defectOptions, "The maximum allowed ensemble defect per nucleotide.");

	vector<string> dnaOptions;
	dnaOptions.push_back( "-d" );
	dnaOptions.push_back( "--dna" );
	parser->addOptionFlagsNoParameters( dnaOptions, "Specify that the sequence is DNA, and DNA parameters are to be used. The default is to use RNA parameters." );

	vector<string> preselectOptions;
#if DEFAULT_PRESELECTED_SEQUENCES    // This flag can be used to switch the default sequence generation algorithm from random to pre-selected (or vice-versa)
	preselectOptions.push_back( "-r" );
	preselectOptions.push_back( "--random" );
	parser->addOptionFlagsNoParameters( preselectOptions, "Specify that all nucleotides should be chosen at random. The default is to use pre-selected sequence segments."); // The default is to use random sequence generation." );
#else
	preselectOptions.push_back( "-p" );
	preselectOptions.push_back( "--preselect" );
	parser->addOptionFlagsNoParameters( preselectOptions, "Specify that use pre-selected sequence segments should be used. The default is that all nucleotides are chosen at random." );
#endif

	// Heuristics mode is no longer supported
	//vector<string> heuristicsOptions;
	//heuristicsOptions.push_back( "-u" );
	//heuristicsOptions.push_back( "--heuristic" );
	//parser->addOptionFlagsNoParameters( heuristicsOptions, "Use heuristics to avoid performing a partition function on the complete sequence.  The default is to not use heuristics." );

	vector<string> maxDepthOptions;
	maxDepthOptions.push_back( "-md" );
	maxDepthOptions.push_back( "--maxdepth" );
	sprintf(description, "Max-depth: The maximum extent to which the structure will be sub-divided in the binary decomposition. The default is %d.", maxDepth);
	parser->addOptionFlagsWithParameters( maxDepthOptions, description);

	// Pseudoknot is no longer supported
	//vector<string> pseudoknotOptions;
	//pseudoknotOptions.push_back( "-k" );
	//pseudoknotOptions.push_back( "-K" );
	//pseudoknotOptions.push_back( "--pseudoknot" );
	//parser->addOptionFlagsNoParameters( pseudoknotOptions, "Turn pseudoknot design on. The default is off.");

	vector<string> maxRedesignOptions;
	maxRedesignOptions.push_back( "-mr" );
	maxRedesignOptions.push_back( "--maxredesign" );
	sprintf(description, "The maximum number of redesigns per parent node. The default is %d.", maxRedesign);
	parser->addOptionFlagsWithParameters( maxRedesignOptions, string(description));

	vector<string> maxMutateOptions;
	maxMutateOptions.push_back( "-mm" );
	maxMutateOptions.push_back( "--maxmutate" );
	sprintf(description, "The maximum number of times a nucleotide will be mutated during defect-weighted reoptimization. The default is %d.", maxMutate);
	parser->addOptionFlagsWithParameters( maxMutateOptions, string(description));

	vector<string> maxLeafRedesignOptions;
	maxLeafRedesignOptions.push_back( "-ml" );
	maxLeafRedesignOptions.push_back( "--maxleaf" );
	sprintf(description, "The maximum number of times a leaf can be re-optimized at random. The default is %d.", maxLeafRedesign);
	parser->addOptionFlagsWithParameters( maxLeafRedesignOptions, string(description));

	vector<string> outputFileOptions;
	outputFileOptions.push_back( "-o" );
	outputFileOptions.push_back( "--output" );
	parser->addOptionFlagsWithParameters( outputFileOptions, "Specify the output file. By default the resulting designed sequence is written to standard output only. This flag instructs the program to output the structure (in ct format) to the specified file." );

	vector<string> timerOptions;
	timerOptions.push_back( "-t" );
	timerOptions.push_back( "--timer" );
	parser->addOptionFlagsNoParameters( timerOptions, "Use a timer to measure the duration of the design process and print the elapsed time to standard output." );

	vector<string> seedOptions;
	seedOptions.push_back( "-s" );
	seedOptions.push_back( "--seed" );
	parser->addOptionFlagsWithParameters( seedOptions, "Specify a random seed. This is required to get exactly reproducible results. (The default is to use a seed based on the current system time)." );

	// Parse the command line into pieces.
	parser->parseLine( argc, argv );

	// Get required parameters from the parser.
	if( !parser->isError() ) {
		ctFile = parser->getParameter( 1 );
		//outFile = parser->getParameter( 2 ); //now output file is set with -o flag (--output)
		//defectThreshold = atof(parser->getParameter( 3 ).c_str());
		//if( defectThreshold <= 0.0 ) { parser->setError( "defect threshold" ); }
	}
	// Get boolean parameters (true if present, false otherwise)
	if (!parser->isError() ) { 
		preselectSequences = parser->contains( preselectOptions ) != DEFAULT_PRESELECTED_SEQUENCES; // If user passed the flag, they want the OPPOSITE of the default.
		isRNA = !parser->contains( dnaOptions );
		//useHeuristicMode = parser->contains( heuristicsOptions); 
		//designPseudoknot = parser->contains( pseudoknotOptions); 
		useTimer = parser->contains( timerOptions );
	}

	if (!parser->isError()) {
		outFile = parser->getOptionString(outputFileOptions, false);
	}

	// Get integer parameters: maxDepth, maxRedesign, maxMuate, maxLeafRedesign
	if( !parser->isError() ) {
		parser->setOptionDouble( defectOptions, defectThreshold);
		if( defectThreshold <= 0 ) { parser->setError( "Maximum Ensemble Defect" ); }
	}
	if( !parser->isError() ) {
		setRandomSeed = parser->setOptionLong( seedOptions, randSeed);
		//	cout << "Random Seed: " << randSeed << endl;
		//if( defectThreshold <= 0 ) { parser->setError( "Maximum Ensemble Defect" ); }
	}
	if( !parser->isError() ) {
		parser->setOptionInteger( maxDepthOptions, maxDepth);
		if( maxDepth <= 0 ) { parser->setError( "Max-Depth" ); }
	}
	if( !parser->isError() ) {
		parser->setOptionInteger( maxRedesignOptions, maxRedesign);
		if( maxRedesign <= 0 ) { parser->setError( "Max-Redesigns per Parent" ); }
	}
	if( !parser->isError() ) {
		parser->setOptionInteger( maxMutateOptions, maxMutate);
		if( maxMutate <= 0 ) { parser->setError( "Max-Mutate" ); }
	}
	if( !parser->isError() ) {
		parser->setOptionInteger( maxLeafRedesignOptions, maxLeafRedesign);
		if( maxLeafRedesign <= 0 ) { parser->setError( "Max-Leaf Redesign" ); }
	}

	// Delete the parser and return whether the parser encountered an error.
	bool noError = ( parser->isError() == false );
	delete parser;
	return noError;
}
コード例 #3
0
///////////////////////////////////////////////////////////////////////////////
// Parse the command line arguments.
///////////////////////////////////////////////////////////////////////////////
bool EnergyPlot::parse( int argc, char* argv[] ) {

	// Create the command line parser and build in its required parameters.
	ParseCommandLine* parser = new ParseCommandLine( "EnergyPlot" );
	parser->addParameterDescription( "folding save file", "A binary save file resulting from a structure folding calculation." );
	parser->addParameterDescription( "output file", "The name of a file to which output will be written. Depending on the options selected, this may be one of the following file types. 1) A Postscript image file. 2) An SVG image file. 3) A plain text file." );

	// Add the entries option.
	vector<string> entriesOptions;
	entriesOptions.push_back( "-e" );
	entriesOptions.push_back( "-E" );
	entriesOptions.push_back( "--entries" );
	parser->addOptionFlagsWithParameters( entriesOptions, "Specifies the number of colors in the dot plot. Default is " + ENTRIES_DEFAULT_STRING + " colors. Minimum is " + ENTRIES_MINIMUM_STRING + " colors. Maximum is " + ENTRIES_MAXIMUM_STRING + " colors." );

	// Add the maximum option.
	vector<string> maximumOptions;
	maximumOptions.push_back( "-max" );
	maximumOptions.push_back( "-MAX" );
	maximumOptions.push_back( "--maximum" );
	parser->addOptionFlagsWithParameters( maximumOptions, "Specifies the maximum value that is viewable in the plot. Default is the largest allowable point in a given data file. If the given value is greater than the default, it is ignored." );

	// Add the minimum option.
	vector<string> minimumOptions;
	minimumOptions.push_back( "-min" );
	minimumOptions.push_back( "-MIN" );
	minimumOptions.push_back( "--minimum" );
	parser->addOptionFlagsWithParameters( minimumOptions, "Specifies the minimum value that is viewable in the plot. Default is the smallest allowable point in a given data file. If the given value is less than the default, it is ignored." );

	// Add the SVG option.
	vector<string> svgOptions;
	svgOptions.push_back( "--svg" );
	parser->addOptionFlagsNoParameters( svgOptions, "Specify that the output file should be an SVG image file, rather than a Postscript image file." );

	// Add the text option.
	vector<string> textOptions;
	textOptions.push_back( "-t" );
	textOptions.push_back( "-T" );
	textOptions.push_back( "--text" );
	parser->addOptionFlagsNoParameters( textOptions, "Specifies that output should be a dot plot (text) file." );

	// Add the description option.
	vector<string> descOptions;
	descOptions.push_back( "--desc" );
	parser->addOptionFlagsWithParameters( descOptions, "Configure the output of descriptions. Valid values are: (1) \"\" or \"~none\" -- Do not write a description (2) \"~file\" -- If the default description corresponds to a file or path, use only the base name of the path (i.e. no directory or file extension). (3) \"~~\" or \"~default\" -- Use the default description (this is the same as not specifying the flag) (4) \"~list|DESC1|DESC2|DESC3\" -- use this syntax when the output is expected to have more than one plot. It specifies a list of descriptions will be applied in the order given. The character immediately after \"~list\" will be used as the separator (i.e. it need not be the bar (|) character. (5) Any other value is assumed to be the literal description you want to have displayed in the plot legend.");


	// Parse the command line into pieces.
	parser->parseLine( argc, argv );

	// Get required parameters from the parser.
	if( !parser->isError() ) {
		inputFile = parser->getParameter( 1 );
		outputFile = parser->getParameter( 2 );
	}

	// Get the entries option.
	if( !parser->isError() ) {
		parser->setOptionInteger( entriesOptions, entries );
		if( ( entries < ENTRIES_MINIMUM ) || ( entries > ENTRIES_MAXIMUM ) ) {
			if( entries < ENTRIES_MINIMUM ) { cerr << "Too few plot entries given." << endl; }
			else { cerr << "Too many plot entries given." << endl; }
			parser->setError();
		}
	}

	// Get the plot bounds options.
	if( !parser->isError() ) {
		parser->setOptionDouble( minimumOptions, minBound );
		parser->setOptionDouble( maximumOptions, maxBound );
		if( minBound > maxBound ) {
			cerr << "Minimum plot value cannot be greater than maximum plot value." << endl;
			parser->setError();
		}
	}

	// Get the description option.
	if( !parser->isError() && parser->contains( descOptions ) )
		descriptionSettings.parse(parser->getOptionString(descOptions, false)); 

	// Get the SVG option.
	if( !parser->isError() ) { isSVG = parser->contains( svgOptions ); }

	// Get the text option.
	if( !parser->isError() ) { writeText = parser->contains( textOptions ); }

	// Delete the parser and return whether the parser encountered an error.
	bool noError = ( parser->isError() == false );
	delete parser;
	return noError;
}
コード例 #4
0
ファイル: efn2.cpp プロジェクト: mayc2/PseudoKnot_research
///////////////////////////////////////////////////////////////////////////////
// Parse the command line arguments.
///////////////////////////////////////////////////////////////////////////////
bool efn2Interface::parse( int argc, char** argv ) {

	// Create the command line parser and build in its required parameters.
	ParseCommandLine* parser = new ParseCommandLine( "efn2" );
	parser->addParameterDescription( "ct file", "The name of a file containing structure CT data." );
	parser->addParameterDescription( "output file", "The energy file to which output is written. Depending on the options selected, this may be one of the following file types. 1) Simple list (Lists free energy for each structure, lowest first). 2) Thermodynamic details (Writes details of every substructure in each structure, and the corresponding free energy of each)." );

	// Add the DNA option.
	vector<string> dnaOptions;
	dnaOptions.push_back( "-d" );
	dnaOptions.push_back( "-D" );
	dnaOptions.push_back( "--DNA" );
	parser->addOptionFlagsNoParameters( dnaOptions, "Specify that the sequence is DNA, and DNA parameters are to be used. Default is to use RNA parameters." );

	// Add the simple eneergy function option.
	vector<string> simpleOptions;
	simpleOptions.push_back( "-s" );
	simpleOptions.push_back( "-S" );
	simpleOptions.push_back( "--simple" );
	parser->addOptionFlagsNoParameters( simpleOptions, "Specify the simple energy function for multibranch loops, used by the dynamic programming algorithms (Fold, partition, stochastic, AllSub, etc.), should be used. If this is not specified, an more sophisticated energy function is used, and the energies might not match those estimated for structures during structure prediction." );

	// Add the print option.
	vector<string> printOptions;
	printOptions.push_back( "-p" );
	printOptions.push_back( "-P" );
	printOptions.push_back( "--print" );
	parser->addOptionFlagsNoParameters( printOptions, "Print the simple list file to standard output. This won't override default behavior of writing to a file. Thermodynamic files (if written) are not piped." );

	// Add the SHAPE option.
	vector<string> shapeOptions;
	shapeOptions.push_back( "-sh" );
	shapeOptions.push_back( "-SH" );
	shapeOptions.push_back( "--SHAPE" );
	parser->addOptionFlagsWithParameters( shapeOptions, "Specify a SHAPE constraints file to be applied. These constraints are pseudoenergy constraints. Default is to have no constraints applied." );

	// Add the SHAPE intercept option.
	vector<string> shapeInterceptOptions;
	shapeInterceptOptions.push_back( "-si" );
	shapeInterceptOptions.push_back( "-SI" );
	shapeInterceptOptions.push_back( "--SHAPEintercept" );
	parser->addOptionFlagsWithParameters( shapeInterceptOptions, "Specify an intercept used with SHAPE constraints. Default is -0.6 kcal/mol." );

	// Add the SHAPE slope option.
	vector<string> shapeSlopeOptions;
	shapeSlopeOptions.push_back( "-sm" );
	shapeSlopeOptions.push_back( "-SM" );
	shapeSlopeOptions.push_back( "--SHAPEslope" );
	parser->addOptionFlagsWithParameters( shapeSlopeOptions, "Specify a slope used with SHAPE constraints. Default is 1.8 kcal/mol." );

	// Add the temperature option.
	vector<string> tempOptions;
	tempOptions.push_back( "-t" );
	tempOptions.push_back( "-T" );
	tempOptions.push_back( "--temperature" );
	parser->addOptionFlagsWithParameters( tempOptions, "Specify the temperature at which calculation takes place in Kelvin. Default is 310.15 K, which is 37 degrees C." );

	// Add the details option.
	vector<string> detailsOptions;
	detailsOptions.push_back( "-w" );
	detailsOptions.push_back( "-W" );
	detailsOptions.push_back( "--writedetails" );
	parser->addOptionFlagsNoParameters( detailsOptions, "Write a thermodynamic details file. The thermodynamic details file replaces the list file that is outputted by default." );

	// Parse the command line into pieces.
	parser->parseLine( argc, argv );

	// Get required parameters from the parser.
	if( !parser->isError() ) {
		ctFile = parser->getParameter( 1 );
		outFile = parser->getParameter( 2 );
	}

	// Get the DNA option.
	if( !parser->isError() ) { isRNA = !parser->contains( dnaOptions ); }

	// Get the simple energy rule option.
	if (!parser->isError() ) { simple = parser->contains( simpleOptions); }

	// Get the print option.
	if( !parser->isError() ) { stdPrint = parser->contains( printOptions ); }

	// Get the SHAPE data and options.
	if( !parser->isError() ) {
		SHAPEFile = parser->getOptionString( shapeOptions );
		if( !parser->isError() ) { parser->setOptionDouble( shapeInterceptOptions, intercept ); }
		if( !parser->isError() ) { parser->setOptionDouble( shapeSlopeOptions, slope ); }
	}

	// Get the temperature option.
	if( !parser->isError() ) {
		parser->setOptionDouble( tempOptions, temperature );
		if( temperature < 0 ) { parser->setError( "temperature" ); }
	}

	// Get the write thermodynamic details option.
	if( !parser->isError() ) { writeTherm = parser->contains( detailsOptions ); }

	// Delete the parser and return whether the parser encountered an error.
	bool noError = ( parser->isError() == false );
	delete parser;
	return noError;
}
コード例 #5
0
///////////////////////////////////////////////////////////////////////////////
// Parse the command line arguments.
///////////////////////////////////////////////////////////////////////////////
bool Multilign_Interface::parse( int argc, char** argv ) {

	// Determine the proper executable name, depending on if the executable is serial or SMP.
#ifndef COMPILE_SMP
	string type = "multilign";
#else
	string type = "multilign-smp";
#endif

	// Create the command line parser and build in its required parameters.
	ParseCommandLine* parser = new ParseCommandLine( type );
	parser->addParameterDescription( "configuration file", "The name of a file containing configuration data." );

	// Tell the parser that a special usage message is needed for this interface.
	parser->setSpecializedUsage();

	// Parse the command line into pieces.
	parser->parseLine( argc, argv );

	// If the specialized usage has been asked for, print it out.
	// An error is set here only for the purpose of preventing further parsing and calculation; it's not a real error.
	if( parser->isSpecializedUsage() ) {
		usage( parser );
		parser->setError();
		return false;
	}

	// Open the config file.
	// If the file isn't valid, delete the parser and return false.
	ConfigFile file( parser->getParameter( 1 ) );
	if( file.isValid() == false ) {
		delete parser;
		return false;
	}

	// Check if the config file contains the Alignment flag, which is always necessary for reading data.
	// If it exists, read it in.
	// If the flag isn't present, set an error, delete the parser, and return false.
	bool isReadable = file.contains( "Alignment" );
	if( isReadable ) { alignmentFile = file.getOption<string>( "Alignment" ); }
	else {
		parser->setErrorSpecialized( "Configuration file must contain the Alignment flag." );
		delete parser;
		return false;
	}

	// If SMP calculations are being done, make sure the processors flag has been specified.
	// If it has, set the number of processors if possible.
	// If it hasn't, show an error, delete the parser, and return false.
#ifdef COMPILE_SMP
	if( file.contains( "Processors" ) ) {
		processors = file.getOption<int>( "Processors" );
		if( processors < 0 ) {
			parser->setError( "number of processors" );
			delete parser;
			return false;
		}
	} else {
		parser->setErrorSpecialized( "Configuration file must contain the Processors flag." );
		delete parser;
		return false;
	}
#endif

	// Initialize the files vector.
	// Index 0: Sequence files
	// Index 1: CT files
	// Index 2: Optional folding constraint files
	// Index 3: Optional SHAPE constraint files
	for( int i = 1; i <= 4; i++ ) {
		vector<string> row;
		files.push_back( row );
	}

	// Check whether sequence files can be read singly.
	// If they can, attempt to read them into the 2D file vector.
	// An error occurs doing this, set an error, delete the parser, and return false.
	bool isReadableSingly =
		file.contains( "Seq1" ) &&
		file.contains( "CT1" ) &&
		file.contains( "SequenceNumber" );
	if( isReadableSingly ) {

		// Set the sequence number.
		// If the sequence number is less than or equal to 0, set an error, delete the parser, and return false.
		seqNumber = file.getOption<int>( "SequenceNumber" );
		if( seqNumber <= 0 ) {
			parser->setErrorSpecialized( "Sequence number must be greater than 0." );
			delete parser;
			return false;
		}

		// Read in all required files.
		// For each possible sequence number, read in the corresponding data file.
		for( int i = 1; i <= seqNumber; i++ ) {

			// Get the next sequence number as a string.
			stringstream numStream( stringstream::in | stringstream::out );
			numStream << i;
			string num = numStream.str();

			// Read in the next sequence file.
			// If an error occurs, set an error, delete the parser, and return false.
			string seqString = "Seq" + num;
			if( file.contains( seqString ) ) { files[0].push_back( file.getOption<string>( seqString ) ); }
			else {
				parser->setErrorSpecialized( "The number of sequence files specified must be equal to SequenceNumber." );
				delete parser;
				return false;
			}

			// Read in the next CT file.
			// If an error occurs, set an error, delete the parser, and return false.
			string ctString = "CT" + num;
			if( file.contains( ctString ) ) { files[1].push_back( file.getOption<string>( ctString ) ); }
			else {
				parser->setErrorSpecialized( "The number of CT files specified must be equal to SequenceNumber." );
				delete parser;
				return false;
			}
		}
	}
	// Check whether sequence files can be read in groups.
	// If they can, attempt to read them into the 2D file vector.
	// If an error occurs doing this, set an error, delete the parser, and return false.
	bool isReadableGroups =
		file.contains( "InSeq" ) &&
		file.contains( "OutCT" );
	if( isReadableGroups ) {

		// Get the sequences.
		string seqData = file.getOption<string>( "InSeq" );
		unsigned int seqLast = seqData.length() - 1;
		if( seqData[0] == '{' && seqData[seqLast] == '}' ) {
			seqData = seqData.erase( 0, 1 );
			seqData = seqData.erase( seqLast - 1, 1 );
			seqLast = seqData.length() - 1;
			if( seqData[seqLast] == ';' ) { seqData = seqData.erase( seqLast, 1 ); }
			stringstream seqStr( seqData );
			string seqFile;
			while( seqStr.good() ) {
				getline( seqStr, seqFile, ';' );
				if( seqFile != "" ) { files[0].push_back( seqFile ); }
			}
		} else {
			if( seqData[0] != '{' ) { parser->setErrorSpecialized( "Sequence group has no start bracket." ); }
			else { parser->setErrorSpecialized( "Sequence group has no end bracket." ); }
			delete parser;
			return false;
		}

		// Get the CT files.
		string ctData = file.getOption<string>( "OutCT" );
		unsigned int ctLast = ctData.length() - 1;
		if( ctData[0] == '{' && ctData[ctLast] == '}' ) {
			ctData = ctData.erase( 0, 1 );
			ctData = ctData.erase( ctLast - 1, 1 );
			ctLast = ctData.length() - 1;
			if( ctData[ctLast] == ';' ) { ctData = ctData.erase( ctLast, 1 ); }
			stringstream ctStr( ctData );
			string ctFile;
			while( ctStr.good() ) {
				getline( ctStr, ctFile, ';' );
				if( ctFile != "" ) { files[1].push_back( ctFile ); }
			}
		} else {
			if( ctData[0] != '{' ) { parser->setErrorSpecialized( "Sequence group has no start bracket." ); }
			else { parser->setErrorSpecialized( "Sequence group has no end bracket." ); }
			delete parser;
			return false;
		}

		// If the number of sequence files equals the number of CT files, set that number as the number of sequences.
		// If not, set an error, delete the parser, and return.
		if( files[0].size() == files[1].size() ) { seqNumber = files[0].size(); }
		else {
			parser->setErrorSpecialized( "Number of sequence files does not equal number of CT files." );
			delete parser;
			return false;
		}
	}

	// If the configuration file isn't set up properly to read sequence files singly or in groups, set an error, delete the parser, and return false.
	if( ( isReadableSingly == false ) && ( isReadableGroups == false ) ) {
		parser->setErrorSpecialized( "File groups are not specified properly. Please run \"" + type + " -h\" for help." );
		delete parser;
		return false;
	}

	// Check to see if optional constraint files or SHAPE files were specified.
	stringstream optionalStream( stringstream::in | stringstream::out );
	string constraintString, shapeString;
	hasSHAPE = false;
	for( int i = 1; i <= seqNumber; i++ ) {

		// If constraint file i is specified, get the name.
		optionalStream << "Constraint" << i;
		constraintString = optionalStream.str();
		if( file.contains( constraintString ) ) { files[2].push_back( file.getOption<string>( constraintString ) ); }
		else { files[2].push_back( "" ); }
		optionalStream.str( "" );

		// If SHAPE file i is specified, get the name.
		optionalStream << "SHAPE" << i;
		shapeString = optionalStream.str();
		if( file.contains( shapeString ) ) {
			files[3].push_back( file.getOption<string>( shapeString ) );
			hasSHAPE = true;
		} else { files[3].push_back( "" ); }
		optionalStream.str( "" );
	}

	// Get the nucleic acid type.
	if( !parser->isError() ) {
		if( file.contains( "DNA" ) ) { isRNA = !( file.getOption<bool>( "DNA" ) ); }
	}

	// Get the gap penalty.
	if( !parser->isError() ) {
		if( file.contains( "Gap" ) ) {
			gap = file.getOption<double>( "Gap" );
			if( gap <= 0.0 ) { parser->setError( "gap penalty" ); }
		}
	}

	// Get the index sequence.
	if( !parser->isError() ) {
		if( file.contains( "IndexSeq" ) ) {
			indexSeq = file.getOption<int>( "IndexSeq" );
			bool inRange = ( indexSeq >= 1 ) && ( indexSeq <= seqNumber );
			if( inRange == false ) { parser->setError( "index sequence number" ); }
		}
	}

	// Get whether base pairs should be inserted.
	if( !parser->isError() ) {
		if( file.contains( "Insert" ) ) { inserts = file.getOption<bool>( "Insert" ); }
	}

	// Get the number of iterations.
	if( !parser->isError() ) {
		if( file.contains( "Iterations" ) ) {
			iterations = file.getOption<int>( "Iterations" );
			if( iterations <= 0 ) { parser->setError( "number of iterations" ); }
		}
	}

	// Get whether intermediate files should be kept.
	if( !parser->isError() ) {
		if( file.contains( "KeepIntermediate" ) ) { keepIntermediate = file.getOption<bool>( "KeepIntermediate" ); }
	}

	// Get whether local folding should be done.
	if( !parser->isError() ) {
		if( file.contains( "Local" ) ) { local = file.getOption<bool>( "Local" ); }
	}

	// Get the maxdsvchange.
	if( !parser->isError() ) {
		if( file.contains( "MaxDsvChange" ) ) {
			maxDsvChange = file.getOption<double>( "MaxDsvChange" );
			bool inRange =
				( ( maxDsvChange > 0.0 && maxDsvChange < 99.0 ) ) ||
				( maxDsvChange == -1.0 );
			if( inRange == false ) { parser->setError( "maxdsvchange" ); }
		}
	}

	// Get the max pairs value.
	if( !parser->isError() ) {
		if( file.contains( "MaxPairs" ) ) {
			maxPairs = file.getOption<int>( "MaxPairs" );
			if( maxPairs <= 0 ) { parser->setError( "max pairs value" ); }
		}
	}

	// Get the maximum percent energy difference, if applicable.
	if( !parser->isError() ) {
		if( file.contains( "MaxPercent" ) ) {
			percent = file.getOption<int>( "MaxPercent" );
			if( percent <= 0 ) { parser->setError( "percent energy difference" ); }
		}
	}

	// Get the maximum percent energy difference in folding free energy change from single sequence folding.
	if( !parser->isError() ) {
		if( file.contains( "MaxPercentSingle" ) ) {
			percentSingle = file.getOption<int>( "MaxPercentSingle" );
			if( percentSingle <= 0 ) { parser->setError( "percent energy difference in folding free energy change" ); }
		}
	}

	// Get the maximum number of structures.
	if( !parser->isError() ) {
		if( file.contains( "MaxStructures" ) ) {
			maxStructures = file.getOption<int>( "MaxStructures" );
			if( maxStructures <= 0 ) { parser->setError( "maximum number of structures" ); }
		}
	}

	// Get the randomization flag.
	if( !parser->isError() ) {
		if( file.contains( "Random" ) ) { random = file.getOption<bool>( "Random" ); }
	}

	// Get the traditional M separation parameter.
	if( !parser->isError() ) {
		if( file.contains( "Separation" ) ) { maxSeparation = file.getOption<double>( "Separation" ); }
	}

	// Get the SHAPE intercept.
	if( !parser->isError() ) {
		if( hasSHAPE ) {
			if( file.contains( "SHAPEintercept" ) ) { intercept = file.getOption<double>( "SHAPEintercept" ); }
		}
	}

	// Get the SHAPE slope.
	if( !parser->isError() ) {
		if( hasSHAPE ) {
			if( file.contains( "SHAPEslope" ) ) { slope = file.getOption<double>( "SHAPEslope" ); }
		}
	}

	// Get the temperature.
	if( !parser->isError() ) {
		if( file.contains( "Temperature" ) ) {
			temperature = file.getOption<double>( "Temperature" );
			if( temperature < 0.0 ) { parser->setError( "temperature" ); }
		}
	}

	// Get the alignment window size.
	if( !parser->isError() ) {
		if( file.contains( "WindowAlign" ) ) {
			alignmentWindow = file.getOption<int>( "WindowAlign" );
			if( alignmentWindow < 0 ) { parser->setError( "alignment window" ); }
		}
	}

	// Get the base pair window size.
	if( !parser->isError() ) {
		if( file.contains( "WindowBP" ) ) {
			basepairWindow = file.getOption<int>( "WindowBP" );
			if( basepairWindow < 0 ) { parser->setError( "base pair window" ); }
		}
	}

	// Delete the parser and return whether the parser encountered an error.
	bool noError = ( parser->isError() == false );
	delete parser;
	return noError;
}
コード例 #6
0
///////////////////////////////////////////////////////////////////////////////
// Parse the command line arguments.
///////////////////////////////////////////////////////////////////////////////
bool DrawStructure::parse( int argc, char** argv ) {

    // Create the command line parser and build in its required parameters.
    ParseCommandLine* parser = new ParseCommandLine( "draw" );
    parser->addParameterDescription( "ct file", "The name of a file containing CT data for the structure to be drawn." );
    parser->addParameterDescription( "output file", "The name of an image file to which output will be written. Usually, this is a Postscript image file, although the user can specify that it be an SVG image file instead. To specify SVG images, the \"--svg\" flag must be specified in conjunction with a structure number flag." );

    // Add the circular option.
    vector<string> circleOptions;
    circleOptions.push_back( "-c" );
    circleOptions.push_back( "-C" );
    circleOptions.push_back( "--circle" );
    parser->addOptionFlagsNoParameters( circleOptions, "Specify that the structure should be drawn with its backbone stretched around a circle. Note that pseudoknotted structures will be drawn circularized even if this option is not specified. Default is to show a collapsed structure." );

    // Add the flat option.
    vector<string> flatOptions;
    flatOptions.push_back( "-f" );
    flatOptions.push_back( "-F" );
    flatOptions.push_back( "--flat" );
    parser->addOptionFlagsNoParameters( flatOptions, "Specify that the structure should be drawn with its backbone stretched in a straight line. Default is to show a collapsed structure." );

    // Add the levorotatory option.
    vector<string> levorotatoryOptions;
    levorotatoryOptions.push_back( "-l" );
    levorotatoryOptions.push_back( "-L" );
    levorotatoryOptions.push_back( "--levorotatory" );
    parser->addOptionFlagsNoParameters( levorotatoryOptions, "Specify that the drawn structure is rendered counterclockwise. Default is to render drawn structures clockwise." );

    // Add the number option.
    vector<string> numberOptions;
    numberOptions.push_back( "-n" );
    numberOptions.push_back( "-N" );
    numberOptions.push_back( "--number" );
    parser->addOptionFlagsWithParameters( numberOptions, "Specify the index of a particular structure in the predicted CT to be compared with the accepted CT, one-indexed. Default is -1, which signifies all structures output to one file." );

    // Add the probability option.
    vector<string> probabilityOptions;
    probabilityOptions.push_back( "-p" );
    probabilityOptions.push_back( "-P" );
    probabilityOptions.push_back( "--probability" );
    parser->addOptionFlagsWithParameters( probabilityOptions, "Specify the name of the partition function file from which base pairing probability data will be read for annotation. This file should describe pairing data for the predicted structure, not the accepted structure. Default is no probability annotation file used." );

    // Add the SHAPE option.
    vector<string> shapeOptions;
    shapeOptions.push_back( "-s" );
    shapeOptions.push_back( "-S" );
    shapeOptions.push_back( "--SHAPE" );
    parser->addOptionFlagsWithParameters( shapeOptions, "Specify the name of the file from which SHAPE data will be read for annotation. Default is no SHAPE annotation file used." );

    // Add the SVG option.
    vector<string> svgOptions;
    svgOptions.push_back( "--svg" );
    parser->addOptionFlagsNoParameters( svgOptions, "Specify that the output file should be an SVG image file, rather than a Postscript image file. Note that only one SVG image can be written into a particular file, so the structure number flag must also be specified when writing an SVG document." );

    // Add the text annotation option.
    vector<string> textOptions;
    textOptions.push_back( "-t" );
    textOptions.push_back( "-T" );
    textOptions.push_back( "--text" );
    parser->addOptionFlagsWithParameters( textOptions, "Specify the name of the text file from which base pairing probability data will be read for annotation. This file should describe pairing data for the predicted structure, not the accepted structure. Default is no probability annotation file used." );

    // Add the uncircled option.
    vector<string> uncircledOptions;
    uncircledOptions.push_back( "-u" );
    uncircledOptions.push_back( "-U" );
    uncircledOptions.push_back( "--uncircled" );
    parser->addOptionFlagsNoParameters( uncircledOptions, "Specify that no circles should surround nucleotides when drawing. Default is to surround nucleotides with circles." );

    // Parse the command line into pieces.
    parser->parseLine( argc, argv );

    // Get required parameters from the parser.
    if( !parser->isError() ) {
        inputFile = parser->getParameter( 1 );
        outputFile = parser->getParameter( 2 );
    }

    // Get the circular option.
    if( !parser->isError() ) {
        circular = parser->contains( circleOptions );
    }

    // Get the flat option.
    if( !parser->isError() ) {
        flat = parser->contains( flatOptions );
    }

    // Get the levorotatory option.
    if( !parser->isError() ) {
        levorotatory = parser->contains( levorotatoryOptions );
    }

    // Get the number option.
    if( !parser->isError() ) {
        parser->setOptionInteger( numberOptions, number );
        bool badNumber =
            ( number != -1 ) &&
            ( number < 0 );
        if( badNumber ) {
            parser->setError( "structure number" );
        }
    }

    // Get the probability annotation file option.
    // This can be read either as a partition function save file or a text file.
    if( !parser->isError() ) {
        probabilityFile = parser->getOptionString( probabilityOptions, true );
        if( probabilityFile == "" ) {
            probabilityFile = parser->getOptionString( textOptions, true );
            if( probabilityFile != "" ) {
                textAnnotation = true;
            }
        }
    }

    // Get the SHAPE annotation file option.
    if( !parser->isError() ) {
        SHAPEFile = parser->getOptionString( shapeOptions, true );
    }

    // Get the SVG option.
    if( !parser->isError() ) {
        isSVG = parser->contains( svgOptions );
    }

    // Get the uncircled option.
    if( !parser->isError() ) {
        encircle = !parser->contains( uncircledOptions );
    }

    // If the user requests levorotatory and linear, show an error, because linear structures should only be shown one way.
    if( levorotatory && flat ) {
        parser->setErrorSpecialized( "Linear structures cannot be rendered counterclockwise." );
    }

    // If in SVG mode and no structure number is specified, show an error message.
    if( ( !parser->isError() ) && parser->contains( svgOptions ) && ( !parser->contains( numberOptions ) ) ) {
        cerr << "No structure number specified with SVG structure." << endl
             << "Please specify the structure to draw as an SVG image file." << endl;
        parser->setError();
    }

    // Delete the parser and return whether the parser encountered an error.
    bool noError = ( parser->isError() == false );
    delete parser;
    return noError;
}
コード例 #7
0
///////////////////////////////////////////////////////////////////////////////
// Parse the command line arguments.
///////////////////////////////////////////////////////////////////////////////
bool TurboFold_Interface::parse( int argc, char** argv ) {

	// Determine the proper executable name, depending on if the executable is serial or SMP.
#ifndef COMPILE_SMP
	string type = "TurboFold";
#else
	string type = "TurboFold-smp";
#endif

	// Create the command line parser and build in its required parameters.
	ParseCommandLine* parser = new ParseCommandLine( type );
	parser->addParameterDescription( "configuration file", "The name of a file containing configuration data." );

	// Tell the parser that a special usage message is needed for this interface.
	parser->setSpecializedUsage();

	// Parse the command line into pieces.
	parser->parseLine( argc, argv );

	// If the specialized usage has been asked for, print it out.
	// An error is set here only for the purpose of preventing further parsing and calculation; it's not a real error.
	if( parser->isSpecializedUsage() ) {
		usage( parser );
		parser->setError();
		return false;
	}

	// Open the config file.
	// If the file isn't valid, delete the parser and return false.
	ConfigFile file( parser->getParameter( 1 ) );
	if( file.isValid() == false ) {
		delete parser;
		return false;
	}

	// Check if the config file contains the Mode flag, which is always necessary for reading data.
	// If it exists, read it in.
	// If the flag isn't present, set an error, delete the parser, and return false.
	bool isReadable = file.contains( "Mode" );
	if( isReadable ) { mode = file.getOption<string>( "Mode" ); }
	else {
		parser->setErrorSpecialized( "Configuration file must contain the Mode flag." );
		delete parser;
		return false;
	}

	// If SMP calculations are being done, make sure the processors flag has been specified.
	// If it has, set the number of processors if possible.
	// If it hasn't, show an error, delete the parser, and return false.
#ifdef COMPILE_SMP
	if( file.contains( "Processors" ) ) {
		processors = file.getOption<int>( "Processors" );
		if( processors < 0 ) {
			parser->setError( "number of processors" );
			delete parser;
			return false;
		}
	} else {
		parser->setErrorSpecialized( "Configuration file must contain the Processors flag." );
		delete parser;
		return false;
	}
#endif

	// Initialize the files vector.
	// Index 0: Sequence files
	// Index 1: CT files
	// Index 2: Optional partition function file names
	// Index 3: Optional SHAPE constraint files
	for( int i = 1; i <= 4; i++ ) {
		vector<string> row;
		files.push_back( row );
	}

	// Check whether sequence files can be read singly.
	// If they can, attempt to read them into the 2D file vector.
	// An error occurs doing this, set an error, delete the parser, and return false.
	bool isReadableSingly =
		file.contains( "Seq1" ) &&
		file.contains( "CT1" ) &&
		file.contains( "SequenceNumber" );
	if( isReadableSingly ) {

		// Set the sequence number.
		// If the sequence number is less than or equal to 0, set an error, delete the parser, and return false.
		seqNumber = file.getOption<int>( "SequenceNumber" );
		if( seqNumber <= 0 ) {
			parser->setErrorSpecialized( "Sequence number must be greater than 0." );
			delete parser;
			return false;
		}

		// Read in all required files.
		// For each possible sequence number, read in the corresponding data file.
		for( int i = 1; i <= seqNumber; i++ ) {

			// Get the next sequence number as a string.
			stringstream numStream( stringstream::in | stringstream::out );
			numStream << i;
			string num = numStream.str();

			// Read in the next sequence file.
			// If an error occurs, set an error, delete the parser, and return false.
			string seqString = "Seq" + num;
			if( file.contains( seqString ) ) { files[0].push_back( file.getOption<string>( seqString ) ); }
			else {
				parser->setErrorSpecialized( "The number of sequence files specified must be equal to SequenceNumber." );
				delete parser;
				return false;
			}

			// Read in the next CT file.
			// If an error occurs, set an error, delete the parser, and return false.
			string ctString = "CT" + num;
			if( file.contains( ctString ) ) { files[1].push_back( file.getOption<string>( ctString ) ); }
			else {
				parser->setErrorSpecialized( "The number of CT files specified must be equal to SequenceNumber." );
				delete parser;
				return false;
			}
		}
	}
	// Check whether sequence files can be read in groups.
	// If they can, attempt to read them into the 2D file vector.
	// If an error occurs doing this, set an error, delete the parser, and return false.
	bool isReadableGroups =
		file.contains( "InSeq" ) &&
		file.contains( "OutCT" );
	if( isReadableGroups ) {

		// Get the sequences.
		string seqData = file.getOption<string>( "InSeq" );
		unsigned int seqLast = seqData.length() - 1;
		if( seqData[0] == '{' && seqData[seqLast] == '}' ) {
			seqData = seqData.erase( 0, 1 );
			seqData = seqData.erase( seqLast - 1, 1 );
			seqLast = seqData.length() - 1;
			if( seqData[seqLast] == ';' ) { seqData = seqData.erase( seqLast, 1 ); }
			stringstream seqStr( seqData );
			string seqFile;
			while( seqStr.good() ) {
				getline( seqStr, seqFile, ';' );
				if( seqFile != "" ) { files[0].push_back( seqFile ); }
			}
		} else {
			if( seqData[0] != '{' ) { parser->setErrorSpecialized( "Sequence group has no start bracket." ); }
			else { parser->setErrorSpecialized( "Sequence group has no end bracket." ); }
			delete parser;
			return false;
		}

		// Get the CT files.
		string ctData = file.getOption<string>( "OutCT" );
		unsigned int ctLast = ctData.length() - 1;
		if( ctData[0] == '{' && ctData[ctLast] == '}' ) {
			ctData = ctData.erase( 0, 1 );
			ctData = ctData.erase( ctLast - 1, 1 );
			ctLast = ctData.length() - 1;
			if( ctData[ctLast] == ';' ) { ctData = ctData.erase( ctLast, 1 ); }
			stringstream ctStr( ctData );
			string ctFile;
			while( ctStr.good() ) {
				getline( ctStr, ctFile, ';' );
				if( ctFile != "" ) { files[1].push_back( ctFile ); }
			}
		} else {
			if( ctData[0] != '{' ) { parser->setErrorSpecialized( "Sequence group has no start bracket." ); }
			else { parser->setErrorSpecialized( "Sequence group has no end bracket." ); }
			delete parser;
			return false;
		}

		// If the number of sequence files equals the number of CT files, set that number as the number of sequences.
		// If not, set an error, delete the parser, and return.
		if( files[0].size() == files[1].size() ) { seqNumber = files[0].size(); }
		else {
			parser->setErrorSpecialized( "Number of sequence files does not equal number of CT files." );
			delete parser;
			return false;
		}
	}

	// If the configuration file isn't set up properly to read sequence files singly or in groups, set an error, delete the parser, and return false.
	if( ( isReadableSingly == false ) && ( isReadableGroups == false ) ) {
		parser->setErrorSpecialized( "File groups are not specified properly. Please run \"" + type + " -h\" for help." );
		delete parser;
		return false;
	}

	// Check to see if optional save files or SHAPE files were specified.
	stringstream optionalStream( stringstream::in | stringstream::out );
	string saveString, shapeString;
	hasSHAPE = false;
	for( int i = 1; i <= seqNumber; i++ ) {

		// If save file i is specified, get the name.
		optionalStream << "Save" << i;
		saveString = optionalStream.str();
		if( file.contains( saveString ) ) { files[2].push_back( file.getOption<string>( saveString ) ); }
		else { files[2].push_back( "" ); }
		optionalStream.str( "" );

		// If SHAPE file i is specified, get the name.
		optionalStream << "SHAPE" << i;
		shapeString = optionalStream.str();
		if( file.contains( shapeString ) ) {
			files[3].push_back( file.getOption<string>( shapeString ) );
			hasSHAPE = true;
		} else { files[3].push_back( "" ); }
		optionalStream.str( "" );
	}

	// Set the general options.
	if( true ) {

		// Get the TurboFold gamma.
		if( !parser->isError() ) {
			if( file.contains( "Gamma" ) ) {
				turboGamma = file.getOption<double>( "Gamma" );
				if( turboGamma < 0.0 ) { parser->setError( "TurboFold gamma" ); }
			}
		}

		// Get the TurboFold iterations.
		if( !parser->isError() ) {
			if( file.contains( "Iterations" ) ) {
				turboIterations = file.getOption<int>( "Iterations" );
				if( turboIterations < 0 ) { parser->setError( "TurboFold iterations" ); }
			}
		}

		// Get the maximum pairing distance.
		if( !parser->isError() ) {
			if( file.contains( "MaximumPairingDistance" ) ) {
				distance = file.getOption<int>( "MaximumPairingDistance" );
				if( distance < 0 ) { parser->setError( "maximum pairing distance" ); }
			}
		}

		// Get the SHAPE intercept.
		if( !parser->isError() ) {
			if( hasSHAPE ) {
				if( file.contains( "SHAPEintercept" ) ) { intercept = file.getOption<double>( "SHAPEintercept" ); }
			}
		}

		// Get the SHAPE slope.
		if( !parser->isError() ) {
			if( hasSHAPE ) {
				if( file.contains( "SHAPEslope" ) ) { slope = file.getOption<double>( "SHAPEslope" ); }
			}
		}

		// Get the temperature.
		if( !parser->isError() ) {
			if( file.contains( "Temperature" ) ) {
				temperature = file.getOption<double>( "Temperature" );
				if( temperature < 0.0 ) { parser->setError( "temperature" ); }
			}
		}
	}

	// Set the MEA mode options, if applicable.
	if( mode == "MEA" ) {

		// Get the maximum percent energy difference.
		if( !parser->isError() ) {
			if( file.contains( "MaxPercent" ) ) {
				percent = file.getOption<double>( "MaxPercent" );
				if( percent < 0.0 ) { parser->setError( "maximum percent energy difference" ); }
			}
		}

		// Get the maximum number of structures.
		if( !parser->isError() ) {
			if( file.contains( "MaxStructures" ) ) {
				maxStructures = file.getOption<int>( "MaxStructures" );
				if( maxStructures < 0 ) { parser->setError( "maximum number of structures" ); }
			}
		}

                // Get the MEA gamma.
                if( !parser->isError() ) {
		  if( file.contains( "MeaGamma" ) ) { meaGamma = file.getOption<double>( "MeaGamma" ); }
                }

		// Get the window size.
		if( !parser->isError() ) {
			if( file.contains( "Window" ) ) {
				windowSize = file.getOption<int>( "Window" );
				if( windowSize < 0 ) { parser->setError( "window size" ); }
			}
		}
	}

	// Set the ProbKnot mode options, if applicable.
	else if( mode == "ProbKnot" ) {

		// Get the number of ProbKnot iterations.
		if( !parser->isError() ) {
			if( file.contains( "PkIterations" ) ) {
				pkIterations = file.getOption<int>( "PkIterations" );
				if( pkIterations < 0 ) { parser->setError( "ProbKnot iterations" ); }
			}
		}

		// Get the minimum helix length, if applicable.
		if( !parser->isError() ) {
			if( file.contains( "MinHelixLength" ) ) {
				minHelixLength = file.getOption<int>( "MinHelixLength" );
				if( minHelixLength < 0 ) { parser->setError( "minimum helix length" ); }
			}
		}
	}

	// Set the Threshold mode options, if applicable.
	else if( mode == "Threshold" ) {

		// Get the threshold for pairs.
		if( !parser->isError() ) {
			if( file.contains( "Threshold" ) ) {
				threshold = file.getOption<double>( "Threshold" );
				if( threshold < 0.0 ) { parser->setError( "pairing threshold" ); }
			}
		}
	}

	// If an invalid mode was specified, show an error message.
	else {
		parser->setErrorSpecialized( "Invalid mode given; mode must be 'MEA', 'ProbKnot', or 'TurboFold'." );
	}

	// Delete the parser and return whether the parser encountered an error.
	bool noError = ( parser->isError() == false );
	delete parser;
	return noError;
}
コード例 #8
0
ファイル: bifold.cpp プロジェクト: DasLab/BPPalign
///////////////////////////////////////////////////////////////////////////////
// Parse the command line arguments.
///////////////////////////////////////////////////////////////////////////////
bool bifold::parse( int argc, char** argv ) {

  // Initialize arrays of flags without and with parameters.
  const char* flagsNoParams[] = {
    "-d", "-D", "--DNA",
    "-i", "-I", "--intramolecular",
  };

  const char* flagsParams[] = {
    "-l", "-L", "--loop",
    "-m", "-M", "--maximum",
    "-p", "-P", "--percent",
    "-s", "-S", "--save",
    "-t", "-T", "--temperature",
    "-w", "-W", "--window"
  };

  // Initialize usage string.
  string usageString =
    "USAGE: bifold <seq file 1> <seq file 2> <ct file> [options]";

  // Initialize required parameters string.
  string seq1Help = "\
<seq file 1>\n\
     The name of a file containing a first input sequence.\
";

  string seq2Help = "\
<seq file 2>\n\
     The name of a file containing a second input sequence.\
";

  string ctHelp = "\
<ct file>\n\
     The name of a CT file to which output will be written.\
";

  string paramsString =
    seq1Help + "\n\n" + seq2Help + "\n\n" + ctHelp;

  // Initialize flags without parameters string.
  string dnaHelp = "\
-d, -D, --DNA\n\
     Specify that the sequence is DNA, and DNA parameters are to be used.\n\
     Default is to use RNA parameters.\
";

  string helpLabel = "\
-h, -H, --help\n\
     Display the usage details message.\
";

  string intramolecularHelp = "\
-i, -I, --intramolecular\n\
     Forbid intramolecular pairs (pairs within the same strand).\n\
     Default is to allow intramolecular pairs.\
";

  string flagsNoParamsString =
    dnaHelp + "\n\n" + helpLabel + "\n\n" + intramolecularHelp;

  // Initialize the flags with parameters string.
  string loopHelp = "\
-l, -L, --loop\n\
     Specify a maximum internal/bulge loop size.\n\
     Default is 30 unpaired nucleotides.\
";

  string maxStructuresHelp = "\
-m, -M, --maximum\n\
     Specify a maximum number of structures.\n\
     Default is 20 structures.\
";

  string percentHelp = "\
-p, -P, --percent\n\
     Specify a maximum percent energy difference.\n\
     Default is 10 percent (specified as 10, not 0.1).\
";

  string saveHelp = "\
-s, -S, --save\n\
     Specify the name of a save file, needed for dotplots and refolding.\n\
     Default is not to generate a save file.\
";

  string tempHelp = "\
-t, -T, --temperature\n\
     Specify the temperature at which calculation takes place in Kelvin.\n\
     Default is 310.15 K, which is 37 degrees C.\
";

  string windowHelp = "\
-w, -W, --window\n\
     Specify a window size.\n\
     Default is 0 nucleotides.\
";

  string flagsParamsString =
    loopHelp + "\n\n" + maxStructuresHelp + "\n\n" + percentHelp + "\n\n" +
    saveHelp + "\n\n" + tempHelp + "\n\n" + windowHelp;

  // Initialize parser and check the command line.
  ParseCommandLine* parser = new ParseCommandLine( argc, argv, 3,
						   6, flagsNoParams,
						   18, flagsParams );
  parser->setUsageStrings( usageString.c_str(), paramsString.c_str(),
                           flagsNoParamsString.c_str(),
			   flagsParamsString.c_str() );
  bool noError = parser->checkLine();

  // If command line structure is OK, proceed with argument retrieval, parsing.
  if( noError ) {

    // Get required parameters.
    seqFile1 = parser->getParameter( 1 );
    seqFile2 = parser->getParameter( 2 );
    ctFile = parser->getParameter( 3 );

    // Set non-parameterized flag(s).
    isRNA = !parser->containsInGroup( "-d -D --DNA" );
    intramolecular = !parser->containsInGroup( "-i -I --intramolecular" );

    // Set parameterized options
    // If one of these options is not found on the command line, the action to
    // set that option is skipped.
    // If one throws an error, an error message is shown and parsing continues,
    // so all errors are shown if there are more than one.
    bool flagSet = true;

    // Maximum loop size option
    flagSet = parser->setOption( maxLoop, "-l -L --loop",
				 "Invalid maximum loop size given." );
    if( flagSet == false ) { noError = false; }

    // Maximum number of structures option
    flagSet = parser->setOption( maxStructures, "-m -M --maximum",
				 "Invalid number of structures given." );
    if( flagSet == false ) { noError = false; }

    // Percent difference option
    flagSet = parser->setOption( percent, "-p -P --percent",
				 "Invalid percent difference given.", ">= 0" );
    if( flagSet == false ) { noError = false; }

    // Save file option
    const char* saveString = "";
    flagSet = parser->setOption( saveString, "-s -S --save",
				 "Error creating save file name.", false );
    if( flagSet == false ) { noError = false; }
    saveFile = saveString;

    // Temperature option
    flagSet = parser->setOption( temperature, "-t -T --temperature",
				 "Invalid temperature given.", ">= 0" );
    if( flagSet == false ) { noError = false; }

    // Window size option
    flagSet = parser->setOption( windowSize, "-w -W --window",
				 "Invalid window size.", ">= 0" );
    if( flagSet == false ) { noError = false; }
  }

  // Delete the parser and return the error state.
  delete parser;
  return noError;

}
コード例 #9
0
bool ShapeKnots_Interface::Parse(int argc, char** argv){
	
	// Create the command line parser and build in its required parameters.
	ParseCommandLine* parser = new ParseCommandLine( "ShapeKnots" );
	parser->addParameterDescription( "seq file", "The name of a sequence file containing input data. Note that lowercase nucleotides are forced single-stranded in structure prediction." );
	parser->addParameterDescription( "ct file", "The name of a CT file to which output will be written." );

    // Add the constraint file option.
	vector<string> constraintOptions;
	constraintOptions.push_back( "-c" );
	constraintOptions.push_back( "-C" );
	constraintOptions.push_back( "--constraint" );
	parser->addOptionFlagsWithParameters( constraintOptions, "Specify a constraints file to be applied. Default is to have no constraints applied." );

    // Add the DMS option.
	vector<string> dmsOptions;
	dmsOptions.push_back( "-dms" );
	dmsOptions.push_back( "-DMS" );
	dmsOptions.push_back( "--DMS" );
	parser->addOptionFlagsWithParameters( dmsOptions, "Specify a DMS constraints file to be applied. These constraints are pseudoenergy constraints. Default is to have no constraints applied." );

	// Add the differential SHAPE restraint file option.
	vector<string> DshapeOptions;
	DshapeOptions.push_back( "-dsh" );
	DshapeOptions.push_back( "-DSH" );
	DshapeOptions.push_back( "--DSHAPE" );
	parser->addOptionFlagsWithParameters(DshapeOptions, "Specify a differential SHAPE restraints file to be applied. These constraints are pseudoenergy restraints. Default is to have no restraints applied." );

	// Add the differential SHAPEslope option.
	vector<string> DshapeSlopeOptions;
	DshapeSlopeOptions.push_back( "-dsm" );
	DshapeSlopeOptions.push_back( "-DSM" );
	DshapeSlopeOptions.push_back( "--DSHAPEslope" );
	parser->addOptionFlagsWithParameters( DshapeSlopeOptions, "Specify a slope used with differential SHAPE restraints. Default is 2.11 kcal/mol." );

	// Add the double offset file option.
	vector<string> doubleOffsetOptions;
	doubleOffsetOptions.push_back( "-dso" );
	doubleOffsetOptions.push_back( "-DSO" );
	doubleOffsetOptions.push_back( "--doubleOffset" );
	parser->addOptionFlagsWithParameters( doubleOffsetOptions, "Specify a double-stranded offset file, which adds energy bonuses to particular double-stranded nucleotides. Default is to have no double-stranded offset specified." );

	// Add the maximum number of structures option.                                                                                                                                                        
	vector<string> INmaxStructuresOptions;
	INmaxStructuresOptions.push_back( "-im" );
	INmaxStructuresOptions.push_back( "-IM" );
	INmaxStructuresOptions.push_back( "--IMaximum" );
	parser->addOptionFlagsWithParameters( INmaxStructuresOptions, "Specify a maximum number of internally generated structures for each call of the dynamic programming algorithm. Note that suboptimal structures are generated until either the maximum number of structures is reached or the maximum percent difference is reached (below).  This is not the maximum number of structures provided to the user, which is controlled by –m, -M, --maximum. Default is 100 structures." );
	
	// Add the percent energy difference option.
	vector<string> INpercentOptions;
	INpercentOptions.push_back( "-ip" );
	INpercentOptions.push_back( "-IP" );
	INpercentOptions.push_back( "--IPercent" );
	parser->addOptionFlagsWithParameters( INpercentOptions, "Specify a maximum percent difference in folding free energy change for internally generated suboptimal structures for each call of the dynamic programming algorithm. For example, 20 would indicate 20%. This is not the maximum percent difference in energy for structures provided to the user, which is controlled by –p, -P, --percent. Default is 20%." );
	
	// Add the window size option.                                                                                                                                                                         
	vector<string> INwindowOptions;
	INwindowOptions.push_back( "-iw" );
	INwindowOptions.push_back( "-IW" );
	INwindowOptions.push_back( "--IWindow" );
	parser->addOptionFlagsWithParameters( INwindowOptions, "Specify a window size for the internally generated suboptimal structures for each call of the dynamic programming algorithm.  This is not the window for structures provided to the user, which is controlled by –w, -W, --window. Default is determined by the length of the sequence." );

	// Add the maximum number of structures option.                                                                                                                                                        
	vector<string> OUTmaxStructuresOptions;
	OUTmaxStructuresOptions.push_back( "-m" );
	OUTmaxStructuresOptions.push_back( "-M" );
	OUTmaxStructuresOptions.push_back( "--maximum" );
	parser->addOptionFlagsWithParameters( OUTmaxStructuresOptions, "Specify a maximum number of structures to be outputted. Note that suboptimal structures are generated until either the maximum number of structures is reached or the maximum percent difference is reached (below). Default is 20 structures." );
	
	// Add the percent energy difference option.
	vector<string> OUTpercentOptions;
	OUTpercentOptions.push_back( "-p" );
	OUTpercentOptions.push_back( "-P" );
	OUTpercentOptions.push_back( "--percent" );
	parser->addOptionFlagsWithParameters( OUTpercentOptions, "Specify a maximum percent difference in folding free energy change for generating suboptimal structures in the output. For example, 10 would indicate 10%. Default is 10%." );

	// Add the Penalty1 option.
	vector<string> Penalty1Options;
	Penalty1Options.push_back( "-p1" );
	Penalty1Options.push_back( "-P1" );
	Penalty1Options.push_back( "--Penalty1" );
	parser->addOptionFlagsWithParameters( Penalty1Options, "Specify a pseudoknot penalty P1. Default is 0.35 kcal/mol." );

	// Add the Penalty2 option.
	vector<string> Penalty2Options;
	Penalty2Options.push_back( "-p2" );
	Penalty2Options.push_back( "-P2" );
	Penalty2Options.push_back( "--Penalty2" );
	parser->addOptionFlagsWithParameters( Penalty2Options, "Specify a pseudoknot penalty P2. Default is 0.65 kcal/mol." );

	// Add the finallistSize option.
	vector<string> finallistSizeOptions;
	finallistSizeOptions.push_back( "-ph" );
	finallistSizeOptions.push_back( "-PH" );
	finallistSizeOptions.push_back( "--PseudoknottedHelices" );
	parser->addOptionFlagsWithParameters( finallistSizeOptions, "Specify maximum number of helices to be processed. Default is 100 helices." );

	// Add the SHAPE restraint file option.
	vector<string> shapeOptions;
	shapeOptions.push_back( "-sh" );
	shapeOptions.push_back( "-SH" );
	shapeOptions.push_back( "--SHAPE" );
	parser->addOptionFlagsWithParameters(shapeOptions, "Specify a SHAPE restraints file to be applied. These restraints specifically use SHAPE pseudoenergy restraints. Default is no SHAPE restraint file specified." );

	// Add the SHAPEintercept option.
	vector<string> shapeInterceptOptions;
	shapeInterceptOptions.push_back( "-si" );
	shapeInterceptOptions.push_back( "-SI" );
	shapeInterceptOptions.push_back( "--SHAPEintercept" );
	parser->addOptionFlagsWithParameters( shapeInterceptOptions, "Specify an intercept used with SHAPE restraints. Default is -0.6 kcal/mol." );

	// Add the SHAPEslope option.
	vector<string> shapeSlopeOptions;
	shapeSlopeOptions.push_back( "-sm" );
	shapeSlopeOptions.push_back( "-SM" );
	shapeSlopeOptions.push_back( "--SHAPEslope" );
	parser->addOptionFlagsWithParameters( shapeSlopeOptions, "Specify an slope used with SHAPE restraints. Default is 1.8 kcal/mol." );

	// Add the single offset file option.
	vector<string> singleOffsetOptions;
	singleOffsetOptions.push_back( "-sso" );
	singleOffsetOptions.push_back( "-SSO" );
	singleOffsetOptions.push_back( "--singleOffset" );
	parser->addOptionFlagsWithParameters( singleOffsetOptions, "Specify a single-stranded offset file, which adds energy bonuses to particular single-stranded nucleotides. Default is to have no single-stranded offset specified." );
	
	// Add the window size option.                                                                                                                                                                         
	vector<string> OUTwindowOptions;
	OUTwindowOptions.push_back( "-w" );
	OUTwindowOptions.push_back( "-W" );
	OUTwindowOptions.push_back( "--window" );
	parser->addOptionFlagsWithParameters( OUTwindowOptions, "Specify a window size for outputted suboptimal structures. Default is determined by the length of the sequence." );

	// Parse the command line into pieces.
	parser->parseLine( argc, argv );

	// Get required parameters from the parser.                                                                                                                                                            
	if( !parser->isError() ) {
		seqFile = parser->getParameter( 1 );
		ctFile = parser->getParameter( 2 );
	}

	// Get the constraint file option.
	if( !parser->isError() ) { constraintFile = parser->getOptionString( constraintOptions, true ); }

	// Get the differential SHAPE slope option.
	if( !parser->isError() ) {
		parser->setOptionDouble( DshapeSlopeOptions, Dslope );
	}

	// Get the double strand offset file option.
	if( !parser->isError() ) { doubleOffsetFile = parser->getOptionString( doubleOffsetOptions, true ); }

	// Get the maximum number of structures to be internally generated.
	if( !parser->isError() ) {
		parser->setOptionInteger( INmaxStructuresOptions, InMaxStructures );
		if( OutMaxStructures <= 0 ) { parser->setError( "maximum number of structures" ); }
	}

	// Get the percent energy difference option for internally generated structures.
	if( !parser->isError() ) {
		parser->setOptionInteger( INpercentOptions, InPercent );
		if( OutPercent < 0 ) { parser->setError( "percent energy difference" ); }
	}
	
	// Get the window size option for internally generated structures.
	if( !parser->isError() ) {
		parser->setOptionInteger( INwindowOptions, InWindowSize );
		if( InWindowSize < 0 ) { parser->setError( "window size" ); }
	}

	// Get the maximum number of structures to be outputted option.
	if( !parser->isError() ) {
		parser->setOptionInteger( OUTmaxStructuresOptions, OutMaxStructures );
		if( OutMaxStructures <= 0 ) { parser->setError( "maximum number of structures" ); }
	}

	// Set modifier type
	if( !parser->isError() ) {
		if(parser->contains(dmsOptions))
		    modifier = "DMS"; 
		if(parser->contains(shapeOptions))
		    modifier = "SHAPE"; 
	}

	// Get the SHAPE, and DMS data and options.
	if( !parser->isError() ) {
		SHAPEFile = parser->getOptionString( shapeOptions );
		DSHAPEFile = parser->getOptionString( DshapeOptions );
        DMSFile = parser->getOptionString( dmsOptions ); 
        if( !parser->isError() ) { parser->setOptionDouble( shapeInterceptOptions, intercept ); }
        if( !parser->isError() ) { parser->setOptionDouble( shapeSlopeOptions, slope ); }
		if( !parser->isError() ) { parser->setOptionDouble( DshapeSlopeOptions, Dslope ); }
	}
    
	// Get the percent energy difference option for outputted suboptimal structures.
    if( !parser->isError() ) {
        parser->setOptionInteger( OUTpercentOptions, OutPercent );
        if( OutPercent < 0 ) { parser->setError( "percent energy difference" ); }
	}

	// Get the pseudoknot penalty 1.
	if( !parser->isError() ) {
		parser->setOptionDouble( Penalty1Options, P1 );
	}

	// Get the pseudoknot penalty 2.
	if( !parser->isError() ) {
		parser->setOptionDouble( Penalty2Options, P2 );
	}

	// Get the finallistSize option.
	if( !parser->isError() ) {
		parser->setOptionInteger( finallistSizeOptions, finallistSize );
		if( finallistSize < 1 ) { parser->setError( "maximum number of possible pseudoknotted helices" ); }
	}

	// Get the single strand offset file option.
	if( !parser->isError() ) { singleOffsetFile = parser->getOptionString( singleOffsetOptions, true ); }
	
	// Get the window size option for outputted structures.
	if( !parser->isError() ) {
		parser->setOptionInteger( OUTwindowOptions, OutWindowSize );
		if( OutWindowSize < 0 ) { parser->setError( "window size" ); }
	}
	//Record if the windowOption was set
	ifWindowOptions=parser->contains(OUTwindowOptions);
	
	// Delete the parser and return whether the parser encountered an error.
	bool noError = ( parser->isError() == false );
	delete parser;
	return noError;
}
コード例 #10
0
ファイル: refold.cpp プロジェクト: franfyh/structureanalysis
///////////////////////////////////////////////////////////////////////////////
// Parse the command line arguments.
///////////////////////////////////////////////////////////////////////////////
bool refold::parse( int argc, char** argv ) {

	// Create the command line parser and build in its required parameters.
	ParseCommandLine* parser = new ParseCommandLine( "refold" );
	parser->addParameterDescription( "save file", "The name of a folding save file that contains structure data." );
	parser->addParameterDescription( "ct file", "The name of a CT file to which output will be written." );

	// Add the maximum number of structures option.
	vector<string> maxStructuresOptions;
	maxStructuresOptions.push_back( "-m" );
	maxStructuresOptions.push_back( "-M" );
	maxStructuresOptions.push_back( "--maximum" );
	parser->addOptionFlagsWithParameters( maxStructuresOptions, "Specify a maximum number of structures. Default is 20 structures." );

	// Add the percent energy difference option.
	vector<string> percentOptions;
	percentOptions.push_back( "-p" );
	percentOptions.push_back( "-P" );
	percentOptions.push_back( "--percent" );
	parser->addOptionFlagsWithParameters( percentOptions, "Specify a maximum percent energy difference. Default is 10 percent (specified as 10, not 0.1)." );

	// Add the window size option.
	vector<string> windowOptions;
	windowOptions.push_back( "-w" );
	windowOptions.push_back( "-W" );
	windowOptions.push_back( "--window" );
	parser->addOptionFlagsWithParameters( windowOptions, "Specify a window size. Default is determined by the length of the sequence." );

	// Parse the command line into pieces.
	parser->parseLine( argc, argv );

	// Get required parameters from the parser.
	if( !parser->isError() ) {
		saveFile = parser->getParameter( 1 );
		ctFile = parser->getParameter( 2 );
	}

	// Get the maximum number of structures option.
	if( !parser->isError() ) {
		parser->setOptionInteger( maxStructuresOptions, maxStructures );
		if( maxStructures <= 0 ) { parser->setError( "maximum number of structures" ); }
	}

	// Get the percent energy difference option.
	if( !parser->isError() ) {
		parser->setOptionDouble( percentOptions, percent );
		if( percent < 0 ) { parser->setError( "percent energy difference" ); }
	}

	// Get the window size option.
	if( !parser->isError() ) {
		parser->setOptionInteger( windowOptions, windowSize );
		bool badWindowSize =
		  ( windowSize < 0 ) &&
		  ( windowSize != -1 );
		if( badWindowSize ) { parser->setError( "window size" ); }
	}

	// Delete the parser and return whether the parser encountered an error.
	bool noError = ( parser->isError() == false );
	delete parser;
	return noError;
}
コード例 #11
0
///////////////////////////////////////////////////////////////////////////////
// Parse the command line arguments.
///////////////////////////////////////////////////////////////////////////////
bool DuplexFold::parse( int argc, char** argv ) {

	// Create the command line parser and build in its required parameters.
	ParseCommandLine* parser = new ParseCommandLine( "DuplexFold" );
	parser->addParameterDescription( "seq file 1", "The name of a file containing a first input sequence." );
	parser->addParameterDescription( "seq file 2", "The name of a file containing a second input sequence." );
	parser->addParameterDescription( "ct file", "The name of a CT file to which output will be written." );

	// Add the DNA option.
	vector<string> dnaOptions;
	dnaOptions.push_back( "-d" );
	dnaOptions.push_back( "-D" );
	dnaOptions.push_back( "--DNA" );
	parser->addOptionFlagsNoParameters( dnaOptions, "Specify that the sequence is DNA, and DNA parameters are to be used. Default is to use RNA parameters." );

	// Add the maximum loop size option.
	vector<string> loopOptions;
	loopOptions.push_back( "-l" );
	loopOptions.push_back( "-L" );
	loopOptions.push_back( "--loop" );
	parser->addOptionFlagsWithParameters( loopOptions, "Specify a maximum internal/bulge loop size. Default is 6 unpaired numcleotides." );

	// Add the maximum number of structures option.
	vector<string> maxStructuresOptions;
	maxStructuresOptions.push_back( "-m" );
	maxStructuresOptions.push_back( "-M" );
	maxStructuresOptions.push_back( "--maximum" );
	parser->addOptionFlagsWithParameters( maxStructuresOptions, "Specify a maximum number of structures. Default is 10 structures." );

	// Add the percent energy difference option.
	vector<string> percentOptions;
	percentOptions.push_back( "-p" );
	percentOptions.push_back( "-P" );
	percentOptions.push_back( "--percent" );
	parser->addOptionFlagsWithParameters( percentOptions, "Specify a maximum percent energy difference. Default is 40 percent (specified as 40, not 0.4)." );

	// Add the temperature option.
	vector<string> tempOptions;
	tempOptions.push_back( "-t" );
	tempOptions.push_back( "-T" );
	tempOptions.push_back( "--temperature" );
	parser->addOptionFlagsWithParameters( tempOptions, "Specify the temperature at which calculation takes place in Kelvin. Default is 310.15 K, which is 37 degrees C." );

	// Add the window size option.
	vector<string> windowOptions;
	windowOptions.push_back( "-w" );
	windowOptions.push_back( "-W" );
	windowOptions.push_back( "--window" );
	parser->addOptionFlagsWithParameters( windowOptions, "Specify a window size. Default is 0 nucleotides." );

	// Parse the command line into pieces.
	parser->parseLine( argc, argv );

	// Get required parameters from the parser.
	if( !parser->isError() ) {
		seqFile1 = parser->getParameter( 1 );
		seqFile2 = parser->getParameter( 2 );
		ctFile = parser->getParameter( 3 );
	}

	// Get the DNA option.
	if( !parser->isError() ) { isRNA = !parser->contains( dnaOptions ); }

	// Get the maximum loop size option.
	if( !parser->isError() ) {
		parser->setOptionInteger( loopOptions, maxLoop );
		if( maxLoop < 0 ) { parser->setError( "maximum loop size" ); }
	}

	// Get the maximum number of structures option.
	if( !parser->isError() ) {
		parser->setOptionInteger( maxStructuresOptions, maxStructures );
		if( maxStructures <= 0 ) { parser->setError( "maximum number of structures" ); }
	}

	// Get the percent energy difference option.
	if( !parser->isError() ) {
		parser->setOptionDouble( percentOptions, percent );
		if( percent < 0 ) { parser->setError( "percent energy difference" ); }
	}

	// Get the temperature option.
	if( !parser->isError() ) {
		parser->setOptionDouble( tempOptions, temperature );
		if( temperature < 0 ) { parser->setError( "temperature" ); }
	}

	// Get the window size option.
	if( !parser->isError() ) {
		parser->setOptionInteger( windowOptions, windowSize );
		if( windowSize < 0 ) { parser->setError( "window size" ); }
	}

	// Delete the parser and return whether the parser encountered an error.
	bool noError = ( parser->isError() == false );
	delete parser;
	return noError;
}
コード例 #12
0
ファイル: AllSub.cpp プロジェクト: DasLab/BPPalign
///////////////////////////////////////////////////////////////////////////////
// Parse the command line arguments.
///////////////////////////////////////////////////////////////////////////////
bool AllSub::parse( int argc, char** argv ) {

  // Initialize arrays of flags without and with parameters.
  const char* flagsNoParams[] = {
    "-d", "-D", "--DNA"
  };

  const char* flagsParams[] = {
    "-a", "-A", "--absolute",
    "-c", "-C", "--constraint",
    "-p", "-P", "--percent",
    "-t", "-T", "--temperature"
  };

  // Initialize usage string.
  string usageString =
    "USAGE: AllSub <seq file> <ct file> [options]";

  // Initialize required parameters string.
  string seqHelp = "\
<seq file>\n\
     The name of a file containing an input sequence.\
";

  string ctHelp = "\
<ct file>\n\
     The name of a CT file to which output will be written.\
";

  string paramsString =
    seqHelp + "\n\n" + ctHelp;

  // Initialize flags without parameters string.
  string dnaHelp = "\
-d, -D, --DNA\n\
     Specify that the sequence is DNA, and DNA parameters are to be used.\n\
     Default is to use RNA parameters.\
";

  string helpLabel = "\
-h, -H, --help\n\
     Display the usage details message.\
";

  string flagsNoParamsString =
    dnaHelp + "\n\n" + helpLabel;

  // Initialize flags with parameters string.
  string absoluteHelp = "\
-a, -A, --absolute\n\
     Specify a maximum absolute energy difference.\n\
     Default is determined by the length of the sequence.\
";

  string constraintHelp = "\
-c, -C, --constraint\n\
     Specify a constraints file to be applied.\n\
     Default is to have no constraints applied.\
";

  string percentHelp = "\
-p, -P, --percent\n\
     Specify a maximum percent energy difference.\n\
     Default is determined by the length of the sequence.\
";

  string tempHelp = "\
-t, -T, --temperature\n\
     Specify the temperature at which calculation takes place in Kelvin.\n\
     Default is 310.15 K, which is 37 degrees C.\
";

  string flagsParamsString = 
    absoluteHelp + "\n\n" + constraintHelp + "\n\n" + percentHelp + "\n\n" +
    tempHelp; 

  // Initialize parser and check the command line.
  ParseCommandLine* parser = new ParseCommandLine( argc, argv, 2,
						   3, flagsNoParams,
						   12, flagsParams );
  parser->setUsageStrings( usageString.c_str(), paramsString.c_str(),
			   flagsNoParamsString.c_str(),
			   flagsParamsString.c_str() );
  bool noError = parser->checkLine();

  // If command line structure is OK, proceed with argument retrieval, parsing.
  if( noError ) {

    // Get required parameters.
    seqFile = parser->getParameter( 1 );
    ctFile = parser->getParameter( 2 );

    // Set non-parameterized flag(s).
    isRNA = !parser->containsInGroup( "-d -D --DNA" );

    // Set parameterized options
    // If one of these options is not found on the command line, the action to
    // set that option is skipped.
    // If one throws an error, an error message is shown and parsing continues,
    // so all errors are shown if there are more than one.
    bool flagSet = true;

    // Absolute energy difference option
    flagSet = 
      parser->setOption( absolute, "-a -A --absolute",
			 "Invalid absolute energy difference given.", ">= 0" );
    if( flagSet == false ) { noError = false; }

    // Constraint file option
    const char* constraintString = "";
    flagSet = parser->setOption( constraintString, "-c -C --constraint",
				 "Constraint file not found.", true );
    constraintFile = constraintString;
    if( flagSet == false ) { noError = false; }

    // Percent difference option
    flagSet = parser->setOption( percent, "-p -P --percent",
				 "Invalid percent difference given.", ">= 0" );
    if( flagSet == false ) { noError = false; }

    // Temperature option
    flagSet = parser->setOption( temperature, "-t -T --temperature",
				 "Invalid temperature given.", ">= 0" );
    if( flagSet == false ) { noError = false; }
  }

  // Delete the parser and return the error state.
  delete parser;
  return noError;

}