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

View of /RecoElemSBW/dumpToSbml.cc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (download) (as text) (annotate)
Wed Sep 24 00:13:53 2003 UTC (16 years, 2 months ago) by efrank
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +48 -2 lines
Can create SIF file for cytoscape now too.  Not great, though.
SIF is "interaction file"

#include <stdio.h>
#include <string>
#include <fstream>

#include "RecoReadout/RecoElem.hh"
#include "RecoElemSBW/SbwFactory.hh"
#include "RecoReadoutOracle/BssFactory.hh"
#include "RecoReadoutOracle/OracleMgr.hh"


using namespace std;

void dumpToSif( RecoElem* top, string filename);

//************************************************************************
int
main(int argc, char* argv[] ) {
//************************************************************************
  SbwFactory  sbwFactory;
  RecoElem* elem;
 
  if (argc != 3) {
    printf("usage: dumpToSbml <recoId> <filename>.xml\n");
    return 1;
  } else {
    cout << "Dumping to file " << argv[2] << endl;
  }


  std::string fileNamebase( argv[2] );

  unsigned int topNodeId = atoi( argv[1] );
  cout << "dumping node " << topNodeId << endl;

  OracleMgr::mgr().startJob();
  BssFactory  bssFactory;
  cout << "start reading" << endl;
  RecoElem* recoTop = bssFactory.getRecoElemById( topNodeId);
  cout << "done reading" << endl;

  std::string sbmlFileName = fileNamebase+".xml";
  sbwFactory.writeSbmlFile( *recoTop, sbmlFileName.c_str() );

  std::string sifFileName = fileNamebase+".sif";
  dumpToSif( recoTop, sifFileName);

  OracleMgr::mgr().endJob();
  delete recoTop;
  return 0;
}

//************************************************************************
void
dumpToSif( RecoElem* top, string filename) {
//************************************************************************
  std::set<Reaction>  rxns;
  std::vector<string> metabs;
  std:: string        rxnName;

  ofstream theFile;
  theFile.open( filename.c_str(), ofstream::trunc);

  top->gatherReactions( rxns );

  std::set<Reaction>::iterator iRxn    = rxns.begin();
  std::set<Reaction>::iterator iRxnEnd = rxns.end();

  cout << "Converting to Sif" << endl;
  for( ; iRxn != iRxnEnd; iRxn++) {
    if (iRxn->hasEnzyme() ) {
      rxnName = iRxn->getEnzymeNames()[0];
    } else {
      rxnName = iRxn->getIdString();
    }

    metabs = iRxn->getInputMetaboliteNames();
    for( int i=0; i < metabs.size(); i++ ){
      theFile << metabs[i] << " reactantFor " << rxnName << endl;
    }

    metabs = iRxn->getOutputMetaboliteNames();
    for( int i=0; i < metabs.size(); i++ ){
      theFile << rxnName << " produces " << metabs[i] << endl;
    }
      
  }

  theFile.close();
  return;
}

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3