[Bio] / RecoElemSBW / SbmlFactory.cc Repository:
ViewVC logotype

View of /RecoElemSBW/SbmlFactory.cc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (download) (as text) (annotate)
Mon Sep 22 20:12:04 2003 UTC (16 years ago) by efrank
Branch: MAIN
CVS Tags: HEAD
Changes since 1.5: +2 -2 lines
dumptoSbml
	give it a RecoId and it dumps SBML

SbmlFactory:
	put in int() for stoich conversions.  may not be right.

SbwFactory:
  	support writing SBML.
	put in int() for stoich conversions.  may not be right

#include <stdio.h>
#include <string>
#include <vector>
#include <iterator>
#include <fstream>
#include <iostream>

#include "RecoReadout/RecoElem.hh"
#include "RecoReadout/Reaction.hh"

#include "sbml/SBMLReader.h"
#include "sbml/SBMLTypes.h"


using namespace std;

//************************************************************************


RecoElem* SBMLtoRecoElem(Model_t* m); 
void inreaction(Reaction_t* r, vector<Reaction>& rxns);
void getReactionModifier(Reaction_t* r, vector<string>& enzymeList );
//************************************************************************





//************************************************************************
RecoElem*
SbmlFactory( const std::string& filename ) {
//************************************************************************
  return SbmlFactory( filename.c_str() );
}


//************************************************************************
RecoElem*
SbmlFactory( const char* filename ) {
//************************************************************************

 
  SBMLDocument_t *d;
  Model_t *m;

  d     = readSBML(filename);

  m = d->model;
  if (0==m) {
    cout << "SbmlFactory:: Did not read model " << filename << endl;
    return 0;
  }

  RecoElem* elem = SBMLtoRecoElem (m); 

  return elem;
}


//**********************************************************************
RecoElem*
SBMLtoRecoElem(Model_t* m) {
//************************************************************************

  string name;
  int id, numreactant, numproduct, modNum;

  Reaction_t* r;  
  Species_t* s;
  ListOf_t* rlist = m->reaction;
 
  SpeciesReference_t* sr;
  

  //not sure what to put as an id, 0 for now

  cout << "model id is " << m->id << endl;  
  if (0==m->name)   {
    name=m->id;
  }  else  {
    name=m->name;
  }

  id=0;

  RecoElem* elem= new RecoElem( name, id);

  vector<Reaction>& rxns      = elem->getReactions();

  //put in reactions
  int reactionsize= ListOf_getNumItems(rlist);
  cout << "in SBMLFactory: number of reactions " << reactionsize << endl;
  

  for (int j=0; j< reactionsize ; j++)
    {
      
      //  cout << "Reaction : " << j <<endl;
      r=Model_getReaction(m,j);
  
      cout << "*****************" << endl;
      inreaction(r,rxns);
      cout << endl;
    }

  return elem;
  

}
//************************************************************************
void
inreaction(Reaction_t* r, vector<Reaction>& rxns) {
//************************************************************************

  int id;
  int dir;

  int numreactant=Reaction_getNumReactants(r);
  int numproduct=Reaction_getNumProducts(r);
  SpeciesReference_t* sr, *pr;
   
  //id not sure what to put here
  //direction is reversible  or not. false, true

  Reaction::Direction reDir;
  id=0;
  dir=r->reversible;
  Reaction rxn( id, Reaction::forward );
  if ( dir ) {
    rxn.setDirection( Reaction::both );
  }

  vector<string>& reactant = rxn.getInputMetaboliteNames();
  vector<string>& product  = rxn.getOutputMetaboliteNames();
  vector<string>& enzymes  = rxn.getEnzymeNames();
  

  vector<int>& inMetabN = rxn.getInputStoich();
  vector<int>& outMetabN = rxn.getOutputStoich();
  
  
  //add reactants
  //add products
  
 

  //figuring out the common denominator
  int rdem = 1;
  int pdem = 1;
  int demstoich;

  for (int j=0; j< numreactant ; j++ )
    {
      sr=Reaction_getReactant(r,j);
      rdem= rdem * sr->denominator;
      
    }

  
  for (int m=0; m<numproduct; m++)
    {
      pr=Reaction_getProduct(r,m);
      pdem= pdem * pr->denominator;

    }


  demstoich = rdem * pdem;
  //cout << "common denominator: " << demstoich;

   for (int k=0; k < numreactant ; k++ )
	 {
	   sr=Reaction_getReactant(r,k);
	   //cout << "test reactant: " << sr->species << endl;

		  
	   reactant.push_back (sr->species);
           inMetabN.push_back( int( demstoich * sr->stoichiometry/sr->denominator));
	 }

   cout << rxn.asString()[0];

   for (int l=0; l<numproduct; l++)
	 {

	   pr=Reaction_getProduct(r,l);
	   //cout << "product: " << pr->species  << endl;
	 
	   product.push_back(pr->species);
	   outMetabN.push_back(int(demstoich * pr->stoichiometry/ pr->denominator) );
	 }
   
   getReactionModifier(r, enzymes);

   rxns.push_back(rxn);
  
  return;
}

//************************************************************************
void
getReactionModifier(Reaction_t* r, vector<string>& enzymeList ) {
//************************************************************************

  ModifierSpeciesReference_t* rMod;
  int modNum;


  modNum = Reaction_getNumModifiers(r);
  cout << modNum << " modifiers for name/id " << r->name << "/" << r->id << endl;

  for (int k =0; k < modNum ; k++)
    {
      rMod =Reaction_getModifier(r, k);
      cout << "the modifier name is " <<  ModifierSpeciesReference_getSpecies(rMod) << endl;
      enzymeList.push_back(ModifierSpeciesReference_getSpecies(rMod) );
    }
}


MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3