/////////////////////////////////////////////////////////////////////////////// // 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; } }
/////////////////////////////////////////////////////////////////////////////// // 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; } }
/////////////////////////////////////////////////////////////////////////////// // 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 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; } }
/////////////////////////////////////////////////////////////////////////////// // 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; } }
/////////////////////////////////////////////////////////////////////////////// // 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; } }
/////////////////////////////////////////////////////////////////////////////// // 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; } }
/////////////////////////////////////////////////////////////////////////////// // 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; } }