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