Ejemplo n.º 1
0
void COmdFile0::saveWhichKindOmefile(RNA& _R)
{
//	KindOfOmd omdKind = OMD_AtYPE;
    CString str;
    for (int i = 0; i < 256; ++i)
    {
        str.Format("%d", i);
        if ((_R.Find("白","gamma",str,"0 255 255").GetSqncArea() != AA_00) ||  //有量測 = .GetMsrFlowNo() != 99
                (_R.Find("紅","gamma",str,"0 255 255").GetSqncArea() != AA_00) ||
                (_R.Find("綠","gamma",str,"0 255 255").GetSqncArea() != AA_00) ||
                (_R.Find("藍","gamma",str,"0 255 255").GetSqncArea() != AA_00))
        {
            //omdKind = OMD_GAMMA;
            m_GmOmd = new COmdFileGm();
            break;
        }
    }

    m_Omd = new COmdFile1(OMD_AtYPE);

// 	switch(omdKind)
// 	{
// 	case OMD_GAMMA: m_GmOmd = new COmdFileGm();  break;
// 	default:		m_Omd = new COmdFile1(OMD_AtYPE);
// 	}
}
Ejemplo n.º 2
0
RNA DnaConfig::add_DNA_CrossTalk(DNA& dnaTotal)
{
	DNA dnaCrossTalk;
	RNA rnaCrossTalk;

    //Cross Talk
    if (m_chkCrossTalk)
    {
        dnaCrossTalk.AddCell(CrsTlk , Pn4, m_CTFE);
        dnaCrossTalk.AddCell(CrsTlkD, Pn4, m_CTFE);
        dnaCrossTalk.AddCell(CrsTlkW, Pn4, m_CTFE);
    }

	if (dnaCrossTalk.Size()) 
	{
		Ts->Trans(dnaCrossTalk, rnaCrossTalk);
		rnaCrossTalk.SortQuackMsr();
	}

	showRNA(rnaCrossTalk);
	dnaTotal += dnaCrossTalk;

	return rnaCrossTalk;
	
}
Ejemplo n.º 3
0
int Multilign_object::get_maxpairs(int maxpairs) {
  if(maxpairs >= 0 ) return maxpairs;
  else {
    int nt=0;
    for ( size_t i = 0; i < Seq_List.size(); ++i){
      RNA *seq = new RNA(Seq_List[i].c_str(), 2);
      nt = nt + seq->GetSequenceLength();
    }
    return nt/Seq_List.size(); //return the average length of all the input sequences
  }
}
Ejemplo n.º 4
0
/**
 * Process the chain, with a given chance of processing individual codons
 * This goes through every codon, and has a chance of "synswch" it meaning
 * the codon will choose either itself or another, synonymous codon, instead
 */
void RNA::process(int chance, PopulationNode *pop) {
	chance = chance % 100;

	m_time += get_time();
	m_product++;
	RNA::t_product++;

	if (m_product >= 3 && m_product % 3 == 0) {
		// After 3 products, mutate self and add to pop
		RNA *n = clone();
		n->synswch(chance);
		pop->add_RNA(n);
	}
}
Ejemplo n.º 5
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;
	}
