Esempio n. 1
0
///////////////////////////////////////////////////////////////////////////////
// Run calculations.
///////////////////////////////////////////////////////////////////////////////
void EnergyPlot::run() {

	/*
	 * Make sure the dot plot data can be accessed.
	 */

	// Print a message that says the dot plot data file is being checked.
	cout << "Checking dot plot input file..." << flush;

	// Initialize the dot plot handler and an error string.
	DotPlotHandler* plotHandler = 0;
	string error = "";

	// Create the RNA strand that holds the dot plot data.
	RNA* strand = new RNA( inputFile.c_str(), 4 );
	ErrorChecker<RNA>* checker = new ErrorChecker<RNA>( strand );
	error = checker->returnError();
	if( error == "" ) { cout << "done." << endl; }

	/*
	 * Prepare the dot plot data.
	 */

	if( error == "" ) {

		// Print a message saying that the dot plot data is being prepared.
		cout << "Preparing dot plot data..." << flush;

		// Build the dot plot handler using the strand's sequence length.
		int length = strand->GetSequenceLength();
		plotHandler = new DotPlotHandler( descriptionSettings.getDescription(inputFile, true), length );

		// Add all possible dots to the dot plot.
		for( int i = 1; i <= length; i++ ) {
			for( int j = i; j <= length; j++ ) {
				double energy = strand->GetPairEnergy( i, j );
				if( energy > 0.0 ) { energy = numeric_limits<double>::infinity(); }
				else {
					stringstream stream( stringstream::in | stringstream::out );
					stream << fixed << setprecision( 1 ) << energy;
					stream >> energy;
				}
				plotHandler->addDotValue( i, j, energy );
			}
		}

		// Print a message saying that the dot plot data has been prepared.
		cout << "done." << endl;
	}
//fetch each attribute, error checking, build rowobject
//input: string of row from csv, colindex for data type
Teach_rowObject TeachingRowBuilder::buildRow(string data, ColIndex index){
   
    //*** instantiate classes that will help out in this function
    AttributeRetriever fetch(data);
    bool hasError = 0; //Set this to 1 if an error is found
    ErrorChecker filter;
    bool enableErrorChecking (1);
    
    //*** retrieve each attribute - temporarily store them
    
    string name = fetch.getAttribute(index.name_loc);
    string domain = fetch.getAttribute(index.domain_loc);
    string program = fetch.getAttribute(index.program_loc);
    string courseType = fetch.getAttribute(index.courseType_loc);
    string geoScope = fetch.getAttribute(index.geoScope_loc);
    string title = fetch.getAttribute(index.title_loc);
    
    int sDate = fetch.getIntAttribute(index.sDate_loc);
    int eDate = fetch.getIntAttribute(index.eDate_loc);
    int nTeach = fetch.getIntAttribute(index.nTeach_loc);
    int tStudents = fetch.getIntAttribute(index.tStudents_loc);
    
    float hpTeach = fetch.getIntAttribute(index.hpTeach_loc);
    float tHours = fetch.getIntAttribute(index.tHours_loc);
    
    //*** check for errors
    if (enableErrorChecking){
    
        //strings - check for blank entries
        name = filter.blankCatch(name, hasError);
        domain = filter.blankCatch(domain, hasError);
        program = filter.blankCatch(program, hasError);
        courseType = filter.blankCatch(courseType, hasError);
        
        //dates, check for zeroes
        sDate = filter.zeroCatch(sDate, hasError);
        eDate = filter.zeroCatch(eDate, hasError);
        hpTeach = filter.zeroCatch(hpTeach, hasError);
        tHours = filter.zeroCatch(tHours, hasError);
        
    }
    
    
    //*** Build Row
    Teach_rowObject currentRow (hasError, name, domain, program, courseType, geoScope, nTeach, sDate, eDate, hpTeach, tHours, tStudents);
    
    return currentRow;
};
Esempio n. 3
0
///////////////////////////////////////////////////////////////////////////////
// Run calculations.
///////////////////////////////////////////////////////////////////////////////
void efn2Interface::run() {

	// Create a variable that handles errors.
	int error = 0;

	/*
	 * Use the constructor for RNA that specifies a filename.
	 * Specify type = 1 (CT file).
	 * isRNA identifies whether the strand is RNA (true) or DNA (false).
	 *
	 * After construction of the strand data structure, create the error checker which monitors for errors.  
	 * Throughout, the error status of the calculation is checked with a variant of the isErrorStatus method, which returns 0 if no error occurred.
	 * The calculation proceeds as long as error = 0.
	 */
	cout << "Initializing nucleic acids..." << flush;
	RNA* strand = new RNA( ctFile.c_str(), 1, isRNA );
	ErrorChecker<RNA>* checker = new ErrorChecker<RNA>( strand );
	error = checker->isErrorStatus();
	if( error == 0 ) { cout << "done." << endl; }

	/*
	 * Check the strand for pseudoknots by looking through each structure with the ContainsPseudoknot method.
	 * efn2 cannot handle pseudoknots, so if the strand contains pseudoknots, this is considered an error.
	 */
	if( error == 0 ) {
		structures = strand->GetStructureNumber();
		for( int i = 1; i <= structures; i++ ) {
			if( strand->ContainsPseudoknot( i ) ) {
				cerr << "Nucleic acids contain pseudoknots; cannot proceed." << endl;
				error = -1;
			}
		}
	}

	/*
	 * Set the temperature using the SetTemperature method.
	 * Only set the temperature if a given temperature doesn't equal the default.
	 * If the temperature does need to be set, use the error checker's isErrorStatus method to check for errors.
	 */
	if( ( error == 0 ) && ( temperature != 310.15 ) ) {

		// Show a message saying that the temperature is being set.
		cout << "Setting temperature..." << flush;

		// Set the temperature and check for errors.
		int tempError = strand->SetTemperature( temperature );
		error = checker->isErrorStatus( tempError );

		// If no error occurred, print a message saying that temperature is set.
		if( error == 0 ) { cout << "done." << endl; }
	}

	/*
	 * Read SHAPE constraints, if applicable.
	 * When reading SHAPE constraints, use the ReadSHAPE method.
	 * After constraints are read, use the error checker's isErrorStatus method to check for errors.
	 */
	if( error == 0 && SHAPEFile != "" ) {

		// Show a message saying that SHAPE constraints are being read.
		cout << "Applying SHAPE constraints..." << flush;

		// Initialize the single stranded SHAPE slope and intercept.
		// For now, these are hard-coded as 0.
		double slopeSingle = 0;
		double interceptSingle = 0;

		// Read SHAPE constraints and check for errors.
		int constraintError = strand->ReadSHAPE( SHAPEFile.c_str(), slope, intercept, slopeSingle, interceptSingle );
		error = checker->isErrorStatus( constraintError );

		// If no error occurred, print a message saying that SHAPE constraints are set.
		if( error == 0 ) { cout << "done." << endl; }
	}

	/*
	 * Do the efn2 calculation.
	 * If the user wants a simple output file, get free energies for each structure using the CalculateFreeEnergy method.
	 * If the user wants a thermodynamic details file, write the file with the WriteThemodynamicDetails method.
	 */
	if( error == 0 ) {

		// Write a thermodynamic details file, if asked.
		if( writeTherm ) {

			// Show a message saying that the details file is being written.
			cout << "Writing thermodynamic details file..." << flush;

			// Write the thermodynamic details file and check for errors.
			int thermError = strand->WriteThermodynamicDetails( outFile.c_str() );
			error = checker->isErrorStatus( thermError );

			// Print a message saying that the details file has been written.
			if( error == 0 ) { cout << "done." << endl; }
		}

		// Write a simple list file, if asked.
		else {

			// Show a message saying that the list file is being written.
			cout << "Writing free energy list file..." << flush;

			// For each structure, calculate its energy and push it into the energies vector.
			// Changed this 5-14-2013, no longer pushes into a vector. Instead use calculatefreeenergy method from RNA class.
			// This is so it works with openMP -- vector would be filled out of order when loop runs in parallel and the indexing would be messed up.
			// If an error occurs, set it.
			//vector<double> energies;
			strand->CalculateFreeEnergy( 1 , simple );			//calculate the free energy of the first structure first (this is to make it play well with openMP)			
			#ifdef SMP
			#pragma omp parallel for
			#endif
			for( int i = 2; i <= structures; i++ ) { 
				strand->CalculateFreeEnergy( i , simple ); 		//now calculate the free energy of the remaining structures
				error = checker->isErrorStatus();
				//if( error == 0 ) { energies.push_back( energy ); }
				//else break;
			}

			// If all free energies were calculated correctly, write the output file.
			if( error == 0 ) {
				ofstream out( outFile.c_str() );
				for( int i = 1; i <= structures; i++ ) {
					int index = i - 1;
					out << "Structure: " << i << "   Energy = " << fixed << setprecision( 1 ) << strand->GetFreeEnergy(i)  << endl; //changed to GetFreeEnergy instead of writing the energies vector
				}
				out.close();
			}

			// Print a message saying that the list file has been written.
			if( error == 0 ) { cout << "done." << endl; }

			// If the output should be piped to standard output, then pipe it.
                        if( ( error == 0 ) && ( stdPrint ) ) {
                          cout << endl << "Generated output file: " << outFile << endl << endl;
                          for( int i = 1; i <= structures; i++ ) {
	                          cout << "Structure: " << i << "   Energy = " << fixed << setprecision( 1 ) << strand->GetFreeEnergy(i) << endl;
			  }
                          cout << endl;
                        }
		}
	}

	// Delete the error checker and data structure.
	delete checker;
	delete strand;

	// Print confirmation of run finishing.
	if( error == 0 ) { cout << calcType << " complete." << endl; }
	else { cerr << calcType << " complete with errors." << endl; }
}
///////////////////////////////////////////////////////////////////////////////
// Read base pair probabilities from a partition function save file.
///////////////////////////////////////////////////////////////////////////////
void Postscript_Annotation_Handler::readPartition( string file,
						   RNA* structureStrand ) {

  // Initialize the RNA strand and error checker that reads partition data.
  RNA* partStrand = new RNA( file.c_str(), PFS_TYPE );
  ErrorChecker<RNA>* partChecker = new ErrorChecker<RNA>( partStrand );

  // If the RNA strand and error checker were created successfully, read in the
  // annotation data.
  if( !( error = partChecker->isErrorStatus() ) ) {

    // If there are no structures in the strand, print out an error message.
    // Otherwise, initialize the annotation array to handle the appropriate
    // amount of structures.
    if( structures == 0 ) {
      cerr << "No structures or pairs are present to annotate." << endl;
      error = true;
    } else {
      probabilityAnnotations.resize( structures );
      for( int i = 1; i <= structures; i++ ) {
	vector<char> row;
	row.resize( length );
	for( int j = 1; j <= length; j++ ) { row[j-1] = 'i'; }
	probabilityAnnotations[i - 1] = row;
      }
    }

    // For each structure possible, read in its base pair probability data.
    for( int i = 1; i <= structures; i++ ) {

      // If an error has occurred, stop reading data.
      if( error ) { break; }

      // Loop through the structure to find pairs.
      for( int j = 1; j <= length; j++ ) {

	// If an error has occurred, stop reading data.
	if( error ) { break; }

	// Get the next pair. If an error occurred, stop reading data.
	int pair = structureStrand->GetPair( j, i );
	int code = structureStrand->GetErrorCode();
	if( code != 0 ) {
	  cerr << endl << structureStrand->GetErrorMessage( code ) << endl;
	  error = true;
	  break;
	}

	// If the next nucleotide is in fact paired, determine the proper
	// color code for it.
	if( ( pair != 0 ) && ( pair > j ) ) {

	  // Get the probability for this pair.
	  // If an error occurred, stop reading data.
	  double bp = partStrand->GetPairProbability( j, pair );
	  if( ( error = partChecker->isErrorStatus() ) ) { break; }

	  // Set the proper values for the color code.
	  probabilityAnnotations[i-1][j-1] =
	    ( bp >= 0.99 ) ? 'a' :
	    ( bp > 0.95 ) ? 'b' :
	    ( bp > 0.90 ) ? 'c' :
	    ( bp > 0.80 ) ? 'd' :
	    ( bp > 0.70 ) ? 'e' :
	    ( bp > 0.60 ) ? 'f' :
	    ( bp > 0.50 ) ? 'g' :
	    'h';

	  probabilityAnnotations[i-1][pair-1] =
	    probabilityAnnotations[i-1][j-1];
	}
      }
    }
  }

  // If an error occurred, print out an extra error message to make sure the
  // user knows the error came from reading the partition function annotation
  // file in.
  if( error ) {
    cerr << "Partition function save file not read successfully." << endl;
  }

  // Delete the RNA strand and error checker when they're no longer needed.
  delete partStrand;
  delete partChecker;

}
///////////////////////////////////////////////////////////////////////////////
// Run calculations.
///////////////////////////////////////////////////////////////////////////////
void Multilign_Interface::run() {

	/*
	 * Rearrange the files vectors so they're organized by sequence number, not by file type.
	 * This is done behind the scenes; no progress message is necessary here.
	 */

	vector< vector<string> > matrix;
	vector<string> filesSeq = files[0];
	vector<string> filesCT = files[1];
	vector<string> filesConstraint = files[2];
	vector<string> filesSHAPE = files[3];
	for( int i = 1; i <= seqNumber; i++ ) {
		vector<string> row;
		row.push_back( filesSeq[i-1] );
		row.push_back( filesCT[i-1] );
		row.push_back( filesConstraint[i-1] );
		row.push_back( filesSHAPE[i-1] );
		matrix.push_back( row );
	}

	// Create a variable that handles errors.
	int error = 0;

	/*
	 * Use the constructor for Multilign_object that specifies a matrix of file names and a nucleic acid type.
	 * This allows for many varied sequence files to be used as input.
	 *
	 * After construction of the data structure, create the error checker which monitors for errors.  
	 * Throughout, the error status of the calculation is checked with a variant of the isErrorStatus method, which returns 0 if no error occurred.
	 * The calculation proceeds as long as error = 0.
	 */
	cout << "Initializing nucleic acids..." << flush;
	Multilign_object* object = new Multilign_object( matrix, isRNA );
	ErrorChecker<Multilign_object>* checker = new ErrorChecker<Multilign_object>( object );
	error = checker->isErrorStatus();
	if( error == 0 ) { cout << "done." << endl; }

	/*
	 * Set the temperature using the SetTemperature method.
	 * Only set the temperature if a given temperature doesn't equal the default.
	 * If the temperature does need to be set, use the error checker's isErrorStatus method to check for errors.
	 */
	if( ( error == 0 ) && ( temperature != 310.15 ) ) {

		// Show a message saying that the temperature is being set.
		cout << "Setting temperature..." << flush;

		// Set the temperature and check for errors.
		object->SetTemperature( temperature );
		error = checker->isErrorStatus();

		// If no error occurred, print a message saying that temperature is set.
		if( error == 0 ) { cout << "done." << endl; }
	}

	/*
	 * Randomize the sequences using the Randomize method.
	 */
	if( ( error == 0 ) && ( random == true ) ) {

		// Show a message saying that randomization has started.
		cout << "Randomizing sequences..." << flush;

		// Randomize sequences.
		// No error can be thrown from this method.
		object->Randomize();

		// Print a message saying that randomization is done.
		cout << "done." << endl;
	}

	/*
	 * Set the index sequence using the SetIndexSeq method.
	 * Only set the index sequence if the given index sequence is not 1.
	 * After setting the index sequence, use the error checker's isErrorStatus method to check for errors.
	 */
	if( ( error == 0 ) && indexSeq != 1 ) {

		// Show a message saying that index sequence setting has started.
		cout << "Setting index sequence..." << flush;

		// Set the index sequence and check for errors.
		int seqError = object->SetIndexSeq( indexSeq );
		error = checker->isErrorStatus( seqError );

		// If no error occurred, print a message saying that sequence setting is done.
		if( error == 0 ) { cout << "done." << endl; }
	}

	/*
	 * Set the iterations using the SetIterations method.
	 */
	if( ( error == 0 ) && ( iterations != 2 ) ) {

		// Show a message saying that iteration setting has started.
		cout << "Setting iterations..." << flush;

		// Set iterations.
		int itError = object->SetIterations( iterations );
		error = checker->isErrorStatus( itError );

		// If no error occurred, print a message saying that iteration setting
		// is done.
		if( error == 0 ) { cout << "done." << endl; }
	}

	/*
	 * Set a maxdsvchange using the SetMaxDsv method.
	 */
	if( ( error == 0 ) && ( maxDsvChange != 1 ) ) {

		// Show a message saying that max DSV change setting has started.
		cout << "Setting max DSV change..." << flush;

		// Set max DSV change.
		int dsvError = object->SetMaxDsv( maxDsvChange );
		error = checker->isErrorStatus( dsvError );

		// If no error occurred, print a message saying that max dsv change setting is done.
		if( error == 0 ) { cout << "done." << endl; }
	}

	/*
	 * Set max pairs using the SetMaxPairs method.
	 */
	if( ( error == 0 ) && ( maxPairs != -1 ) ) {

		// Show a message saying that max pairs setting has started.
		cout << "Setting max pairs..." << flush;

		// Set max pairs.
		int pairsError = object->SetMaxPairs( maxPairs );
		error = checker->isErrorStatus( pairsError );

		// If no error occurred, print a message saying that max pairs setting is done.
		if( error == 0 ) { cout << "done." << endl; }
	}

	/**
	 * Set SHAPE data using the SetSHAPEIntercept and SetSHAPESlope method.
	 * Only do this if SHAPE data has been read.
	 */
	if( ( error == 0 ) && ( hasSHAPE == true ) ) {

		// Show a message saying that SHAPE parameter setting has started.
		cout << "Setting SHAPE parameters..." << flush;

		// Set SHAPE parameters.
		object->SetSHAPEIntercept( intercept );
		object->SetSHAPESlope( slope );

		// If no error occurred, print a message saying that SHAPE parameter setting is done.
		cout << "done." << endl;
	}

	/*
	 * Run the Multilign algorithm using the ProgressiveMultilign method.
	 * During calculation, monitor progress using the TProgressDialog class and the Start/StopProgress methods of the RNA class.
	 * Neither of these methods require any error checking.
	 * After the main calculation is complete, use the error checker's isErrorStatus method to check for errors.
	 */
	if( error == 0 ) {

		// Show a message saying that the main calculation has started.
		cout << "Folding nucleic acids..." << endl;

		// Create the progress monitor.
		TProgressDialog* progress = new TProgressDialog();
		object->SetProgress( progress );

		// Run the Multilign algorithm and check for errors.
		int mainCalcError = object->ProgressiveMultilign(
			processors, true, true, maxStructures, basepairWindow,
			alignmentWindow, percent, maxSeparation, gap, inserts,
			percentSingle, local );
		error = checker->isErrorStatus( mainCalcError );

		// Delete the progress monitor.
		object->StopProgress();
		delete progress;

		// If no error occurred, print a message saying that the main calculation is done.
		if( error == 0 ) { cout << "done." << endl; }
	}

	/*
	 * Write the alignment file using the WriteAlignment method.
	 * After writing is complete, use the error checker's isErrorStatus method to check for errors.
	 */
	if( error == 0 ) {

		// Show a message saying that the alignment file is being written.
		cout << "Writing multiple alignment file..." << flush;

		// Write the alignment file and check for errors.
		int writeError = object->WriteAlignment( alignmentFile );
		error = checker->isErrorStatus( writeError );

		// If no errors occurred, print a message saying that alignment file writing is done.
		if( error == 0 ) { cout << "done." << endl; }
	}

	/*
	 * If requested by the user, clean up the intermediate files created by Multilign using the CleanupIntermediateFiles method.
	 * After files are cleaned up, use the error checker's isErrorStatus method to check for errors.
	 */
	if( keepIntermediate == false ) {
		int cleanupError = object->CleanupIntermediateFiles();
		error = checker->isErrorStatus( cleanupError );
	}

	// Delete the error checker and data structure.
	delete checker;
	delete object;

	// Print confirmation of run finishing.
	if( error == 0 ) { cout << calcType << " complete." << endl; }
	else { cerr << calcType << " complete with errors." << endl; }
}
///////////////////////////////////////////////////////////////////////////////
// Run calculations.
///////////////////////////////////////////////////////////////////////////////
void DrawStructure::run() {

    // Create a variable that tracks the result of calculations.
    // Throughout, the calculation continues if result = "".
    string result = "";

    // Create variables to determine the range of structures that will be drawn.
    // Initialize them so the range of structures will only be the specific structure given, if any.
    int start = number;
    int end = number;

    // Create a temporary strand for the purpose of determining the number and range of structures to be drawn.
    int structures = 0;
    if( result == "" ) {

        // Show a message that the information gathering phase has begun.
        cout << "Determining structure information..." << flush;

        // Create the temporary strand to get the number of structures, then delete it.
        RNA* strand = new RNA( inputFile.c_str(), 1 );
        ErrorChecker<RNA>* checker = new ErrorChecker<RNA>( strand );
        result = checker->returnError();
        structures = strand->GetStructureNumber();
        delete strand;
        delete checker;

        // Use the number of structures to determine if the user gave an appropriate specific structure value, if necessary.
        // If the structure value is invalid, set the error string to show this.
        if( result == "" ) {
            if( number != -1 && !( number >= 1 && number <= structures ) ) {
                result = "Structure number out of range.\n";
            }
        }

        // If the user did not give a specific structure, set the range of structures to all possible structures.
        if( number == -1 ) {
            start = 1;
            end = structures;
        }

        // If no error occurred, print a message saying that the information gathering phase is done.
        // Otherwise, print the error message.
        if( result == "" ) {
            cout << "done." << endl;
        }
        else {
            cerr << endl << result;
        }
    }

    // If no errors have occurred in structure preparation, draw the structure(s).
    if( result == "" ) {

        // Print a message saying that the drawing phase has started.
        cout << "Drawing..." << endl;

        // If the output file already exists, delete the file so a new file with that name can be generated.
        ifstream test( outputFile.c_str() );
        bool exists = test.good();
        test.close();
        if( exists ) {
            remove( outputFile.c_str() );
        }

        // For each structure in the range, get its data and draw it appropriately.
        for( int i = start; i <= end; i++ ) {

            // Print a message saying that a particular structure has started drawing.
            cout << "    Drawing structure " << i << "..." << flush;

            // Create the drawing handler and set whether it should circle nucleotides.
            StructureImageHandler* handler = new StructureImageHandler();
            handler->setNucleotidesCircled( encircle );

            // Read in the structure.
            // Note that if a pseudoknotted structure is fed to the radial routine, the radial routine automatically calls the circular routine.
            if( result == "" ) {
                if( circular ) {
                    result = handler->readCircular( inputFile, i );
                }
                else if( flat ) {
                    result = handler->readLinear( inputFile, i );
                }
                else {
                    handler->readRadial( inputFile, i );
                }
            }

            // Read in annotation, if necessary.
            if( result == "" ) {
                if( probabilityFile != "" ) {
                    result = handler->addAnnotationProbability( probabilityFile, textAnnotation );
                } else if( SHAPEFile != "" ) {
                    result = handler->addAnnotationSHAPE( SHAPEFile );
                }
            }

            // Flip the structure, if asked.
            if( ( result == "" ) && ( levorotatory == true ) ) {
                handler->flipHorizontally();
            }

            // Write the structure image, as either SVG or Postscript.
            if( result == "" ) {
                if( isSVG ) {
                    handler->writeSVG( outputFile );
                }
                else {
                    bool append = ( number == -1 );
                    if( i == start ) {
                        ifstream test( outputFile.c_str() );
                        if( test ) {
                            append = false;
                        }
                    }
                    handler->writePostscript( outputFile, append );
                }
            }

            // Delete the drawing handler.
            delete handler;

            // Print a message saying that a particular structure has finished drawing, if no error occurred.
            // If an error did occur, break out of the loop.
            if( result == "" ) {
                cout << "done." << endl;
            }
            else break;
        }

        // If no error occurred, print a message saying that the drawing phase is done.
        // Otherwise, print the error message.
        if( result == "" ) {
            cout << "done." << endl;
        }
        else {
            cerr << endl << result << endl;
        }
    }

    // Print confirmation of run finishing.
    if( result == "" ) {
        cout << calcType << " complete." << endl;
    }
    else {
        cerr << calcType << " complete with errors." << endl;
    }

}
///////////////////////////////////////////////////////////////////////////////
// Run calculations.
///////////////////////////////////////////////////////////////////////////////
void TurboFold_Interface::run() {

	// Create a variable that handles errors.
	int error = 0;

	/*
	 * Use the constructor for TurboFold_object that specifies vectors of file names.
	 * This allows for many varied sequence files to be used as input.
	 *
	 * After construction of the data structure, create the error checker which monitors for errors.
	 * Throughout, the error status of the calculation is checked with a variant of the isErrorStatus method, which returns 0 if no error occurred.
	 * The calculation proceeds as long as error = 0.
	 */
	cout << "Initializing nucleic acids..." << flush;
	TurboFold* object = new TurboFold( &files[0], &files[2] );
	ErrorChecker<TurboFold>* checker = new ErrorChecker<TurboFold>( object );
	error = checker->isErrorStatus();
	if( error == 0 ) { cout << "done." << endl; }

	/*
	 * Set the temperature using the SetTemperature method.
	 * Only set the temperature if a given temperature doesn't equal the default.
	 * If the temperature does need to be set, use the error checker's isErrorStatus method to check for errors.
	 */
	if( ( error == 0 ) && ( temperature != 310.15 ) ) {

		// Show a message saying that the temperature is being set.
		cout << "Setting temperature..." << flush;

		// Set the temperature and check for errors.
		int tempError = object->SetTemperature( temperature );
		error = checker->isErrorStatus( tempError );

		// If no error occurred, print a message saying temperature is set.
		if( error == 0 ) { cout << "done." << endl; }
	}

	/*
	 * Set the maximum pairing distance, if required.
	 */
	if( ( error == 0 ) && ( distance > 0 ) ) {

		// Show a message saying that maximum pairing distance is being set.
		cout << "Setting maximum pairing distance..." << flush;

		// Set the maximum pairing distance and check for errors.
		int distError = object->SetMaxPairingDistance( distance );
		error = checker->isErrorStatus( distError );

		// If no error occurred, print a message saying that maximum pairing
		// distance is set.
		if( error == 0 ) { cout << "done." << endl; }
	}

	/*
	 * Read SHAPE data where necessary for specific sequence files.
	 * Since SHAPE data must be read individually for each sequence, use the ReadSHAPE method.
	 */
	if( error == 0 && hasSHAPE ) {

		// Show a message saying SHAPE data is being read.
		cout << "Reading SHAPE data..." << flush;

		// For each sequence, read in SHAPE data, if applicable.
		for( int i = 1; i <= seqNumber; i++ ) {
			if( files[3][i-1] != "" ) {
				int shapeError = object->ReadSHAPE( i, files[3][i-1].c_str(), slope, intercept );
				if( ( error = checker->isErrorStatus( shapeError ) ) == true ) {
					i += seqNumber;
				}
			}
		}

		// Show a message saying SHAPE data reading is done.
		if( error == 0 ) { cout << "done." << endl; }
	}

	/*
	 * Run the TurboFold algorithm using the fold method.
	 * During calculation, monitor progress using the TProgressDialog class and the Start/StopProgress methods of the RNA class.
	 * Neither of these methods require any error checking.
	 * After the main calculation is complete, use the error checker's isErrorStatus method to check for errors.
	 */
	if( error == 0 ) {

		// Show a message saying that the main calculation has started.
		cout << "Folding nucleic acids..." << endl;

		// Create the progress monitor.
		TProgressDialog* progress = new TProgressDialog();
		object->SetProgress( *progress );

		// Run the TurboFold algorithm and check for errors.
		int mainCalcError = object->fold( turboGamma, turboIterations, processors );
		error = checker->isErrorStatus( mainCalcError );

		// Delete the progress monitor.
		object->StopProgress();
		delete progress;

		// If no error occurred, print message that main calculation is done.
		if( error == 0 ) { cout << "done." << endl; }
	}

	/*
	 * Resolve the structures generated by TurboFold using specific methods, depending on the mode selected for TurboFold.
	 * In MEA mode, use the MaximizeExpectedAccuracy method.
	 * In ProbKnot mode, use the ProbKnot method.
	 * In Threshold mode, use the PredictProbablePairs method.
	 * During calculation, monitor progress using the TProgressDialog class and the Start/StopProgress methods of the RNA class.
	 * Neither of these methods require any error checking.
	 * After the resolution calculation is complete, use the error checker's isErrorStatus method to check for errors.
	 */
	if( error == 0 ) {

		// Show a message saying that the resolving calculation has started.
		if( mode == "MEA" ) {
			cout << "Calculating maximum expected accuracy structures..." << flush;
		} else if( mode == "ProbKnot" ) {
			cout << "Predicting pseudoknots..." << flush;
		} else {
			cout << "Calculating probable pairs..." << flush;
		}

		// Resolve the structures and check for errors.
		for( int i = 1; i <= seqNumber; i++ ) {
			int resolveError = 0;
			if( mode == "MEA" ) {
				resolveError = object->MaximizeExpectedAccuracy( i, percent, maxStructures, windowSize, meaGamma );
			} else if( mode == "ProbKnot" ) {
				resolveError = object->ProbKnot( i, pkIterations, minHelixLength );
			} else {
				resolveError = object->PredictProbablePairs( i, threshold );
			}
			error = checker->isErrorStatus( resolveError );

			if( error != 0 ) { i += seqNumber; }
		}

		// If no error occurred, print message that resolving is done.
		if( error == 0 ) { cout << "done." << endl; }
	}

	/*
	 * Write CT output files using the WriteCt method.
	 * After writing is complete, use the error checker's isErrorStatus method to check for errors.
	 */
	if( error == 0 ) {

		// Show a message saying that the CT files are being written.
		cout << "Writing output ct files..." << flush;

		// Write the CT files and check for errors.
		for( int i = 1; i <= seqNumber; i++ ) {
			int writeError = object->WriteCt( i, files[1][i-1].c_str() );
			error = checker->isErrorStatus( writeError );
			if( error != 0 ) { i += seqNumber; }
		}

		// If no errors occurred, show a CT files writing completion message.
		if( error == 0 ) { cout << "done." << endl; }
	}

	// Delete the error checker and data structure.
	delete checker;
	delete object;

	// Print confirmation of run finishing.
	if( error == 0 ) { cout << calcType << " complete." << endl; }
	else { cerr << calcType << " complete with errors." << endl; }
}
Esempio n. 8
0
///////////////////////////////////////////////////////////////////////////////
// Run bimolecular folding calculations.
///////////////////////////////////////////////////////////////////////////////
void bifold::run() {

  // Create a variable that handles errors.
  int error = 0;

  /*
   * Use the constructor for HybridRNA that specifies two filenames and types.
   * For both sequences, specify type = 2 (sequence file).
   * isRNA identifies whether the strand is RNA (true) or DNA (false).
   *
   * After construction of the strand data structure, create the error checker
   * which monitors for errors.
   * Throughout, the error status of the calculation is checked with a variant
   * of the isErrorStatus method, which returns 0 if no error occurred. The
   * calculation proceeds as long as error = 0.
   */
  cout << "Initializing nucleic acids..." << flush;
  HybridRNA* strand =
    new HybridRNA( seqFile1.c_str(), 2, seqFile2.c_str(), 2, isRNA );
  ErrorChecker<HybridRNA>* checker = new ErrorChecker<HybridRNA>( strand );
  error = checker->isErrorStatus();
  if( error == 0 ) { cout << "done." << endl; }

  /*
   * Set the temperature using the SetTemperature method.
   * Only set the temperature if a given temperature doesn't equal the default.
   * If the temperature does need to be set, use the error checker's
   * isErrorStatus method to check for errors.
   */
  if( ( error == 0 ) && ( temperature != 310.15 ) ) {

    // Show a message saying that the temperature is being set.
    cout << "Setting temperature..." << flush;

    // Set the temperature and check for errors.
    int tempError = strand->SetTemperature( temperature );
    error = checker->isErrorStatus( tempError );

    // If no error occurred, print a message saying that temperature is set.
    if( error == 0 ) { cout << "done." << endl; }
  }

  /*
   * Set allowance or denial of intramolecular pairs using the
   * SetForbidIntramolecular method.
   * Since this method only sets a flag, error checking is not necessary.
   */
  if( error == 0 ) {
    strand->SetForbidIntramolecular( intramolecular );
  }

  /*
   * Fold the hybrid strand using the FoldBimolecular method.
   * If a save file name has been specified, the FoldBimolecular method also
   * has the ability to write a folding save file.
   * During calculation, monitor progress using the TProgressDialog class and
   * the Start/StopProgress methods of the RNA class. Neither of these methods
   * require any error checking.
   * After the main calculation is complete, use the error checker's
   * isErrorStatus method to check for errors in the main calculation.
   */
  if( error == 0 ) {

    // Show a message saying that the main calculation has started.
    cout << "Folding two strands..." << endl;

    // Create the progress monitor.
    TProgressDialog* progress = new TProgressDialog();
    strand->SetProgress( *progress );

    // Fold the hybrid strand and check for errors.
    int mainCalcError =
      strand->FoldBimolecular( percent, maxStructures, windowSize,
			       saveFile.c_str(), maxLoop );
    error = checker->isErrorStatus( mainCalcError );

    // Delete the progress monitor.
    strand->StopProgress();
    delete progress;

    // If no error occurred, print message that main calculation is done.
    if( error == 0 ) { cout << "done." << endl; }
  }

  /*
   * Write a CT output file using the WriteCt method.
   * After writing is complete, use the error checker's isErrorStatus method to
   * check for errors.
   */
  if( error == 0 ) {

    // Show a message saying that the CT file is being written.
    cout << "Writing output ct file..." << flush;

    // Write the CT file and check for errors.
    int writeError = strand->WriteCt( ctFile.c_str() );
    error = checker->isErrorStatus( writeError );

    // If no errors occurred, show a CT file writing completion message.
    if( error == 0 ) { cout << "done." << endl; }
  }

  // Delete the error checker and data structure.
  delete checker;
  delete strand;

  // Print confirmation of run finishing.
  if( error == 0 ) { cout << calcType << " complete." << endl; }
  else { cerr << calcType << " complete with errors." << endl; }

}
Esempio n. 9
0
///////////////////////////////////////////////////////////////////////////////
// Run calculations.
///////////////////////////////////////////////////////////////////////////////
void refold::run() {

	// Create a variable that handles errors.
	int error = 0;

	/*
	 * Use the constructor for RNA that specifies a filename.
	 * Specify type = 4 (folding save file).
	 * The save file handles the type of nucleic acid being folded, so it can be set as the default (RNA) in the constructor.
	 *
	 * After construction of the strand data structure, create the error checker which monitors for errors.  
	 * Throughout, the error status of the calculation is checked with a variant of the isErrorStatus method, which returns 0 if no error occurred.
	 * The calculation proceeds as long as error = 0.
	 */
	cout << "Initializing nucleic acids..." << flush;
	RNA* strand = new RNA( saveFile.c_str(), 4 );
	ErrorChecker<RNA>* checker = new ErrorChecker<RNA>( strand );
	error = checker->isErrorStatus();
	if( error == 0 ) { cout << "done." << endl; }

	/*
	 * Set the window size, based on the length of the sequence given as input.
	 * Only do this if window size hasn't been set on the command line.
	 * Use method GetSequenceLength to get the length of the sequence.
	 * The window sizes in relation to the length are hardcoded values.
	 */
	if( windowSize == -1 && error == 0 ) {
		int length = strand->GetSequenceLength();
		windowSize =
			( length > 1200 ) ? 20 :
			( length > 800 ) ? 15 :
			( length > 500 ) ? 11 :
			( length > 300 ) ? 7 :
			( length > 120 ) ? 5 :
			( length > 50 ) ? 3 :
			2;
	}

	/*
	 * Refold the regenerated strand using the ReFoldSingleStrand method.
	 * After the main calculation is complete, use the error checker's isErrorStatus method to check for errors.
	 */
	if( error == 0 ) {

		// Show a message saying that the main calculation has started.
		cout << "Refolding nucleic acids..." << flush;

		// Do the main calculation and check for errors.
		int mainCalcError = strand->ReFoldSingleStrand( percent, maxStructures, windowSize );
		error = checker->isErrorStatus( mainCalcError );

		// If no error occurred, print a message saying that the main calculation is done.
		if( error == 0 ) { cout << "done." << endl; }
	}

	/*
	 * Write a CT output file using the WriteCt method.
	 * After writing is complete, use the error checker's isErrorStatus method to check for errors.
	 */
	if( error == 0 ) {

		// Show a message saying that the CT file is being written.
		cout << "Writing output ct file..." << flush;

		// Write the CT file and check for errors.
		int writeError = strand->WriteCt( ctFile.c_str() );
		error = checker->isErrorStatus( writeError );

		// If no errors occurred, show a CT file writing completion message.
		if( error == 0 ) { cout << "done." << endl; }
	}

	// Delete the error checker and data structure.
	delete checker;
	delete strand;

	// Print confirmation of run finishing.
	if( error == 0 ) { cout << calcType << " complete." << endl; }
	else { cerr << calcType << " complete with errors." << endl; }
}
Esempio n. 10
0
///////////////////////////////////////////////////////////////////////////////
// Run calculations.
///////////////////////////////////////////////////////////////////////////////
void DuplexFold::run() {

	// Create a variable that handles errors.
	int error = 0;

	/*
	 * Use the constructor for HybridRNA that specifies two filenames and types.
	 * For both sequences, specify type = 2 (sequence file).
	 * isRNA identifies whether the strand is RNA (true) or DNA (false).
	 *
	 * After construction of the strand data structure, create the error checker which monitors for errors.
	 * Throughout, the error status of the calculation is checked with a variant of the isErrorStatus method, which returns 0 if no error occurred.
	 * The calculation proceeds as long as error = 0.
	 */
	cout << "Initializing nucleic acids..." << flush;
	HybridRNA* strand = new HybridRNA( seqFile1.c_str(), 2, seqFile2.c_str(), 2, isRNA );
	ErrorChecker<HybridRNA>* checker = new ErrorChecker<HybridRNA>( strand );
	error = checker->isErrorStatus();
	if( error == 0 ) { cout << "done." << endl; }

	/*
	 * Set the temperature using the SetTemperature method.
	 * Only set the temperature if a given temperature doesn't equal the default.
	 * If the temperature does need to be set, use the error checker's isErrorStatus method to check for errors.
	 */
	if( ( error == 0 ) && ( temperature != 310.15 ) ) {

		// Show a message saying that the temperature is being set.
		cout << "Setting temperature..." << flush;

		// Set the temperature and check for errors.
		int tempError = strand->SetTemperature( temperature );
		error = checker->isErrorStatus( tempError );

		// If no error occurred, print a message saying that temperature is set.
		if( error == 0 ) { cout << "done." << endl; }
	}

	/*
	 * Fold the hybrid strand using the FoldDuplex method.
	 * After the main calculation is complete, use the error checker's isErrorStatus method to check for errors.
	 */
	if( error == 0 ) {

		// Show a message saying that the main calculation has started.
		cout << "Folding duplex..." << endl;

		// Create the progress monitor.
		TProgressDialog* progress = new TProgressDialog();
		strand->SetProgress( *progress );

		// Do the main calculation and check for errors.
		int mainCalcError = strand->FoldDuplex( percent, maxStructures, windowSize, maxLoop );
		error = checker->isErrorStatus( mainCalcError );

		// Delete the progress monitor.
		strand->StopProgress();
		delete progress;

		// If no error occurred, print message that main calculation is done.
		if( error == 0 ) { cout << "done." << endl; }
	}

	/*
	 * Write a CT output file using the WriteCt method.
	 * After writing is complete, use the error checker's isErrorStatus method to check for errors.
	 */
	if( error == 0 ) {

		// Show a message saying that the CT file is being written.
		cout << "Writing output ct file..." << flush;

		// Write the CT file and check for errors.
		int writeError = strand->WriteCt( ctFile.c_str() );
		error = checker->isErrorStatus( writeError );

		// If no errors occurred, show a CT file writing completion message.
		if( error == 0 ) { cout << "done." << endl; }
	}

	// Delete the error checker and data structure.
	delete checker;
	delete strand;

	// Print confirmation of run finishing.
	if( error == 0 ) { cout << calcType << " complete." << endl; }
	else { cerr << calcType << " complete with errors." << endl; }
}
Esempio n. 11
0
///////////////////////////////////////////////////////////////////////////////
// Run the suboptimal structure calculations.
///////////////////////////////////////////////////////////////////////////////
void AllSub::run() {

  // Create a variable that handles errors.
  int error = 0;

  /*
   * Use the constructor for RNA that specifies a filename.
   * Specify type = 2 (sequence file).
   * isRNA identifies whether the strand is RNA (true) or DNA (false).
   *
   * After construction of the strand data structure, create the error checker
   * which monitors for errors.  
   * Throughout, the error status of the calculation is checked with a variant
   * of the isErrorStatus method, which returns 0 if no error occurred. The
   * calculation proceeds as long as error = 0.
   */
  cout << "Initializing nucleic acids..." << flush;
  RNA* strand = new RNA( seqFile.c_str(), 2, isRNA );
  ErrorChecker<RNA>* checker = new ErrorChecker<RNA>( strand );
  error = checker->isErrorStatus();
  if( error == 0 ) { cout << "done." << endl; }

  /*
   * Set the percent difference and the maximum absolute energy difference.
   * Both differences are based on the length of the sequence, and their values
   * in relation to the sequence length are hardcoded.
   * Only set these values if they were not set on the command line. As one or
   * the other of them may or may not be set, each one is checked individually.
   *
   * Get the length of the sequence using the GetSequenceLength method.
   * Since this method only returns a length, error checking is not necessary.
   */
  if( error == 0 ) {

    // Get the sequence length to identify the hardcoded thresholds.
    int length = strand->GetSequenceLength();

    // Set the maximum percent difference, if applicable.
    if( percent == -1 ) {
      percent =
	( length > 1200 ) ? 5 :
	( length > 800 ) ? 8 :
	( length > 500 ) ? 10 :
	( length > 300 ) ? 15 :
	( length > 120 ) ? 20 :
	( length > 50 ) ? 25 :
	50;
    }

    // Set the absolute energy difference, if applicable.
    if( absolute == -1 ) {
      absolute =
	( length > 1200 ) ? 0.25 :
	( length > 800 ) ? 0.5 :
	( length > 500 ) ? 0.75 :
	( length > 300 ) ? 1 :
	( length > 120 ) ? 1.5 :
	( length > 50 ) ? 3 :
	10;
    }
  }

  /*
   * Set the temperature using the SetTemperature method.
   * Only set the temperature if a given temperature doesn't equal the default.
   * If the temperature does need to be set, use the error checker's
   * isErrorStatus method to check for errors.
   */
  if( ( error == 0 ) && ( temperature != 310.15 ) ) {

    // Show a message saying that the temperature is being set.
    cout << "Setting temperature..." << flush;

    // Set the temperature and check for errors.
    int tempError = strand->SetTemperature( temperature );
    error = checker->isErrorStatus( tempError );

    // If no error occurred, print a message saying that temperature is set.
    if( error == 0 ) { cout << "done." << endl; }
  }

  /*
   * Add constraints if a file has been given for their inclusion.
   * Read in this constraints with method ReadConstraints.
   * After constraints are read, use the error checker's isErrorStatus method
   * to check for errors.
   */
  if( error == 0 && constraintFile != "" ) {

    // Show a message saying that constraints are being applied.
    cout << "Applying constraints..." << flush;

    // Apply constraints and check for errors.
    int constraintError = strand->ReadConstraints( constraintFile.c_str() );
    error = checker->isErrorStatus( constraintError );

    // If no error occurred, print a message saying constraints were included.
    if( error == 0 ) { cout << "done." << endl; }
  }

  /*
   * Generate structures using the GenerateAllSuboptimalStructures method.
   * During calculation, monitor progress using the TProgressDialog class and
   * the Start/StopProgress methods of the RNA class. Neither of these methods
   * require any error checking.
   * After the main calculation is complete, use the error checker's
   * isErrorStatus method to check for errors.
   */
  if( error == 0 ) {

    // Show a message saying that the main calculation has started.
    cout << "Generating suboptimal structures..." << endl;

    // Create the progress monitor.
    TProgressDialog* progress = new TProgressDialog();
    strand->SetProgress( *progress );

    // Generate the suboptimal structures and check for errors.
    int mainCalcError =
      strand->GenerateAllSuboptimalStructures( (float)percent, absolute );
    error = checker->isErrorStatus( mainCalcError );

    // Delete the progress monitor.
    strand->StopProgress();
    delete progress;

    // If no error occurred, print message that main calculation is done.
    if( error == 0 ) { cout << "done." << endl; }
  }

  /*
   * Write a CT output file using the WriteCt method.
   * After writing is complete, use the error checker's isErrorStatus method to
   * check for errors.
   */
  if( error == 0 ) {

    // Show a message saying that the CT file is being written.
    cout << "Writing output ct file..." << flush;

    // Write the CT file and check for errors.
    int writeError = strand->WriteCt( ctFile.c_str() );
    error = checker->isErrorStatus( writeError );

    // If no errors occurred, show a CT file writing completion message.
    if( error == 0 ) { cout << "done." << endl; }
  }

  // Delete the error checker and data structure.
  delete checker;
  delete strand;

  // Print confirmation of run finishing.
  if( error == 0 ) { cout << calcType << " complete." << endl; }
  else { cerr << calcType << " complete with errors." << endl; }

}
//fetch each object, error checking, build row
//input: raw string of row from CSV, column index for data type
//output: complete row object
Grant_rowObject GrantRowBuilder::buildRow(string data, ColIndex index){
    
    //*** instantiate classes that will help out in this function
    AttributeRetriever fetch(data);
    bool hasError = 0;//IF this row has an error in it, this flag should be set to true
    ErrorChecker filter;
    bool enableErrorChecking (1);
    
    //*** retrieve each attribute - temporarily store them
    
    string name = fetch.getAttribute(index.name_loc);
    string domain = fetch.getAttribute(index.domain_loc);
    string fundType = fetch.getAttribute(index.fundType_loc);
    string stat = fetch.getAttribute(index.stat_loc);
    string role = fetch.getAttribute(index.role_loc);
    string title = fetch.getAttribute(index.title_loc);
    string pInvestigator = fetch.getAttribute(index.pInvestigator_loc);
    
    // Deal with multiple co-investigators in a cell
    string cpInvestigator = fetch.getAttribute(index.cpInvestigator_loc);
    fetch.grabFirstString(cpInvestigator);//TEMPORARY -returns first co-investigator
    
    bool peerReviewed = fetch.getBoolAttribute(index.peerReviewed_loc);
    bool indGrant = fetch.getBoolAttribute(index.indGrant_loc);
    
    int sDate = fetch.getIntAttribute(index.sDate_loc);
    int eDate = fetch.getIntAttribute(index.eDate_loc);
    
    long long totalAmount = fetch.getLongAttribute(index.totalAmount_loc);
    
    
    //*** Error Checking
    if (enableErrorChecking){
    
        //strings - chack for blank fields
        name = filter.blankCatch(name, hasError);
        domain = filter.blankCatch(domain, hasError);
        fundType = filter.blankCatch(fundType, hasError);
        stat = filter.blankCatch(stat, hasError);
        role = filter.blankCatch(role, hasError);
        title = filter.blankCatch(title, hasError);
        pInvestigator = filter.blankCatch(pInvestigator, hasError);
        
        //PEER REVIEWED - if feild is left blank, we assume it has not been peer reviewed
        //INDUSTRY GRANT - if feild is left blank, we assume it was not an industry grant
        
        //dates - check for zeroes
        sDate = filter.zeroCatch(sDate, hasError);
        eDate = filter.zeroCatch(eDate, hasError);
        
        //Assert FundType
        string acceptable_fundTypes [2] = {"Grants","Clinical Trials"};
        fundType = filter.stringAssert(fundType, hasError, 2, acceptable_fundTypes);
        
        //Assert status
        string acceptable_statuses [5] = {"Applied","Funded","Declined","Rejected","Not Funded"};
        stat = filter.stringAssert(stat, hasError, 5, acceptable_statuses);
        
        //Assert Role
        string acceptable_Roles [8] = {"Co-Applicant","Co-Investigator","Collaborator","Co-Principal Investigator","Principal Applicant","Principal Investigator","Principal Site Investigator","Site Investigator"};
        role = filter.stringAssert(role,hasError, 8, acceptable_Roles);
        
    }
    
    //*** Build Row
    Grant_rowObject currentRow (hasError, name, domain, sDate, eDate, fundType, stat, peerReviewed,indGrant, role, title, pInvestigator, cpInvestigator, totalAmount);
    
    return currentRow;
};