Ejemplo n.º 1
0
//create REACTION
void SbmlReader::createReaction( map< string,Id > &molMap )
{	
	map< string,double > rctMap;
	map< string,double >::iterator rctMap_iter;
	map< string,double >pdtMap;
	map< string,double >::iterator pdtMap_iter;
	map< string,Eref >::iterator elemt_iter;
	map< string,EnzymeInfo >enzInfoMap;
	double rctorder,pdtorder;
	static const Cinfo* moleculeCinfo = initMoleculeCinfo();
	static const Finfo* reacFinfo =moleculeCinfo->findFinfo( "reac" );	
	static const Cinfo* reactionCinfo = initReactionCinfo();
	static const Finfo* subFinfo = reactionCinfo->findFinfo( "sub" );
	static const Finfo* prdFinfo = reactionCinfo->findFinfo( "prd" );
	static const Finfo* kfFinfo = reactionCinfo->findFinfo( "kf" );	
	static const Finfo* kbFinfo = reactionCinfo->findFinfo( "kb" );	
	Reaction* reac;	
	for ( unsigned int r = 0; r < model_->getNumReactions(); r++ )
	{	
		reac = model_->getReaction( r ); 
		const string id=reac->getId();
		//cout<<"reaction is "<<id<<endl;
		std::string name;
		if ( reac->isSetName() ){
			name = reac->getName();
		}
		string grpname = getAnnotation( reac,enzInfoMap );
		if ( (grpname != "") && (enzInfoMap[grpname].stage == 3) )
			setupEnzymaticReaction( enzInfoMap[grpname],grpname );
		else if ( grpname == "" )
		{
			if ( reac->getNumModifiers()> 0 )
				 setupMMEnzymeReaction( reac,id );
			else{
				bool rev=reac->getReversible();
				bool fast=reac->getFast();
				if ( fast ){
					cout<<"warning: for now fast attribute is not handled"<<endl;
					errorFlag_ = true;
				}
				int numRcts = reac->getNumReactants();
				int numPdts = reac->getNumProducts();
				if ( numRcts == 0 && numPdts != 0 ){
					const SpeciesReference* pdt = reac->getProduct( 0 );
					std::string spName = pdt->getSpecies();     
					Id parent = molMap.find( spName )->second; //gives compartment of spName
					string parentCompt = parent()->name();
					//cout<<"parent of reactant :"<<parentCompt<<endl;
					ostringstream spId;
					spId <<id<<"_Src";
					molecule_ = Neutral::create( "Molecule",spId.str(),parent,Id::scratchId() );//create Molecule
					molMap[spId.str()] = parent; 
					elmtMap_[spId.str()] = Eref( molecule_ );
					::set< double >( molecule_,"conc", 1 );
					::set< int >( molecule_,"mode",4 );
					reaction_ = Neutral::create( "Reaction",id,parent,Id::scratchId() ); //create Reaction
					Eref( reaction_ ).add( subFinfo->msg(),elmtMap_[spId.str()],reacFinfo->msg(),ConnTainer::Default );
				}
				else{	
					const SpeciesReference* rect=reac->getReactant(0);
					std::string sp=rect->getSpecies();
					Id m = molMap.find(sp)->second; //gives compartment of sp
					reaction_ = Neutral::create( "Reaction",id,m,Id::scratchId() ); //create Reaction
					double rctcount=0.0;	
					rctMap.clear();
					for ( unsigned int rt=0;rt<reac->getNumReactants();rt++ )
					{	
						const SpeciesReference* rct=reac->getReactant(rt);
						sp=rct->getSpecies();
						rctMap_iter = rctMap.find(sp);			
						if ( rctMap_iter != rctMap.end() ){	
							rctcount = rctMap_iter->second;
						}		
						else {
							rctcount = 0.0;
						}
						rctcount += rct->getStoichiometry();
						rctMap[sp] = rctcount;
						for ( int i=0;(int)i<rct->getStoichiometry();i++ )
						{	
							Eref(reaction_).add( subFinfo->msg(),elmtMap_[sp],reacFinfo->msg(),ConnTainer::Default );
				
						}
					}
				}
				double pdtcount = 0.0;
				pdtMap.clear();
				for ( unsigned int pt=0;pt<reac->getNumProducts();pt++ )
				{
					const SpeciesReference* pdt=reac->getProduct(pt);
					std::string sp=pdt->getSpecies();	
					pdtMap_iter = pdtMap.find(sp);
					if ( pdtMap_iter != pdtMap.end() ){	
						pdtcount = pdtMap_iter->second;
					}		
					else {
						pdtcount = 0.0;
					}
					pdtcount += pdt->getStoichiometry();
					pdtMap[sp] = pdtcount;	
					for ( int i=0;i<pdt->getStoichiometry();i++ )
					{	
						Eref(reaction_).add( prdFinfo->msg(),elmtMap_[sp],reacFinfo->msg(),ConnTainer::Default );
					}
			
				}
				//order of reactants
				rctorder = 0.0;	
				string rsp = "",psp = "";
				for ( rctMap_iter=rctMap.begin();rctMap_iter!=rctMap.end();rctMap_iter++ )
				{
					rctorder += rctMap_iter->second;
					rsp=rctMap_iter->first;	//species of the reactant
				}	
				//cout<<"rct order = "<<rctorder<<endl;
				//order of products
				pdtorder = 0.0;
				for ( pdtMap_iter=pdtMap.begin();pdtMap_iter!=pdtMap.end();pdtMap_iter++ )
				{
					pdtorder += pdtMap_iter->second;
					psp=pdtMap_iter->first;	//species of the product	
				}
				//cout<<"pdt order = "<<pdtorder<<endl;
				if ( reac->isSetKineticLaw() )
				{	KineticLaw * klaw=reac->getKineticLaw();
					//vector< double > rate = getKLaw( klaw,rev );
					vector< double > rate;
					rate.clear();
					getKLaw( klaw,rev,rate );
					if ( errorFlag_ )
						return;
					else if ( !errorFlag_ ){
						::set< double >( reaction_, kfFinfo, rate[0] ); 
						::set< double >( reaction_, kbFinfo, rate[1] );	
					}
			
				}

			}//else modifier
		}//else 	
	}//reaction 
}//create reaction
Ejemplo n.º 2
0
void SbmlReader::createReaction(const map< string, Id > &molSidcmptMIdMap ) {
    Reaction* reac;

    map< string,double > rctMap;
    map< string,double >::iterator rctMap_iter;
    map< string,double >prdMap;
    map< string,double >::iterator prdMap_iter;
    map< string,EnzymeInfo >enzInfoMap;

    for ( unsigned int r = 0; r < model_->getNumReactions(); r++ ) {
        Id reaction_;
        reac = model_->getReaction( r );
        noOfsub_ = 0;
        noOfprd_ = 0;
        std:: string id; //=reac->getId();
        if ( reac->isSetId() )
            id = reac->getId();

        std::string name;
        if ( reac->isSetName() ) {
            name = reac->getName();
            name = nameString(name);
        }
        if (name.empty()) {
            if (id.empty())
                assert("Reaction id and name is empty");
            else
                name = id;
        }
        string grpname = getAnnotation( reac,enzInfoMap );
        if ( (grpname != "") && (enzInfoMap[grpname].stage == 3) ) {
            setupEnzymaticReaction( enzInfoMap[grpname],grpname ,molSidcmptMIdMap,name);
        }
        //if (grpname != "")
        // {
        //cout << "\n enz matic reaction " << enzInfoMap[grpname].stage;
        //setupEnzymaticReaction( enzInfoMap[grpname],grpname ,molSidcmptMIdMap);
        //}

        else if ( grpname == "" ) {
            if (reac->getNumModifiers() > 0)
                setupMMEnzymeReaction( reac,id,name ,molSidcmptMIdMap);
            else {
                bool rev=reac->getReversible();
                bool fast=reac->getFast();
                if ( fast ) {
                    cout<<"warning: for now fast attribute is not handled"<<endl;
                    errorFlag_ = true;
                }
                int numRcts = reac->getNumReactants();
                int numPdts = reac->getNumProducts();
                if ( numRcts == 0 && numPdts != 0 ) {
                    cout << "Reaction with zero Substrate is not possible but exist in this model";
                    const SpeciesReference* pdt = reac->getProduct( 0 );
                    std::string spName = pdt->getSpecies();
                    Id parent = molSidcmptMIdMap.find( spName )->second; //gives compartment of spName
                    cout << " \n \t ################################# Sub = 0 and prd != 0 need to the reac ############### ";
                    const SpeciesReference* rect=reac->getReactant(0);
                    std::string sp=rect->getSpecies();
                    Id comptRef = molSidcmptMIdMap.find(sp)->second; //gives compartment of sp
                    Id meshEntry = Neutral::child( comptRef.eref(), "mesh" );
                    Shell* shell = reinterpret_cast< Shell* >( Id().eref().data() );
                    reaction_ = shell->doCreate("Reac", meshEntry, name, 1);
                    //shell->doAddMsg( "Single", meshEntry, "remeshReacs", reaction_, "remesh");
                    //Get Substrate
                    addSubPrd(reac,reaction_,"prd");
                } //if numRcts == 0
                else {
                    const SpeciesReference* rect=reac->getReactant(0);
                    std::string sp=rect->getSpecies();
                    Id comptRef = molSidcmptMIdMap.find(sp)->second; //gives compartment of sp
                    Id meshEntry = Neutral::child( comptRef.eref(), "mesh" );
                    Shell* shell = reinterpret_cast< Shell* >( Id().eref().data() );

                    reaction_ = shell->doCreate("Reac", comptRef, name, 1);
                    //shell->doAddMsg( "Single", meshEntry, "remeshReacs", reaction_, "remesh");
                    //Get Substrate
                    addSubPrd(reac,reaction_,"sub");

                    //Get Product
                    addSubPrd(reac,reaction_,"prd");
                }
                if ( reac->isSetKineticLaw() ) {
                    KineticLaw * klaw=reac->getKineticLaw();

                    //vector< double > rate = getKLaw( klaw,rev );
                    vector< double > rate;
                    rate.clear();
                    getKLaw( klaw,rev,rate );
                    if ( errorFlag_ )
                        return;
                    else if ( !errorFlag_ ) {
                        //cout << " Reaction name " << name << " kf " << rate[0] << " kb " << rate[1]<<endl;

                        Field < double > :: set( reaction_, "Kf", rate[0] );
                        Field < double > :: set( reaction_, "Kb", rate[1] );
                        /*if (numRcts > 1)
                        rate[0] = rate[0]*pow(1e3,1.0);
                             cout << "Reaction " << id << " " << name << " " << rate[0] << "  " << rate[1]<<endl;
                             Field < double > :: set( reaction_, "Kf", rate[0] );
                             Field < double > :: set( reaction_, "Kb", rate[1] );
                             */
                    }
                } //issetKineticLaw

            } //else
        } // else grpname == ""
    }//for unsigned
} //reaction