Ejemplo n.º 6
0
RNA DnaConfig::add_DNA_Gamma(DNA& dnaTotal)
{
	DNA dnaGamma;
	RNA rnaGamma;
	//Gamma
    if (m_chkWGamma || m_chkDGamma)        
                        dnaGamma.AddCell(White, PnGamma, m_WGammaBegin, m_WGamma_End, m_WGamma_Avg );  
    if (m_chkRGamma)    dnaGamma.AddCell(Red  , PnGamma, m_RGammaBegin, m_RGamma_End, m_RGamma_Avg );
    if (m_chkGGamma)    dnaGamma.AddCell(Green, PnGamma, m_GGammaBegin, m_GGamma_End, m_GGamma_Avg );
    if (m_chkBGamma)    dnaGamma.AddCell(Blue , PnGamma, m_BGammaBegin, m_BGamma_End, m_BGamma_Avg );

	if (dnaGamma.Size()) 
	{
		Ts->Trans(dnaGamma, rnaGamma);
		rnaGamma.SortOrigMsr();
	}
	dnaTotal += dnaGamma;

	return rnaGamma;
}
Ejemplo n.º 7
0
// the core function doing progressive dynalign calculations and templating
int Multilign_object::ProgressiveMultilign(
        const short int numProcessors,
        const bool Dsv, const bool Ali,
        const short int maxtrace,
        const short int bpwin, const short int awin,
        const short int percent,
        const short int imaxseparation,
        const float gap,
        const bool singleinsert,
        const short int singlefold_subopt_percent,
        const bool local){

    // prepare the object to be ready for the real calculation.
#ifndef MULTIFIND
  if (ErrorCode = PrepInput())
    return ErrorCode;
#else
  if(ErrorCode = PrepMultifindInput())
    return ErrorCode;
#endif
  
    // percent of progress
    int Ppercent = 5;
    int Ppercentstep = (100-Ppercent) / (seqPair.size() * iterations);
    int Ppercentstep1 = Ppercentstep * 0.2; // percent advanced for a dsv template
    int Ppercentstep2 = Ppercentstep - Ppercentstep1; // percent advanced for a dynalign calculation
    if (progress!=NULL) progress->update(Ppercent);
    //   dGIndex.resize(input_alignment.size()-1);
    //  energies.resize(input_alignment.size()-1);
    // if Dsv is true, .dsv files will be stored as
    // j.i_<seq1_name>_<seq2_name>.aout,
    // where j is the cycle number and i is which number of calculation in the cycle
#ifndef MULTIFIND 
    if (Dsv) NameDsvFiles();
#else
    if(Dsv) NameMultifindDsvFiles();
#endif
    // if Ali is true, .aout files will be stored as
    // aliFiles[j][i] = j.i_<seq1_name>_<seq2_name>.aout,
    // where j is the cycle number and i is which number of calculation in the cycle.
#ifndef MULTIFIND
    if (Ali) NameAliFiles();
#else
    if (Ali) NameMultifindAliFiles();
#endif
    int stepBP = 0, totalBP = 0;
    string tmpfilename;
    int struct_num;
    RNA *rna;
    for (int j = 0; j < iterations; ++j){
        for ( size_t i = 0; i < seqPair.size(); ++i){
            //cout << "\nPair " << i+1 << " in cycle " << j+1 << ':' << endl;
            //cout << '\t' << inputList[seqPair[i].first][0] << "<==>" << inputList[seqPair[i].second][0] << endl;
#ifndef MULTIFIND      
            instance = new Dynalign_object(inputList[seqPair[i].first][0].c_str(), 2,
                                    inputList[seqPair[i].second][0].c_str(), 2, isRNA);
#else
	    //   cerr<<input_sequences[seqPair[i].first]<<"\n";
	    //   cerr<<input_sequences[seqPair[i].second]<<"\n";
		    
	    instance = new Dynalign_object(input_sequences[seqPair[i].first].c_str(),input_sequences[seqPair[i].second].c_str());
	  
#endif	  
            instance->GetRNA1()->SetTemperature(temperature);

            // read constraint file for the first seq if it exists
#ifndef MULTIFIND
            if(!inputList[seqPair[i].first][2].empty()){
                //cout << "\tConstraint 1: " << inputList[seqPair[i].first][2] << endl;
                if(ErrorCode = instance->GetRNA1()->ReadConstraints(inputList[seqPair[i].first][2].c_str()))
                    return ErrorCode;
            }

            // read constraint file for the second seq if it exists
            if(!inputList[seqPair[i].second][2].empty()){
                //cout << "\tConstraint 2: " << inputList[seqPair[i].second][2] << endl;
                if(ErrorCode = instance->GetRNA2()->ReadConstraints(inputList[seqPair[i].second][2].c_str()))
                   return ErrorCode;
            }

            structure *ct;
            ct = instance->GetRNA1()->GetStructure();
            // read SHAPE file for the first seq if it exists
            if(!inputList[seqPair[i].first][3].empty()){
                //cout << "\tSHAPE 1: " << inputList[seqPair[i].first][3] << endl;
                ct->SHAPEslope = SHAPESlope * conversionfactor;
                ct->SHAPEintercept = SHAPEIntercept * conversionfactor;
                ct->ReadSHAPE(inputList[seqPair[i].first][3].c_str());
            }

            ct = instance->GetRNA2()->GetStructure();
            // read SHAPE file for the second seq if it exists
            if(!inputList[seqPair[i].second][3].empty()){
                //cout << "\tSHAPE 2: " << inputList[seqPair[i].second][3] << endl;
                ct->SHAPEslope = SHAPESlope * conversionfactor;
                ct->SHAPEintercept = SHAPEIntercept * conversionfactor;
                ct->ReadSHAPE(inputList[seqPair[i].second][3].c_str());
            }
#else
#endif
            // doing dsv templating.
            if (i!=0) tmpfilename = dsvFiles[j][i-1];
            // i == 0 && j != 0
            else if (j!=0) tmpfilename = dsvFiles[j-1][seqPair.size()-1];
            // the first Dynalign is not templated
        if (!(i==0 && j==0) ){
                //cout << "\tdsv template file: " << tmpfilename << endl;
                if(ErrorCode=instance->Templatefromdsv(tmpfilename.c_str(), maxDsv))
                    return ErrorCode;
            }

            if(progress!=NULL){
                Ppercent += Ppercentstep1;
                progress->update(Ppercent);
            }

            // set up the number of base pairs to template
            if (i != 0 && j != 0 && j < iterations - 1) {
                totalBP =- stepBP;
            }
            else totalBP = maxPairs;
	    // cerr<<dsvFiles[j][i]<<"\n";
	    //	    cerr<<"i "<<i<<" j "<<j<<"\n";
            if (ErrorCode = instance->Dynalign(maxtrace, bpwin, awin,
                                               percent, imaxseparation,
                                               gap, singleinsert,
                                               dsvFiles[j][i].c_str(),
                                               false, // Multilign has to set the optimal_only to false
                                               singlefold_subopt_percent,
                                               local, numProcessors,
                                               totalBP) ){
	      
                //cout << "ERROR(cycle " << ++j << ' ' << (seq_pair+i)->first << ' ' << (seq_pair+i)->second << "): " << instance->GetErrorMessage(ErrorCode);
                return ErrorCode;
            }
	    //  cerr<<"we are out!\n";
            if(progress!=NULL){
                Ppercent += Ppercentstep2;
                progress->update(Ppercent);
            }

            if (i==0 && j==0) {
                totalBP = CountBP();
                if (iterations==1)
                    stepBP = (totalBP - maxPairs) / (iterations * seqPair.size() );
                else
                    stepBP = (totalBP - maxPairs) / ( (iterations-1) * seqPair.size() );
            }

            instance->WriteAlignment( aliFiles[j][i].c_str() );

            // last iteration
            if (j == iterations-1){
                if (i==seqPair.size()-1){
                    rna = instance->GetRNA1();
                    struct_num = rna->GetStructureNumber();
                    // calculate free energyies and write into ct variables
                    for(int n = 1; n <= struct_num; ++n) {
                        rna->CalculateFreeEnergy(n);
                    }
                    //cout << "295l   " << struct_num << endl;
#ifndef MULTIFIND
                    if (ErrorCode = instance->GetRNA1()->WriteCt( inputList[seqPair[i].first][1].c_str() )) {
		      return ErrorCode;
		    }
#else
		    if(ct_files.size())if (ErrorCode = instance->GetRNA1()->WriteCt( ct_files[seqPair[i].first].c_str() )) {

                        return ErrorCode;
                    }
#endif
                }
                ///// This is for debug/test.//////////
                ///// output the ct files of the index sequence in the ith pair of dynalign calculations.
                //else {
                    //rna = instance->GetRNA1();
                    //struct_num = rna->GetStructureNumber();
                    //// calculate free energyies and write into ct variables
                    //for(int n = 1; n <= struct_num; ++n) {
                        //rna->CalculateFreeEnergy(n);
                    //}
                    //if (ErrorCode = instance->GetRNA1()->WriteCt( inputList[seqPair[i].first][1] + '1').c_str() )) return ErrorCode;
                //}
                ///// This is for debug/test./////////
		dGIndex.push_back(instance->GetRNA1()->CalculateFreeEnergy(1));
                rna = instance->GetRNA2();
                struct_num = rna->GetStructureNumber();
                // calculate free energyies and write into ct variables
                for(int n = 1; n <= struct_num; ++n) {
		  if (n==1)
    	            energies.push_back(rna->CalculateFreeEnergy(n));
		  else
                    rna->CalculateFreeEnergy(n);
                }
#ifndef MULTIFIND	      
                if (ErrorCode = instance->GetRNA2()->WriteCt( inputList[seqPair[i].second][1].c_str() )) return ErrorCode;
#else 
		//	cerr<<ct_files.size()<<"\n";
		if(ct_files.size())
		if (ErrorCode = instance->GetRNA2()->WriteCt( ct_files[seqPair[i].second].c_str() ) ) return ErrorCode;
#endif	       
            }

            delete instance;

        }
    }

    //if (ErrorCode = WriteAlignment(allali)) return ErrorCode;
    if(progress != NULL && Ppercent != 100) progress->update(100);

    return 0;
}
Ejemplo n.º 8
0
// Run spf calculation on sequence and load folding priors.
// THE PRIORS COMING FROM SPF PROGRAM ARE IN LINEAR DOMAIN!!!
t_spf_array::t_spf_array(int seq_length, 
						 char* seq_path, 
						 t_ppf_cli* _ppf_cli, 
						 char* pairing_probs_file, 
						 bool mallocate)
{
	this->ppf_cli = _ppf_cli;

	this->n_bytes_alloced = 0.0f;

	// Copy sequence length.
	this->N = seq_length;

	if(mallocate)
	{
		this->pairing_array = (double**)malloc(sizeof(double*) * (N + 1));
		this->ind_unpairing_array = (double*)malloc(sizeof(double) * (N + 1));
		this->ind_pairing_array = (double*)malloc(sizeof(double) * (N + 1));
		this->fold_env = (bool**)malloc(sizeof(bool*) * (N + 1));
		this->str_coinc_env = (bool**)malloc(sizeof(bool*) * (N + 1));

		this->n_bytes_alloced += ((sizeof(double*) * (N + 1)) + 
									(sizeof(double) * (N + 1)) + 
									(sizeof(double) * (N + 1)) +
									(sizeof(bool*) * (N + 1)) + 
									(sizeof(bool*) * (N + 1)) + 
									(sizeof(short*) * (N + 1)));
	}
	else
	{
		this->pairing_array = NULL;
		this->ind_unpairing_array = NULL;
		this->ind_pairing_array = NULL;
		this->fold_env = NULL;
		this->str_coinc_env = NULL;
	}

	this->n_bytes_alloced += ((sizeof(double*) * (N + 1)) + 
								(sizeof(double) * (N + 1)) + 
								(sizeof(double) * (N + 1)) +
								(sizeof(bool*) * (N + 1)) + 
								(sizeof(bool*) * (N + 1)) + 
								(sizeof(short*) * (N + 1)));

	// Allocate pairing and unpairing spf arrays.
	for(int i1 = 0; i1 <= N; i1++)
	{
		// Include the max_separation criterion in the allocation function.
		int min_i2 = i1;
		int max_i2 = MIN(i1 + ppf_cli->max_n_separation_between_nucs, N);

		if(mallocate)
		{
			this->fold_env[i1] = (bool*)malloc(sizeof(bool) * (max_i2 - min_i2 + 2));
			this->fold_env[i1] -= i1; // Do pointer shift for fold envelope.
		}

		this->n_bytes_alloced += (sizeof(bool) * (max_i2 - min_i2 + 2));

		if(mallocate)
		{
			this->pairing_array[i1] = (double*)malloc(sizeof(double) * (max_i2 - min_i2 + 2)); // Allocate pairing prob.
			this->pairing_array[i1] -= i1; // Do pointer shift to access the array using sequence indices.
		}

		this->n_bytes_alloced += (sizeof(double) * (max_i2 - min_i2 + 2));

		if(mallocate)
		{
			this->str_coinc_env[i1] = (bool*)malloc(sizeof(bool) * (max_i2 - min_i2 + 2));
			this->str_coinc_env[i1] -= i1; // Do pointer shift for fold envelope.
		}

		this->n_bytes_alloced += (sizeof(double) * (max_i2 - min_i2 + 2));

		if(mallocate)
		{
			this->ind_pairing_array[i1] = ZERO;
			this->ind_unpairing_array[i1] = ZERO;

			for(int i2 = min_i2; i2 <= max_i2; i2++)
			{
				this->pairing_array[i1][i2] = CONVERT_FROM_LIN(0.0); // Initialize the probabilities to 0.
				this->fold_env[i1][i2] = false; // Set all possible pairs.
				this->str_coinc_env[i1][i2] = false;
			}
		}
	} // i1 loop

	if(!mallocate)
	{
		return;
	}

	// Now arrays are allocated, do single partition function calculation for that sequence
	if(pairing_probs_file == NULL)
	{
        	RNA* rna = new RNA(seq_path, 2);
	        rna->PartitionFunction();

		// Load pairing array.
		for(int i = 1; i <= this->N; i++)
		{
			int min_j = i+1;
			int max_j = MIN(i + ppf_cli->max_n_separation_between_nucs, N);

			for(int j = min_j; j <= max_j; j++)
			{
				this->pairing_array[i][j] = rna->GetPairProbability(i, j);
			}
		}
	}
	else
	{
		// Read spf file:
		/*
		Read spf array file, the format is as following:
		1 2 0.000000000000000000000000000000
		1 3 0.000000000000000000000000000000
		1 4 0.000000000000000000000000000000
		1 5 0.000000000000000000000000000000
		1 6 0.000000000000000000000000000000
		1 7 0.000000000000000000000000000000
		1 8 0.000000000000000000000000000000
		1 9 0.000000000000000000000000000000
		1 10 0.000000000000000000000000000000
		1 11 0.000002568332606195572231287628
		...

		where each line consists of
		[index 1] [index 2] [pairing probability of two nucleotides]
		*/
		char spf_array_fn[1000];
		strcpy(spf_array_fn, pairing_probs_file);

		// Read file, read all lines, # of lines read must be equal to # of nucleotides in sequence.
		FILE* spf_file = open_f(spf_array_fn, "rb");

		if(spf_file == NULL)
		{
			printf("Could not open single partition function %s @ %s(%d)\n", spf_array_fn, __FILE__, __LINE__);
			exit(0);
		}

		// SPF file do not contain all the (i1, i2) pairs, it rather includes 
		// i1, i2 pairs where i1 < i2. However in ppf calculations, 
		int i1 = 0;
		int i2 = 0;
		double current_lin_prob = ZERO;
		int n_samples = 0;
		int n_curr_pp_cnt = 0;

		if(fread(&n_samples, sizeof(int), 1, spf_file) != 1)
		{
			printf("Could not read number of samples from %s\n", spf_array_fn);
			exit(0);
		}
		else
		{
			printf("%d samples are processed to estimate base pairing probabilities.\n", n_samples);
		}

		// 1 11 0.000002568332606195572231287628
		while(true)
		{
			if(fread(&i1, sizeof(int), 1, spf_file) != 1)
			{
				break;
			}
		
			if(fread(&i2, sizeof(int), 1, spf_file) != 1)
			{
				printf("Could not read i2 for i1=%d in %s\n", i1, spf_array_fn);
				exit(0);
			}

			if(fread(&n_curr_pp_cnt, sizeof(int), 1, spf_file) != 1)
			{
				printf("Could not read i2 for i1=%d in %s\n", i1, spf_array_fn);
				exit(0);
			}

			current_lin_prob = (double)n_curr_pp_cnt / (double)n_samples;

			// Check max_separation criterion.
			if(i2 > i1 && (i2 - i1) <= ppf_cli->max_n_separation_between_nucs)
			{
				// It should be noted that probabilities in spf file are linear, might need to change them.
				this->pairing_array[i1][i2] = CONVERT_FROM_LIN(current_lin_prob);

	if(_DUMP_SPF_MESSAGES_)
				printf("pp(%d, %d) = %.25f\n", i1, i2, current_lin_prob);

				// If the pairing probability is smaller than fold_env_prob_treshold, set fold envelope for this to 0.
				if(this->pairing_array[i1][i2] >= CONVERT_FROM_LIN(ppf_cli->fold_env_prob_treshold))
				{
					this->fold_env[i1][i2] = true;
				}
			}
			else
			{
				// Out of bounds, do not set the value here since it is not allocated.
			}

	if(_DUMP_SPF_MESSAGES_)
			printf("P_pair(%d, %d) = %.25f\n", i1, i2, this->pairing_array[i1][i2]);

			//fscanf(spf_file, "%d %d %lf", &i1, &i2, &current_lin_prob);
			//printf("read %d %d\n", i1, i2);
		}

		fclose(spf_file);
	} // read the pairing probabilities from external file.

	// Compute the pairing and coincidence ptr relocation maps with base pairing enforced for pairs that have 0.999 or higher probability of pairing.
	this->folding_constraints = new t_folding_constraints(seq_path, this->pairing_array, 0.999f);

	// Weigh all pairing probabilities with a factor in log domain to
	// decrease affect of positive feedback.
	this->calculate_unpairing_probs();

if(_DUMP_SPF_MESSAGES_)
	printf("t_spf_array allocated %lf bytes\n", this->n_bytes_alloced);

//	// Dump spf plane if desired.
//if(_DUMP_SPF_PLANES_)
//{
//	this->dump_spf_plane();
//	this->dump_fold_env();
//}
}
Ejemplo n.º 9
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;

}
Ejemplo n.º 11
0
RNA DnaConfig::add_DNA_WRGBD(DNA& dnaTotal)
{
 	DNA dnaSortStable;
	RNA rnaSortStable;

    //修改的話,要同步修改
    //中心點
    if (m_chkWP1)  dnaSortStable.AddCell(White, Pn1);
    if (m_chkRP1)  dnaSortStable.AddCell(Red  , Pn1);
    if (m_chkGP1)  dnaSortStable.AddCell(Green, Pn1);
    if (m_chkBP1)  dnaSortStable.AddCell(Blue , Pn1);
    if (m_chkDP1)  dnaSortStable.AddCell(Dark , Pn1);
    
    //Nits
    if (m_chkNits)  dnaSortStable.AddCell(Nits, Pn9, m_NitsLv, m_NitsDirect);
    
    //5點
    if (m_chkWP5)    dnaSortStable.AddCell(White, Pn5, m_W5FE);
//     if (m_chkRP5)    dnaSortStable.AddCell(Red  , Pn5, W5FE);
//     if (m_chkGP5)    dnaSortStable.AddCell(Green, Pn5, W5FE);
//     if (m_chkBP5)    dnaSortStable.AddCell(Blue , Pn5, W5FE);
//     if (m_chkDP5)    dnaSortStable.AddCell(Dark , Pn5, W5FE);
    
    //9點
    if (m_chkWP9)    dnaSortStable.AddCell(White, Pn9, m_W9FE, m_W9EdgeType);
//     if (m_chkRP9)    dnaSortStable.AddCell(Red  , Pn9, W9FE, PA_FEover);
//     if (m_chkGP9)    dnaSortStable.AddCell(Green, Pn9, W9FE, PA_FEover);
//     if (m_chkBP9)    dnaSortStable.AddCell(Blue , Pn9, W9FE, PA_FEover);
    if (m_chkDP9)    dnaSortStable.AddCell(Dark , Pn9, m_D9FE, m_D9EdgeType);
    
    //21點
//     if (m_chkWP21)    dnaSortStable.AddCell(White, Pn21, D21FE);
//     if (m_chkRP21)    dnaSortStable.AddCell(Red  , Pn21, D21FE);
//     if (m_chkGP21)    dnaSortStable.AddCell(Green, Pn21, D21FE);
//     if (m_chkBP21)    dnaSortStable.AddCell(Blue , Pn21, D21FE);
    if (m_chkDP21)    dnaSortStable.AddCell(Dark , Pn21, m_D21FE);
    
    //13點
//     if (m_chkWP13)    dnaSortStable.AddCell(White, Pn13, D13FE);
//     if (m_chkRP13)    dnaSortStable.AddCell(Red  , Pn13, D13FE);
//     if (m_chkGP13)    dnaSortStable.AddCell(Green, Pn13, D13FE);
//     if (m_chkBP13)    dnaSortStable.AddCell(Blue , Pn13, D13FE);
    if (m_chkDP13)    dnaSortStable.AddCell(Dark , Pn13, m_D13FE);
    
    //25點
//     if (m_chkWP25)    dnaSortStable.AddCell(White, Pn25, D25FE, D25RectSide);
//     if (m_chkRP25)    dnaSortStable.AddCell(Red  , Pn25, D25FE, D25RectSide);
//     if (m_chkGP25)    dnaSortStable.AddCell(Green, Pn25, D25FE, D25RectSide);
//     if (m_chkBP25)    dnaSortStable.AddCell(Blue , Pn25, D25FE, D25RectSide);
    if (m_chkDP25)    dnaSortStable.AddCell(Dark , Pn25, m_D25FE, m_D25RectSide);
    
    //49點
    if (m_chkWP49)    dnaSortStable.AddCell(White, Pn49);
//     if (m_chkRP49)    dnaSortStable.AddCell(Red  , Pn49);
//     if (m_chkGP49)    dnaSortStable.AddCell(Green, Pn49);
//     if (m_chkBP49)    dnaSortStable.AddCell(Blue , Pn49);
//     if (m_chkDP49)    dnaSortStable.AddCell(Dark , Pn49);

	if (dnaSortStable.Size())
	{
		Ts->Trans(dnaSortStable, rnaSortStable);

		//排序
		if (m_msrQuick)  rnaSortStable.SortQuackMsr();
		else             rnaSortStable.SortOrigMsr();
	}

	showRNA(rnaSortStable);
	dnaTotal += dnaSortStable;
	return rnaSortStable;
}
Ejemplo n.º 12
0
///////////////////////////////////////////////////////////////////////////////
// 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;
    }

}
Ejemplo n.º 13
0
int main( int argc , char *argv[] )
{
   /*  
    string filename = argv[1];
    protein *testp = new protein ;
    testp->load_file( filename );
    testp->gen_score1();
    testp->gen_score2();
    testp->gen_score3();
    testp->gen_score4();
    testp->gen_score5();
    */
string filename = argv[1];
ofstream out1( "RNA_fea.txt" );
RNA *testr = new RNA;
    testr->init( filename );
  //cout << "step 1 is running..." << endl;
    testr->stepFirst();
    //cout << "step 2 is running..." << endl;
    testr->stepSecond();
//cout << "result is running..." << endl;
        for( int i = 0 ; i < 10 ; ++i )
        {
            out1 << testr->ten1[i] << "\t";

        }
        for( int i = 0 ; i < 10 ; ++i )
        {
            out1 << testr->ten2[i] << "\t";

        }
        for( int i = 0 ; i < 9 ; ++i )
        {
            out1 << testr->ten3[i] << "\t";

        }
	out1 << testr->ten3[9] << "\n";
out1.close();
/*ofstream out1( "RNA_fea.txt" );
    char *filename = argv[1];
int i, num;
FILE *fp,*tpfile;
char lineinfo[5000];
	if((fp=fopen(filename,"r"))==NULL){
		
	printf("\nCannot open %s for reading!\n",filename);
		 
	    }


     fgets(lineinfo,5000,fp);

    

    while(!feof(fp)){
      
       if(lineinfo[0]=='>'){
          
          if((tpfile=fopen("tmpSS.fasta","w"))==NULL){
              printf("cannot open queryseq for write\n");
             
          }
           num=num+1;      

           fprintf(tpfile,"%s",lineinfo);
printf("lineinfo=%s\n",lineinfo);
              fgets(lineinfo,5000,fp);
                 
           while(lineinfo[0]!='>' && !feof(fp)){
                  
                   lineinfo[strlen(lineinfo)-1]='\0';
                 fprintf(tpfile,"%s",lineinfo);
               //strcat(madata,lineinfo);
               fgets(lineinfo,5000,fp);

               //printf("lineinfo=%s",lineinfo);
           }
              //fprintf(tpfile,"%s",madata);
           fclose(tpfile);


    RNA *testr = new RNA;
    testr->init( "tmpSS.fasta" );
  //cout << "step 1 is running..." << endl;
    testr->stepFirst();
    //cout << "step 2 is running..." << endl;
    testr->stepSecond();
//cout << "result is running..." << endl;
        for( int i = 0 ; i < 10 ; ++i )
        {
            out1 << testr->ten1[i] << "\t";

        }
        for( int i = 0 ; i < 10 ; ++i )
        {
            out1 << testr->ten2[i] << "\t";

        }
        for( int i = 0 ; i < 9 ; ++i )
        {
            out1 << testr->ten3[i] << "\t";

        }
	out1 << testr->ten3[9] << "\n";
     delete testr;
    testr = NULL;       
    }

              
  }
   
  fclose(fp);
out1.close();
*/
//    cout << "step 3 is running..." << endl;

    //testr->humanprotein_1 = testr->load_humanprotein( testp->score1 , testr->humanprotein_1 , testr->len_humanprotein_1 );
    //testr->humanprotein_2 = testr->load_humanprotein( testp->score2 , testr->humanprotein_2 , testr->len_humanprotein_2 );
    //testr->humanprotein_3 = testr->load_humanprotein( testp->score3 , testr->humanprotein_3 , testr->len_humanprotein_3 );
    //testr->humanprotein_4 = testr->load_humanprotein( testp->score4 , testr->humanprotein_4 , testr->len_humanprotein_4 );
    //testr->humanprotein_5 = testr->load_humanprotein( testp->score5 , testr->humanprotein_5 , testr->len_humanprotein_5 );

    //testr->stepThird();
    //testr->protein_name = testp->all_name;
    //cout << "output as file \"score.txt\"..." << endl;
    //testr->output();

    return 0;
}
Ejemplo n.º 14
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; }
}
Ejemplo n.º 15
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; }

}