コード例 #1
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;

}
コード例 #2
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;

}