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

View of /RecoElemSBW/RecoElemSBWServer.cc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (download) (as text) (annotate)
Thu May 8 18:12:11 2003 UTC (16 years, 5 months ago) by efrank
Branch: MAIN
CVS Tags: ldrd-2003-01, HEAD
Changes since 1.1: +5 -3 lines
Migrate RecoElem to not use RecoElemImpl

//************************************************************************
// Play with exploring the e. coli reco in biosimscratch.
//
//
// look at enscript | ps2pnm | ppmtopcx to get faux fluxmap.
//
//************************************************************************

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

#include "SBW.h"

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

#include "RecoReadoutOracle/BssFactory.hh"
#include "RecoReadoutOracle/OracleMgr.hh"

using namespace std;
using namespace SystemsBiologyWorkbench ;


//************************************************************************
void usage( void );
void registerRecoElemSBWServer(int argc, char* arg[]);
void reactionToSBW( Reaction& rxn, DataBlockWriter& theWriter);
void recoElemToSBW( RecoElem& theElem, DataBlockWriter& theWriter);


//************************************************************************
class RecoElemSBWService {
//************************************************************************
public :
  DataBlockWriter get_Tree(Module from, DataBlockReader reader);

  static void registerMethods(MethodTable<RecoElemSBWService> &table) {
    table.addMethod(&RecoElemSBWService::get_Tree, "{} getTree(int)");
  }
};

//************************************************************************
int
main(int argc, char* argv[] ) {
//************************************************************************

  std::set<string>      species;      // collect the species list here
  std::set<Reaction>     rxns;         // collect reactions here

  if ( 1 != argc  && 2 != argc ) {
    usage();
    return 1;
  }

  OracleMgr::mgr().startJob();

  // start/register SBW service
  registerRecoElemSBWServer(argc, argv);

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

//************************************************************************
void
usage( void ) {
//************************************************************************
  cout << endl;
  cout << "usage: RecoElemSBWServer [-sbwregister]" << endl;
  cout << endl;

  return;
}


//************************************************************************
void
registerRecoElemSBWServer(int argc, char* argv[]) {
//************************************************************************

  try
    {
      // in the following calls help text is an optional argument which has not
      // been supplied in this example
      
      ModuleImpl modImpl(
			 "gov.mcs.anl.compbio", // module identification
			 "ANL SBW services",    // humanly readable name
			 SelfManagedModule      // management scheme
			 );

	
      modImpl.addServiceObject(
			       "RecoElemRead",      // service identification
			       "Fetch RecoElems",   // humanly readable name
			       "RecoElemServer",    // category
			       new RecoElemSBWService());      
      
      // connect to broker providing services
      modImpl.run(argc, argv);
    }
  catch (SBWException *e)
    {
      fprintf(stderr, "RecoElemSBWServer exception: %s\n", 
	      e->getMessage().c_str());
      exit(1);
    }

  return;
}


//************************************************************************
DataBlockWriter 
RecoElemSBWService::get_Tree(Module from, DataBlockReader reader) {
//************************************************************************
    
  // Fetch the requested RecoElem from the database.

  int topNodeId;
  reader >> topNodeId;
  
  BssFactory theFactory;
  RecoElem* recoTop = theFactory.getRecoElemById( topNodeId );   // we own!
    
  // Convert it to SBW format (pack it into a datablock writer

  DataBlockWriter  result;
  recoElemToSBW( *recoTop, result );

  delete recoTop;
  return result;
}

//************************************************************************
void
recoElemToSBW( RecoElem& theElem, DataBlockWriter& theWriter) {
//************************************************************************

  theWriter << theElem.getName();
  theWriter << (int) theElem.getId();

  vector<Reaction>& theRxns = theElem.getReactions();
  int nRxn = theRxns.size();

  theWriter << nRxn;
  for ( int i=0; i<nRxn; i++) {
    reactionToSBW( theRxns[i], theWriter );
  }

  vector<RecoElem>& kids    = theElem.getSubElements();
  int               nKids   = kids.size();
  theWriter << nKids;
  for( int i=0; i<nKids; i++) {
    recoElemToSBW( kids[i], theWriter );
  }
  return;
}

//************************************************************************
void
reactionToSBW( Reaction& rxn, DataBlockWriter& theWriter) {
//************************************************************************
  // Add rxn into the datablockwriter, theWriter

  DataBlockWriter Rx, inMetabL, outMetabL, enzymeL;
  
  vector<string>& inMetab   = rxn.getInputMetaboliteNames();
  vector<int>&    inMetabN  = rxn.getInputStoich();
  vector<string>& outMetab  = rxn.getOutputMetaboliteNames();
  vector<int>&    outMetabN = rxn.getOutputStoich();
  vector<string>& enzymes   = rxn.getEnzymeNames();
  int             nIn       = inMetab.size();
  int             nOut      = outMetab.size();
  int             nEnz      = enzymes.size();

  inMetabL << nIn;
  for ( int i=0; i<nIn; i++ ) {
    inMetabL << inMetab[i];
    inMetabL << inMetabN[i];
  }

  outMetabL << nOut;
  for ( int i=0; i<nOut; i++ ) {
    outMetabL << outMetab[i];
    outMetabL << outMetabN[i];
  }

  enzymeL << nEnz;
  for ( int i=0; i<nEnz; i++ ) {
    enzymeL << enzymes[i];
  }

  // [rxId, Direction, inMetabList, outMetabList, catalystList ]

  Rx << (int) rxn.getId()
     << (int) rxn.getDirection()
     << inMetabL
     << outMetabL
     << enzymeL;

  theWriter << Rx;

  return;
}

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3