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

View of /RecoElemSBW/RecoElemSBWSampleClient.cc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (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.3: +1 -2 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 "MExplorer/xduGen.hh"

using namespace std;
using namespace SystemsBiologyWorkbench ;


//************************************************************************
void usage( void );
RecoElem* sbwToRecoElem( DataBlockReader& r );
void unpackRx( DataBlockReader& r, vector<Reaction>& rxns );
void printList (RecoElem& elem);


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

  DataBlockWriter  args;
  DataBlockReader  result;

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

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

  // connect to broker, find RecoElemRead service
	 
  SBW::connect();

  Module recoElemReadModule   = SBW::getModuleInstance("gov.mcs.anl.compbio");
  Service recoElemReadService = recoElemReadModule.findServiceByName("RecoElemRead");
  ServiceMethod RecoMethod    = recoElemReadService.getMethod("{}getTree(int)");
		
  // build arg list to call service:  pass it the node Id we want to get back
  // then actually do the call

  args << topNodeId;
  result=RecoMethod.call( args );
 
  
  RecoElem* elem = sbwToRecoElem( result );
  
  // now we actually have the recoElem, transfered from the server.  do
  // something with it..

  std::string path="";
  xduGen( *elem, path );

  cout << "************************" << endl;
  printList(*elem);
  cout << "************************" << endl;

  
  recoElemReadModule.shutdown();
  SBW::disconnect(); 

  return 0;
}

void printList (RecoElem& elem)

{

  vector<RecoElem>& subElem   = elem.getSubElements();
  vector<Reaction>& rxns      = elem.getReactions();

  int nrxns= rxns.size ();
  int nkids= subElem.size ();

  cout << "MY NAME: " << elem.getName() << endl;
  cout << "  No. of reactions " << nrxns << endl;
  cout << "  No. of kids: " << nkids << endl;
  cout << " &&&&&&&&&&" <<endl;

  for (int l=0; l< nrxns ; l++) {
    cout << rxns[l].asString() << endl; 
  }


  for (int i=0; i<nkids; i++){
    cout << "in deeper  ****  " << endl;
    printList(subElem[i]);
    cout << "back up *** " << endl;
  }

  return;
}


//************************************************************************
void
usage( void ) {
//************************************************************************
  cout << endl;
  cout << "usage: RecoElemSBWClient TopNodeId" << endl;
  cout << "   TopNodeId is the ProcessId of the top of the reconstruction." << endl;
  cout << "   You can find the top node of a reconstruction with lsCat," << endl;
  cout << "   which lists the Catalog." << endl;
  cout << endl;

  return;
}



//************************************************************************
RecoElem*
sbwToRecoElem( DataBlockReader& r ) {
//************************************************************************

  string          n;
  int             id;

  r >> n;
  r >> id;
  RecoElem* elem = new RecoElem( n, id );

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

  int nrx;
  r >> nrx;
  for( int i=0; i<nrx; i++ ) {
    unpackRx( r, rxns);
   
  }


  int nKid;
  r >> nKid;
  RecoElem* aKid;
  for ( int i=0; i<nKid; i++ ) {
    aKid = sbwToRecoElem( r );
    subElems.push_back( *aKid );
  }

 
  return elem;
}


//************************************************************************
void
unpackRx( DataBlockReader& rIn, vector <Reaction>& rxns ) {

  int             id;
  int             dir;
  DataBlockReader inMetabL, outMetabL, enzymeL;
  DataBlockReader r;

  
  // The passed in DataBlockReader, rIn, begins with a List...shove it
  // into r and pull the rx info out of it.

  rIn >> r;
  
  r >> id;
  r >> dir;


  Reaction rxn( id, (Reaction::Direction) dir );
  
  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;
  int             nOut;
  int             nEnz;
  string          name;
  int             stoich;


  r >> inMetabL;
  inMetabL >> nIn;
  for ( int i=0; i<nIn; i++ ) {
    inMetabL >> name;
    inMetabL >> stoich;


    inMetab.push_back( name);
    inMetabN.push_back( stoich );
    
  
  }
 

  r >> outMetabL;
  outMetabL >> nOut;
  for ( int i=0; i<nOut; i++ ) {
    outMetabL >> name;
    outMetabL >> stoich;
    outMetab.push_back( name);
    outMetabN.push_back( stoich );
  }

  r >> enzymeL;
  enzymeL >> nEnz;
  for ( int i=0; i<nEnz; i++ ) {
    enzymeL >> name;
    enzymes.push_back( name );
  }

  

  rxns.push_back( rxn );
  

  return;
}

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3