Esempio n. 1
0
/**
 * \fn void SBML_reaction(Model_t *mod, pEspeces molecules, Reaction_t *react, int nbEspeces)
 * \author Amine Ghozlane
 * \brief  Simulation of a discrete transision
 * \param  mod Model of the SBML file
 * \param  molecules Struct Especes
 * \param  react Reaction id
 * \param  nbEspeces Number of molecules
 */
void SBML_reaction(Model_t *mod, pEspeces molecules, Reaction_t *react, int nbEspeces)
{
  /* Simulation d'une transision discrete */
  SpeciesReference_t *reactif;
  Species_t *especeId;
  int i, ref = 0;

  /*boucle pour retirer des reactifs*/
  for (i = 0; i < (int)Reaction_getNumReactants(react); i++) {
      /* Indentification du reactif */
      reactif = Reaction_getReactant(react, i);
      especeId = Model_getSpeciesById(mod, SpeciesReference_getSpecies(reactif));
      ref = Especes_find(molecules, Species_getId(especeId), nbEspeces);
      /* Modification de sa quantite */
      Especes_setQuantite(molecules, ref, (Especes_getQuantite(molecules, ref)- SpeciesReference_getStoichiometry(reactif)));
  }

  /*boucle pour ajouter des produits */
  for (i = 0; i < (int)Reaction_getNumProducts(react); i++) {
      /* Indentification du reactif */
      reactif = Reaction_getProduct(react, i);
      especeId = Model_getSpeciesById(mod, SpeciesReference_getSpecies(reactif));
      ref = Especes_find(molecules, Species_getId(especeId), nbEspeces);
      /* Modification de sa quantite */
      Especes_setQuantite(molecules, ref, (Especes_getQuantite(molecules, ref)+ SpeciesReference_getStoichiometry(reactif)));
  }
}
Esempio n. 2
0
END_TEST


START_TEST (test_Species_setId)
{
  const char *id = "Glucose";


  Species_setId(S, id);

  fail_unless( !strcmp(Species_getId(S), id) );
  fail_unless( Species_isSetId(S) );

  if (Species_getId(S) == id)
  {
    fail("Species_setId(...) did not make a copy of string.");
  }

  /* Reflexive case (pathological) */
  Species_setId(S, Species_getId(S));
  fail_unless( !strcmp(Species_getId(S), id) );

  Species_setId(S, NULL);
  fail_unless( !Species_isSetId(S) );

  if (Species_getId(S) != NULL)
  {
    fail("Species_setId(S, NULL) did not clear string.");
  }
}
Esempio n. 3
0
END_TEST


START_TEST (test_L3_Species_initDefaults)
{
  Species_t *s = Species_create(3,1);

  fail_unless( Species_getId     (s) == NULL );
  fail_unless( Species_getName   (s) == NULL );
  fail_unless( Species_getCompartment  (s) == NULL );
  fail_unless( util_isNaN(Species_getInitialAmount (s)) );
  fail_unless( util_isNaN(Species_getInitialConcentration (s)) );
  fail_unless( Species_getSubstanceUnits  (s) == NULL );
  fail_unless( Species_getHasOnlySubstanceUnits(s) == 0   );
  fail_unless( Species_getBoundaryCondition(s) == 0   );
  fail_unless( Species_getConstant(s) == 0   );
  fail_unless( Species_getConversionFactor  (s) == NULL );

  fail_unless( !Species_isSetId     (s) );
  fail_unless( !Species_isSetName   (s) );
  fail_unless( !Species_isSetCompartment (s) );
  fail_unless( !Species_isSetInitialAmount (s) );
  fail_unless( !Species_isSetInitialConcentration (s) );
  fail_unless( !Species_isSetSubstanceUnits  (s) );
  fail_unless( !Species_isSetHasOnlySubstanceUnits(s)   );
  fail_unless( !Species_isSetBoundaryCondition(s)   );
  fail_unless( !Species_isSetConstant(s)   );
  fail_unless( !Species_isSetConversionFactor  (s) );

  Species_initDefaults(s);

  fail_unless( Species_getId     (s) == NULL );
  fail_unless( Species_getName   (s) == NULL );
  fail_unless( Species_getCompartment  (s) == NULL );
  fail_unless( util_isNaN(Species_getInitialAmount (s)) );
  fail_unless( util_isNaN(Species_getInitialConcentration (s)) );
  fail_unless( !strcmp(Species_getSubstanceUnits  (s),"mole" ));
  fail_unless( Species_getHasOnlySubstanceUnits(s) == 0   );
  fail_unless( Species_getBoundaryCondition(s) == 0   );
  fail_unless( Species_getConstant(s) == 0   );
  fail_unless( Species_getConversionFactor  (s) == NULL );

  fail_unless( !Species_isSetId     (s) );
  fail_unless( !Species_isSetName   (s) );
  fail_unless( !Species_isSetCompartment (s) );
  fail_unless( !Species_isSetInitialAmount (s) );
  fail_unless( !Species_isSetInitialConcentration (s) );
  fail_unless( Species_isSetSubstanceUnits  (s) );
  fail_unless( Species_isSetHasOnlySubstanceUnits(s)   );
  fail_unless( Species_isSetBoundaryCondition(s)   );
  fail_unless( Species_isSetConstant(s)   );
  fail_unless( !Species_isSetConversionFactor  (s) );

  Species_free(s);
}
Esempio n. 4
0
int count_ode(mySpecies* sp[], unsigned int num_of_species, int* ode_check, Species_t* s){
	unsigned int i;
	for(i=0; i<num_of_species; i++){
		if(strcmp(Species_getId(s), Species_getId(sp[i]->origin)) == 0){
			if(*(ode_check + i) == 0){
				*(ode_check + i) = 1;
				return 1;
			}
		}
	}
	return 0;
}
void prepare_reversible_fast_reaction(Model_t *m, myReaction *re[], mySpecies *sp[], myParameter *param[], myCompartment *comp[], double sim_time, double dt, double *time, myInitialAssignment *initAssign[], char *time_variant_target_id[], unsigned int num_of_time_variant_targets, timeVariantAssignments *timeVarAssign, allocated_memory *mem, copied_AST *cp_AST){
  unsigned int i;
  unsigned int num_of_reactions = Model_getNumReactions(m);
  ASTNode_t *node, *cp_node1, *cp_node2;
  myASTNode *myNode = NULL;
  myASTNode *copied_myAST[MAX_COPIED_AST];
  unsigned int num_of_copied_myAST = 0;
  for(i=0; i<num_of_reactions; i++){
    if(re[i]->is_fast && re[i]->is_reversible){
      node = (ASTNode_t*)KineticLaw_getMath(Reaction_getKineticLaw(re[i]->origin));
      node = ASTNode_deepCopy(node);
      TRACE(("original math of %s: ", Reaction_getId(re[i]->origin)));
      check_AST(node, NULL);
      /* alter_tree_structure(m, &node, cp_AST); */
      alter_tree_structure(m, &node, NULL, 0, cp_AST);
      set_local_para_as_value(node, Reaction_getKineticLaw(re[i]->origin));
      TRACE(("alterated math of %s : ", Reaction_getId(re[i]->origin)));
      check_AST(node, NULL);
      cp_node1 = ASTNode_deepCopy(node);
      cp_node2 = ASTNode_deepCopy(node);
      /* get products numerator */
      myNode = (myASTNode*)malloc(sizeof(myASTNode));
      copied_myAST[num_of_copied_myAST++] = myNode;
      myNode->origin = cp_node1;
      myNode->parent = NULL;
      myNode->left = NULL;
      myNode->right = NULL;
      myASTNode_create(myNode, cp_node1, copied_myAST, &num_of_copied_myAST);
      re[i]->products_equili_numerator = (equation*)malloc(sizeof(equation));
      TRACE(("target_id is %s\n", Species_getId(re[i]->reactants[0]->mySp->origin)));
      check_AST(cp_node1, NULL);
      _prepare_reversible_fast_reaction(m, myNode, re[i], sp, param, comp, re, sim_time, dt, time, initAssign, time_variant_target_id, num_of_time_variant_targets, timeVarAssign, (char*)Species_getId(re[i]->reactants[0]->mySp->origin), 0, mem);
      /* get reactants numerator */
      myNode = (myASTNode*)malloc(sizeof(myASTNode));
      copied_myAST[num_of_copied_myAST++] = myNode;
      myNode->origin = cp_node2;
      myNode->parent = NULL;
      myNode->left = NULL;
      myNode->right = NULL;
      re[i]->reactants_equili_numerator = (equation*)malloc(sizeof(equation));
      myASTNode_create(myNode, cp_node2, copied_myAST, &num_of_copied_myAST);
      TRACE(("target_id is %s\n", Species_getId(re[i]->products[0]->mySp->origin)));
      check_AST(cp_node2, NULL);
      _prepare_reversible_fast_reaction(m, myNode, re[i], sp, param, comp, re, sim_time, dt, time, initAssign, time_variant_target_id, num_of_time_variant_targets, timeVarAssign, (char*)Species_getId(re[i]->products[0]->mySp->origin), 1, mem);
      myASTNode_free(copied_myAST, num_of_copied_myAST);
    }
  }
}
Esempio n. 6
0
void myInitialAssignment_initTarget(
    myInitialAssignment *assign,
    mySpecies **species, unsigned int num_of_species,
    myParameter **parameters, unsigned int num_of_parameters,
    myCompartment **compartments, unsigned int num_of_compartments) {
  unsigned int i;
  InitialAssignment_t *origin;
  const char *origin_symbol;

  origin = myInitialAssignment_getOrigin(assign);
  origin_symbol = InitialAssignment_getSymbol(origin);

  for (i = 0; i < num_of_species; i++) {
    if (strcmp(origin_symbol, Species_getId(species[i]->origin)) == 0) {
      myInitialAssignment_setTargetSpecies(assign, species[i]);
      return;
    }
  }

  for (i = 0; i < num_of_parameters; i++) {
    if (strcmp(origin_symbol, Parameter_getId(parameters[i]->origin)) == 0) {
      myInitialAssignment_setTargetParameter(assign, parameters[i]);
      return;
    }
  }

  for (i = 0; i < num_of_compartments; i++) {
    if (strcmp(origin_symbol, Compartment_getId(compartments[i]->origin)) == 0) {
      myInitialAssignment_setTargetCompartment(assign, compartments[i]);
      return;
    }
  }
}
Esempio n. 7
0
/* create contents of myResult object */
myResult *create_myResult(Model_t *m, mySpecies *mySp[], myParameter *myParam[], myCompartment *myComp[], double sim_time, double dt, int print_interval) {
  int i;
  myResult *result;
  int num_of_species = Model_getNumSpecies(m);
  int num_of_parameters = Model_getNumParameters(m);
  int num_of_compartments = Model_getNumCompartments(m);
  int end_cycle = get_end_cycle(sim_time, dt);

  result = (myResult *)malloc(sizeof(myResult));
  result->error_code = NoError;
  result->error_message = NULL;
  result->num_of_columns_sp = num_of_species;
  result->num_of_columns_param = num_of_parameters;
  result->num_of_columns_comp = num_of_compartments;
  result->num_of_rows = end_cycle / print_interval + 1;
  result->column_name_time  = dupstr("time");
  result->column_name_sp    = (const char **)malloc(sizeof(char *) * num_of_species);
  result->column_name_param = (const char **)malloc(sizeof(char *) * num_of_parameters);
  result->column_name_comp  = (const char **)malloc(sizeof(char *) * num_of_compartments);
  result->values_time = (double *)malloc(sizeof(double) * result->num_of_rows);
  result->values_sp = (double *)malloc(sizeof(double) * num_of_species * result->num_of_rows);
  result->values_param = (double *)malloc(sizeof(double) * num_of_parameters * result->num_of_rows);
  result->values_comp = (double *)malloc(sizeof(double) * num_of_compartments * result->num_of_rows);
  for(i=0; i<num_of_species; i++){
    result->column_name_sp[i] = dupstr(Species_getId(mySp[i]->origin));
  }
  for(i=0; i<num_of_parameters; i++){
    result->column_name_param[i] = dupstr(Parameter_getId(myParam[i]->origin));
  }
  for(i=0; i<num_of_compartments; i++){
    result->column_name_comp[i] = dupstr(Compartment_getId(myComp[i]->origin));
  }
  return result;
}
Esempio n. 8
0
int SBML_checkQuantite(Model_t *mod, Reaction_t *react, int nbEspeces, pEspeces molecules)
{
  /* Determine le nombre de reaction possible a partir de la quantite des reactifs */
  int  ref = 0, i;
  double quantite = 0.0, minStep = 0.0, temp = 0.0;
  SpeciesReference_t *reactif;
  Species_t *especeId;
  /*TODO Il est possible de reprogrammer ca plus proprement */
  /* Recupere la quantite de la premiere molecule */
  reactif = Reaction_getReactant(react, 0);
  especeId = Model_getSpeciesById(mod, SpeciesReference_getSpecies(reactif));
  ref = Especes_find(molecules, Species_getId(especeId), nbEspeces);
  /* Cas ou la quantite de la molecule est egale a zero */
  if ((quantite = Especes_getQuantite(molecules, ref)) <= 0.0) return END;
  /* Calcul du nombre de pas minimum qu'il sera possible d'effectuer */
  /* C'est le nombre minimum d'etat de tous les reactifs qui determine le nombre de pas */
  minStep = floor(quantite / SpeciesReference_getStoichiometry(reactif));

  /*fprintf(stderr,"round species %s minstep %f quantite %f stochiometry %f\n",Species_getId(especeId),round(quantite / SpeciesReference_getStoichiometry(reactif)),quantite,SpeciesReference_getStoichiometry(reactif));
  fprintf(stderr,"ceil species %s minstep %f quantite %f stochiometry %f\n",Species_getId(especeId),ceil(quantite / SpeciesReference_getStoichiometry(reactif)),quantite,SpeciesReference_getStoichiometry(reactif));
  fprintf(stderr,"floor species %s minstep %f quantite %f stochiometry %f\n",Species_getId(especeId),floor(quantite / SpeciesReference_getStoichiometry(reactif)),quantite,SpeciesReference_getStoichiometry(reactif));*/
  /* Cas ou le nombre de pas est egal a 0 */
  if(minStep==0.0) return END;

  /* On calcule pour les autres reactifs */
  for (i = 1; i < (int)Reaction_getNumReactants(react); i++) {
      /* Recupere la quantite d'une molecule */
      reactif = Reaction_getReactant(react, i);
      especeId = Model_getSpeciesById(mod, SpeciesReference_getSpecies(reactif));
      ref = Especes_find(molecules, Species_getId(especeId), nbEspeces);
      quantite= Especes_getQuantite(molecules, ref);
      /* La quantite est egale a 0 */
      if(quantite<=0.0) return END;
      /* On calcule le nombre de pas minimum qu'il sera possible d'effectuer */
      temp = floor(Especes_getQuantite(molecules, ref)/SpeciesReference_getStoichiometry(reactif));
      /*fprintf(stderr,"species %s minstep %f temp %f\n",Species_getId(especeId),minStep,temp);*/
      /*fprintf(stderr,"round species %s minstep %f quantite %f stochiometry %f\n",Species_getId(especeId),round(quantite / SpeciesReference_getStoichiometry(reactif)),quantite,SpeciesReference_getStoichiometry(reactif));
      fprintf(stderr,"ceil species %s minstep %f quantite %f stochiometry %f\n",Species_getId(especeId),ceil(quantite / SpeciesReference_getStoichiometry(reactif)),quantite,SpeciesReference_getStoichiometry(reactif));
      fprintf(stderr,"floor species %s minstep %f quantite %f stochiometry %f\n",Species_getId(especeId),floor(quantite / SpeciesReference_getStoichiometry(reactif)),quantite,SpeciesReference_getStoichiometry(reactif));*/
      /* Cas ou le nombre de pas est egal a 0 */
      if(temp==0.0) return END;
      /* Si le nouveau nombre est inferieur au precedent, on change la valeur de minStep */
      if (minStep > temp) minStep = temp;
  }
  /*fprintf(stderr,"minStep returned %d\n",(int)minStep);*/
  return (int)minStep;
}
void printSpecies(Model_t *m, FILE *f)
{
  int i, j;
  Species_t *s;  
  Compartment_t *c;

  fprintf(f, "\n");
  fprintf(f, "# Initial Conditions for Species and Compartments:\n");
  for ( i=0; i<Model_getNumCompartments(m); i++ ) {
    if ( i== 0 ) fprintf(f, "# Compartments:\n");
    c = Model_getCompartment(m,i);
    if(Compartment_isSetId(c))
      fprintf(f, "%s ", Compartment_getId(c));
    if(Compartment_isSetName(c))
      fprintf(f, "(%s) ", Compartment_getName(c));
    if ( Compartment_isSetVolume(c) )
     fprintf(f, "= %g; ", Compartment_getSize(c));
    fprintf(f, "%s", Compartment_getConstant(c) ? "" : "variable; ");
    if(Compartment_isSetOutside(c))
      fprintf(f, "outside %s; ", Compartment_getOutside(c));
   /*  fprintf(f, "\n"); */
    fprintf(f, "dimensions %d; ", Compartment_getSpatialDimensions(c));

    if(Compartment_isSetUnits(c))
      fprintf(f, "[%s]; ", Compartment_getUnits(c));
    fprintf(f, "\n");
    
    fprintf(f, "# Species concentrations in `compartment' %s\n",
	   Compartment_getId(c));
    for(j=0;j<Model_getNumSpecies(m);j++){
      s = Model_getSpecies(m,j);      
      if(strcmp(Species_getCompartment(s), Compartment_getId(c))==0){  

	fprintf(f, "%s ", Species_getId(s));
	if(Species_isSetName(s))
	  fprintf(f, "(%s) ", Species_getName(s));
	
	if ( Species_isSetInitialAmount(s) )
	  fprintf(f, "= %g/%g; ",
		 Species_getInitialAmount(s),
		 Compartment_getSize(c));
	else if ( Species_isSetInitialConcentration(s) )
	  fprintf(f, "= %g; ", Species_getInitialConcentration(s));
	else
	  fprintf(f, "# no initial value;");	
	fprintf(f, "%s", Species_getBoundaryCondition(s) ? "boundary;" : "");
	fprintf(f, "%s", Species_getConstant(s) ? "constant;" : "");
	if(Species_isSetCharge(s))
	  fprintf(f, "charge = %d; ", Species_getCharge(s));

	fprintf(f, "\n");
      }     
    }
    fprintf(f, "\n");  
  }  
}
Esempio n. 10
0
END_TEST


START_TEST (test_L3_Species_id)
{
  const char *id = "mitochondria";


  fail_unless( !Species_isSetId(S) );
  
  Species_setId(S, id);

  fail_unless( !strcmp(Species_getId(S), id) );
  fail_unless( Species_isSetId(S) );

  if (Species_getId(S) == id)
  {
    fail("Species_setId(...) did not make a copy of string.");
  }
}
Esempio n. 11
0
END_TEST


START_TEST (test_L3_Species_createWithNS )
{
  XMLNamespaces_t *xmlns = XMLNamespaces_create();
  XMLNamespaces_add(xmlns, "http://www.sbml.org", "testsbml");
  SBMLNamespaces_t *sbmlns = SBMLNamespaces_create(3,1);
  SBMLNamespaces_addNamespaces(sbmlns,xmlns);

  Species_t *s = 
    Species_createWithNS (sbmlns);


  fail_unless( SBase_getTypeCode  ((SBase_t *) s) == SBML_SPECIES );
  fail_unless( SBase_getMetaId    ((SBase_t *) s) == NULL );
  fail_unless( SBase_getNotes     ((SBase_t *) s) == NULL );
  fail_unless( SBase_getAnnotation((SBase_t *) s) == NULL );

  fail_unless( SBase_getLevel       ((SBase_t *) s) == 3 );
  fail_unless( SBase_getVersion     ((SBase_t *) s) == 1 );

  fail_unless( Species_getNamespaces     (s) != NULL );
  fail_unless( XMLNamespaces_getLength(Species_getNamespaces(s)) == 2 );


  fail_unless( Species_getId     (s) == NULL );
  fail_unless( Species_getName   (s) == NULL );
  fail_unless( Species_getCompartment  (s) == NULL );
  fail_unless( util_isNaN(Species_getInitialAmount (s)) );
  fail_unless( util_isNaN(Species_getInitialConcentration (s)) );
  fail_unless( Species_getSubstanceUnits  (s) == NULL );
  fail_unless( Species_getHasOnlySubstanceUnits(s) == 0   );
  fail_unless( Species_getBoundaryCondition(s) == 0   );
  fail_unless( Species_getConstant(s) == 0   );
  fail_unless( Species_getConversionFactor  (s) == NULL );

  fail_unless( !Species_isSetId     (s) );
  fail_unless( !Species_isSetName   (s) );
  fail_unless( !Species_isSetCompartment (s) );
  fail_unless( !Species_isSetInitialAmount (s) );
  fail_unless( !Species_isSetInitialConcentration (s) );
  fail_unless( !Species_isSetSubstanceUnits  (s) );
  fail_unless( !Species_isSetHasOnlySubstanceUnits(s)   );
  fail_unless( !Species_isSetBoundaryCondition(s)   );
  fail_unless( !Species_isSetConstant(s)   );
  fail_unless( !Species_isSetConversionFactor  (s) );

  Species_free(s);
  XMLNamespaces_free(xmlns);
  SBMLNamespaces_free(sbmlns);
}
Esempio n. 12
0
/**
 * \fn void SBML_initEspeceAmounts(Model_t *mod, pEspeces molecules, int nbEspeces)
 * \author Amine Ghozlane
 * \brief  Alloc memory and initialize the struct Especes
 * \param  mod Model of the SBML file
 * \param  molecules Struct Especes
 * \param  nbEspeces Number of molecules
 */
void SBML_initEspeceAmounts(Model_t *mod, pEspeces molecules, int nbEspeces)
{
  /* Initialisation de l'etat des especes */
  int i;
  Species_t *esp=NULL;

  /* Initialisation des quantites des especes*/
  for (i = 0; i < nbEspeces; i++) {
      esp = Model_getSpecies(mod, i);
      Especes_save(molecules, i, Species_getInitialAmount(esp),
          Species_getId(esp));
  }
}
Esempio n. 13
0
void post_ev_alter_tree_structure(Model_t *m, ASTNode_t **node_p, ASTNode_t *parent, int child_order){
  ASTNode_t *divide_node, *times_node;
  ASTNode_t *compartment_node;
  ASTNode_t *node, *next_node;
  unsigned int i;
  Species_t *sp;

  node = *node_p;
  for(i=0; i<ASTNode_getNumChildren(node); i++){
    next_node = ASTNode_getChild(node, i);
    post_ev_alter_tree_structure(m, &next_node, *node_p, i);
  }
  if(ASTNode_getType(node) == AST_NAME){
    for(i=0; i<Model_getNumSpecies(m); i++){
      sp = (Species_t*)ListOf_get(Model_getListOfSpecies(m), i);
      if(strcmp(Species_getId(sp), ASTNode_getName(node)) == 0){
        if(!Species_getHasOnlySubstanceUnits(sp) && Compartment_getSpatialDimensions(Model_getCompartmentById(m, Species_getCompartment(sp))) != 0){/* use val/comp in calculation */
          divide_node = ASTNode_createWithType(AST_DIVIDE);
          compartment_node = ASTNode_createWithType(AST_NAME);
          ASTNode_setName(compartment_node, Compartment_getId(Model_getCompartmentById(m, Species_getCompartment(sp))));
          ASTNode_addChild(divide_node, node);
          ASTNode_addChild(divide_node, compartment_node);
          if(parent != NULL){
            ASTNode_replaceChild(parent, child_order, divide_node);
          }else{
            *node_p = divide_node;
          }
          node = *node_p;
          break;
        }else if(Species_getHasOnlySubstanceUnits(sp) && Species_isSetInitialConcentration(sp) && Compartment_getSpatialDimensions(Model_getCompartmentById(m, Species_getCompartment(sp))) != 0){/*  use val*comp in calculation */
          times_node = ASTNode_createWithType(AST_TIMES);
          compartment_node = ASTNode_createWithType(AST_NAME);
          ASTNode_setName(compartment_node, Compartment_getId(Model_getCompartmentById(m, Species_getCompartment(sp))));
          ASTNode_addChild(times_node, node);
          ASTNode_addChild(times_node, compartment_node);
          if(parent != NULL){
            ASTNode_replaceChild(parent, child_order, times_node);
          }else{
            *node_p = times_node;
          }
          node = *node_p;
          break;
        }
      }
    }
  }
  return;
}
END_TEST


START_TEST (test_Species_setId3)
{
  Species_t *c = 
    Species_create(2, 2);

  int i = Species_setId(c, "cell");

  fail_unless( i == LIBSBML_OPERATION_SUCCESS );
  fail_unless( Species_isSetId(c) );
  fail_unless( !strcmp(Species_getId(c), "cell" ));

  Species_free(c);
}
Esempio n. 15
0
/**
 * \fn void SBML_setReactions(Model_t *mod, pEspeces molecules, pScore result, double *reactions_ratio, int nbReactions, int nbEspeces)
 * \author Amine Ghozlane
 * \brief  Alloc memory and initialize the struct Especes
 * \param  mod Model of the SBML file
 * \param  molecules Struct Especes
 * \param  result Struct Score
 * \param  reactions_ratio List of computed reaction ratio
 * \param  nbReactions Number of reaction
 * \param  nbEspeces Number of molecules
 */
void SBML_setReactions(Model_t *mod, pEspeces molecules, pScore result, double *reactions_ratio, int nbReactions, int nbEspeces)
{
  /* Initialisation les reactions auquelles participent chaque espece */
  int ref = 0, i, j, resultat=OK;
  SpeciesReference_t *reactif=NULL;
  Species_t *especeId=NULL;
  Reaction_t *react=NULL;
  const char *kf=NULL;
  /*const ASTNode_t *km;*/
  KineticLaw_t *kl=NULL;

  /* Recherche les reactions ou apparaissent chaque espece */
  for (i = 0; i < nbReactions; i++) {
      react = Model_getReaction(mod, i);
      /* Recherche si la reaction est etudiee */
      resultat = SBML_findReaction(result->reaction,Reaction_getId(react), result->nb_reaction);
      /* Etude des reactifs */
      for (j = 0; j < (int)Reaction_getNumReactants(react); j++) {
          /* Recuperation d'un reactif */
          reactif = Reaction_getReactant(react, j);
          /* Recuperation du nom de l'espece */
          especeId = Model_getSpeciesById(mod, SpeciesReference_getSpecies(reactif));
          /* Recherche la reference de cette molecule dans la struture molecule */
          ref = Especes_find(molecules, Species_getId(especeId), nbEspeces);
          /* Recuperation de la loi cinetique sur la */
          kl = Reaction_getKineticLaw(react);
          /* Reaction dont on recherche le bon ratio */
          if(resultat!=OK){
              Especes_allocReactions(molecules, ref, react, reactions_ratio[resultat]);
          }
          /* Si la loi cinetique est au format : formule on recupere le ratio en question */
          else if (KineticLaw_isSetFormula(kl)) {
              kf = KineticLaw_getFormula(kl);
              Especes_allocReactions(molecules, ref, react, SBML_evalExpression(kf));
          } else { /* Sinon on n'utilise pas ces informations */
              /*km = KineticLaw_getMath(kl);*/
              fprintf(stderr,"SBML equation are taken into account, use instead the parameter file\n");
              /*exit(EXIT_FAILURE);*/
          }
      }
  }
}
Esempio n. 16
0
void print_result_list(Model_t *m, mySpecies *mySp[], myParameter *myParam[], myCompartment *myComp[]){
  FILE *fp = NULL;
  unsigned int i;
  int column = 2;
  if ((fp = my_fopen(fp, "./simulation_results/result_list.dat", "w")) == NULL) {
    return;
  }
  TRACE(("Result : Species List\n"));
  fprintf(fp, "Result : Species List\n");
  for(i=0; i<Model_getNumSpecies(m); i++){
    /*     if(!(Species_getConstant(mySp[i]->origin) && Species_getBoundaryCondition(mySp[i]->origin))){ //XXX must remove this */
    fprintf(fp, "column %d : ID=%s Name=%s\n", column, Species_getId(mySp[i]->origin), Species_getName(mySp[i]->origin));
    column++;
    /*    } */
  }
  TRACE(("\n"));
  fprintf(fp, "\n");
  fprintf(fp, "Result : Parameter List\n");
  column = 2;
  for(i=0; i<Model_getNumParameters(m); i++){
    /*     if(!Parameter_getConstant(myParam[i]->origin)){ //XXX must remove this */
    TRACE(("column %d : ID=%s Name=%s\n", column, Parameter_getId(myParam[i]->origin), Parameter_getName(myParam[i]->origin)));
    fprintf(fp, "column %d : ID=%s Name=%s\n", column, Parameter_getId(myParam[i]->origin), Parameter_getName(myParam[i]->origin));
    column++;
    /*     } */
  }
  TRACE(("Result : Compartment List\n"));
  fprintf(fp, "Result : Compartment List\n");
  column = 2;
  for(i=0; i<Model_getNumCompartments(m); i++){
    /*     if(!Compartment_getConstant(myComp[i]->origin)){ //XXX must remove this */
    TRACE(("column %d : ID=%s Name=%s\n", column, Compartment_getId(myComp[i]->origin), Compartment_getName(myComp[i]->origin)));
    fprintf(fp, "column %d : ID=%s Name=%s\n", column, Compartment_getId(myComp[i]->origin), Compartment_getName(myComp[i]->origin));
    column++;
    /*     } */
  }
  fclose(fp);
}
Esempio n. 17
0
void myRule_initTarget(
    myRule *rule,
    mySpecies **species, unsigned int num_of_species,
    myParameter **parameters, unsigned int num_of_parameters,
    myCompartment **compartments, unsigned int num_of_compartments,
    myReaction **reactions, unsigned int num_of_reactions) {
  unsigned int i, j;
  Rule_t *origin;
  const char *origin_var;
  mySpecies *sp;
  myParameter *param;
  myCompartment *comp;
  myReaction *re;
  mySpeciesReference *product, *reactant;

  origin = myRule_getOrigin(rule);
  origin_var = Rule_getVariable(origin);

  for (i = 0; i < num_of_species; i++) {
    sp = species[i];
    if (strcmp(origin_var, Species_getId(sp->origin)) == 0) {
      myRule_setTargetSpecies(rule, sp);
      mySpecies_setDependingRule(sp, rule);
      return;
    }
  }

  for (i = 0; i < num_of_parameters; i++) {
    param = parameters[i];
    if (strcmp(origin_var, Parameter_getId(param->origin)) == 0) {
      myRule_setTargetParameter(rule, param);
      myParameter_setDependingRule(param, rule);
      return;
    }
  }

  for (i = 0; i < num_of_compartments; i++) {
    comp = compartments[i];
    if (strcmp(origin_var, Compartment_getId(comp->origin)) == 0) {
      myRule_setTargetCompartment(rule, comp);
      myCompartment_setDependingRule(comp, rule);
      return;
    }
  }

  for (i=0; i < num_of_reactions; i++) {
    re = reactions[i];

    for (j = 0; j < re->num_of_products; j++) {
      product = re->products[j];
      if (SpeciesReference_isSetId(product->origin)
          && strcmp(origin_var, SpeciesReference_getId(product->origin)) == 0) {
        myRule_setTargetSpeciesReference(rule, product);
        mySpeciesReference_setDependingRule(product, rule);
        return;
      }
    }

    for (j = 0; j < re->num_of_reactants; j++) {
      reactant = re->reactants[j];
      if (SpeciesReference_isSetId(reactant->origin)
          && strcmp(origin_var, SpeciesReference_getId(reactant->origin)) == 0) {
        myRule_setTargetSpeciesReference(rule, reactant);
        mySpeciesReference_setDependingRule(reactant, rule);
        return;
      }
    }
  }
}
Esempio n. 18
0
int main(int argc, char** argv)
{
    myspecies_t* species;	//pinakas ximikon stoixeion
    reaction_t *reaction;	//20 ximikes antidraseis
    int i,j,k,num_species, num_reactions;
    double V;
    FILE *pf1, *pf2, *pf3, *pf4, *pf5, *pf6, *fsize;

    SBMLDocument_t *d;
    Model_t        *m;
    ListOf_t    *lo;
    Species_t   *sp;
    Reaction_t  *re;
    Parameter_t *p;
    KineticLaw_t *kin;
    SpeciesReference_t *sr;
    Compartment_t *c;

	//an den exei 2 argument
	if(argc != 2)
    {
        printf("Ektelesi: %s <SBML xml>\n", argv[0]);
        exit(-1);
    }

    //arxeia results
    if((pf1 = fopen("RT_reactant.txt", "w")) == NULL)
    {
        printf("Error create file %s\n","RT_reactant.txt");
        exit(-1);
    }
    
    if((pf2 = fopen("RT_product.txt", "w")) == NULL)
    {
        printf("Error create file %s\n","RT_product.txt");
        fclose(pf1);
        exit(-1);
    }
    
    if((pf3 = fopen("VT_reactant.txt", "w")) == NULL)
    {
        printf("Error create file %s\n","VT_reactant.txt");
        fclose(pf1);
        fclose(pf2);
        exit(-1);
    }
    
    if((pf4 = fopen("VT_product.txt", "w")) == NULL)
    {
        printf("Error create file %s\n","VT_product.txt");
        fclose(pf1);
        fclose(pf2);
        fclose(pf3);
        exit(-1);
    }
    
    if((pf5 = fopen("ST.txt", "w")) == NULL)
    {
        printf("Error create file %s\n","ST.txt");
        fclose(pf1);
        fclose(pf2);
        fclose(pf3);
        fclose(pf4);
        exit(-1);
    }
    
    if((pf6 = fopen("k_parameter.txt", "w")) == NULL)
    {
        printf("Error create file %s\n","k_parameter.txt");
        fclose(pf1);
        fclose(pf2);
        fclose(pf3);
        fclose(pf4);
        fclose(pf5);
        exit(-1);
    }

    fsize = fopen("fsize.txt", "w");

    //anoigo to SBML arxeio
    d = readSBML(argv[1]);
    //d=readSBML("C:/home/orsalia/BIOMD0000000001");
    m = SBMLDocument_getModel(d);
    num_species = Model_getNumSpecies(m);
    num_reactions = Model_getNumReactions(m);

    fprintf(fsize,"%d\n",num_species);
    fprintf(fsize,"%d\n",num_reactions);
    
    //Pairnoume ton ogko
    c = Model_getCompartment(m,0);
    V = Compartment_getVolume(c);


    //Desmeysi pinakon domon gia stoixeia kai reaction
    species =  (myspecies_t*) malloc(num_species*sizeof(myspecies_t));
    reaction = (reaction_t*) malloc(num_reactions*sizeof(reaction_t));

    //gemizo ton pinaka me tis arxikes sigkentroseis ton stoixeion
    for(i=0;i<num_species;i++)
    {
        sp = Model_getSpecies(m,i);
        species[i].conc = Species_getInitialConcentration(sp)?Species_getInitialConcentration(sp):Species_getInitialAmount(sp);
        species[i].name = malloc(50*sizeof(char));
        strcpy(species[i].name,Species_getId(sp));
        strcpy(species[i].name2,Species_getName(sp));
    }

    ///gemizo ton pinaka domon ton reaction
    for(i=0;i<num_reactions;i++)
    {
        re = Model_getReaction(m,i);
        kin = Reaction_getKineticLaw(re);
        p = KineticLaw_getParameter(kin,0);

        reaction[i].react_num = Reaction_getNumReactants(re);
        reaction[i].product_num = Reaction_getNumProducts(re);
        reaction[i].react = (x_vector_t*) malloc(reaction[i].react_num*sizeof(x_vector_t));
        reaction[i].product = (x_vector_t*) malloc(reaction[i].product_num*sizeof(x_vector_t));

		for(j=0;j<reaction[i].react_num;j++)
        {
            sr = Reaction_getReactant(re,j);

            for(k=0;k<num_species;k++)
            {
                //an vrei to stoixeio ston megalo pinaka krata ti thesi tou
                if (strcmp(SpeciesReference_getSpecies(sr),species[k].name) == 0)
                {
                    reaction[i].react[j].x = k;		//ithesi ston pinaka species
                    reaction[i].react[j].v = (-1) * SpeciesReference_getStoichiometry(sr);
                    break;
                }
            }
        }
        
        for(j=0;j<reaction[i].product_num;j++)
        {
            sr = Reaction_getProduct(re,j);

            for(k=0;k<num_species;k++)
            {
                //an vrei to stoixeio ston megalo pinaka krata ti thesi tou
                if (strcmp(SpeciesReference_getSpecies(sr),species[k].name) == 0)
                {
                    reaction[i].product[j].x = k;	//ithesi ston pinaka species
                    reaction[i].product[j].v = SpeciesReference_getStoichiometry(sr);
                    break;
                }
            }
        }
        
        reaction[i].k = Parameter_getValue(p);

        //vlepo tin eidos antidraseis einai kai vazo to c tis kathe antidrasis
        if(reaction[i].react_num == 3)
        {
        	reaction[i].type = 7;
            reaction[i].c = Parameter_getValue(p)/(V*V);	//mallon
        }
        else if(reaction[i].react_num == 2)
        {	
          	sr = Reaction_getReactant(re,0);
          	
          	if (SpeciesReference_getStoichiometry(sr) == 2 )
        	{
        		reaction[i].type = 5;
            	reaction[i].c = 2*Parameter_getValue(p)/(V*V);	//oute kan
        	}
        	else
        	{
        		sr = Reaction_getReactant(re,1);
        	
        		if (SpeciesReference_getStoichiometry(sr) == 2 )
		    	{
		    		reaction[i].type = 6;
		        	reaction[i].c = 2*Parameter_getValue(p)/(V*V);	//oute kan
		    	}
		    	else
		    	{
		    		reaction[i].type = 2;
		        	reaction[i].c = Parameter_getValue(p)/V;	
		    	}
		    }
            
        }
        else //if(reaction[i].react_num == 1)
        {	
        	sr = Reaction_getReactant(re,0);
        	
            if (SpeciesReference_getStoichiometry(sr) == 2 )		//an einai bimolecular me to idio stoixeio
            {
                reaction[i].type = 3;
                reaction[i].c = 2*Parameter_getValue(p)/V;
            }
            else if(SpeciesReference_getStoichiometry(sr) == 3 )
            {
            	reaction[i].type = 4;
                reaction[i].c = 3*Parameter_getValue(p)/(V*V);	//mallon
            }
            else 
            {
                reaction[i].type = 1;
            	reaction[i].c = Parameter_getValue(p);
            }
        }
    }

	for(i=0;i<num_species;i++)
	{
		//fprintf(pf5,"%d\t%s\n",(int)species[i].conc,species[i].name2);
		fprintf(pf5,"%d\t\n",(int)species[i].conc);
	}

	for(i=0;i<num_reactions;i++)
	{
		for(k=0;k<reaction[i].react_num;k++)
		{
			fprintf(pf1,"%d\t",reaction[i].react[k].x+1);
			fprintf(pf3,"%d\t",reaction[i].react[k].v);
		}
		
		for(k=0;k<reaction[i].product_num;k++)
		{
			fprintf(pf2,"%d\t",reaction[i].product[k].x+1);
			fprintf(pf4,"%d\t",reaction[i].product[k].v);
		}

		fprintf(pf1,"\n");
		fprintf(pf3,"\n");
		fprintf(pf2,"\n");
		fprintf(pf4,"\n");
		
		fprintf(pf6,"%f\n",reaction[i].k);
		
		
		
	}
	
	
    fclose(pf1);
    fclose(pf2);
    fclose(pf3);
    fclose(pf4);
    fclose(pf5);
    fclose(pf6);
    fclose(fsize);

}
Esempio n. 19
0
/*
  setValues: the user can enter a species name and
  change its initial condition (amount or concentration)
*/
static void setValues(Model_t *m) {

  char *species;
  char *newIA;
  char *newIC;
  Species_t *s;

  printf("Please enter the id of the species to change: ");
  species = get_line(stdin);
  species = util_trim(species);
  
  if ( (s = Model_getSpeciesById(m,species) ) ) {      
    printf("\n");
    printf("Id:                    %s\n", Species_getId(s));
    if ( Species_isSetName(s) ) {
      printf("Name:                  %s\n", Species_getName(s));
    }
    if ( Species_isSetInitialAmount(s) ) {
      printf("Initial Amount:        %g", Species_getInitialAmount(s));
    }
    else if (Species_isSetInitialConcentration(s) ) {
      printf("Initial Concentration: %g", Species_getInitialConcentration(s));
    }
   

    if ( Species_getHasOnlySubstanceUnits(s) ) {
      if ( Species_isSetSubstanceUnits(s) ) {
	printf("%s ", Species_getSubstanceUnits(s));
      }
    } else {
      if ( Species_isSetSubstanceUnits(s) ) {
	printf("%s ", Species_getSubstanceUnits(s));
      }
      if ( Species_isSetSpatialSizeUnits(s) ) {
	printf("%s%s", "/", Species_getSpatialSizeUnits(s));
      }
    }
    if ( Species_getHasOnlySubstanceUnits(s) ) {
	printf(" (has only substance units)");
    }
    printf("\n");
    if ( Species_isSetCharge(s) ) {
      printf("Charge: %-10d", Species_getCharge(s));
    }
    printf("\n");   
    printf("%s       ", Species_getBoundaryCondition(s) ?
	   "Species is a Boundary\n" : "\n");
    printf("%s       ", Species_getConstant(s) ?
	   "Species is set constant" : "\n");
    printf("\n");
   
    if ( Species_isSetInitialAmount(s) ) {
      printf("Please enter new initial Amount: ");
      newIA = get_line(stdin);
      newIA = util_trim(newIA);
      Species_setInitialAmount(s, (float) atof(newIA));
    }
    else if ( Species_isSetInitialConcentration(s) ) {
      printf("Please enter new initial Concentration: ");
      newIC = get_line(stdin);
      newIC = util_trim(newIC);
      Species_setInitialConcentration(s, (float) atof(newIC));
    }
  }
  else {
    printf("%s not found.\n", species);
  }
  
}
Esempio n. 20
0
SBML_ODESOLVER_API int drawModel(Model_t *m, char* file, char *format) {
  
#if !USE_GRAPHVIZ

  SolverError_error(
		    WARNING_ERROR_TYPE,
		    SOLVER_ERROR_NO_GRAPHVIZ,
		    "odeSolver has been compiled without GRAPHIZ functionality. ",
		    "Graphs are printed to stdout in the graphviz' .dot format.");
  drawModelTxt(m, file);
  
#else

  GVC_t *gvc;
  Agraph_t *g;
  Agnode_t *r;
  Agnode_t *s;  
  Agedge_t *e;
  Agsym_t *a;
  Species_t *sp;
  Reaction_t *re;
  const ASTNode_t *math;  
  SpeciesReference_t *sref;
  ModifierSpeciesReference_t *mref;
  char *output[4];
  char *command = "dot";
  char *formatopt;
  char *outfile;
  int i,j;
  int reversible;
  char name[WORDSIZE];
  char label[WORDSIZE];

  /* setting name of outfile */
  ASSIGN_NEW_MEMORY_BLOCK(outfile, strlen(file)+ strlen(format)+7, char, 0);
  sprintf(outfile, "-o%s_rn.%s", file, format);

  /* setting output format */
  ASSIGN_NEW_MEMORY_BLOCK(formatopt, strlen(format)+3, char, 0);
  sprintf(formatopt, "-T%s", format);

  /* construct command-line */
  output[0] = command;
  output[1] = formatopt;
  output[2] = outfile;
  output[3] = NULL;

  /* set up renderer context */
  gvc = (GVC_t *) gvContext();
#if GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION < 4
  dotneato_initialize(gvc, 3, output);
#elif GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION == 4
  parse_args(gvc, 3, output);
#elif GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION >= 6 || GRAPHVIZ_MAJOR_VERSION >= 3
  gvParseArgs(gvc, 3, output);  
#endif  

  g = agopen("G", AGDIGRAPH);
  
  /* avoid overlapping nodes, for graph embedding by neato */ 
  a = agraphattr(g, "overlap", "");
  agxset(g, a->index, "scale");

  for ( i=0; i<Model_getNumReactions(m); i++ ) {

    re = Model_getReaction(m,i);
    reversible = Reaction_getReversible(re);
    sprintf(name, "%s", Reaction_getId(re));
    r = agnode(g,name);
    a = agnodeattr(g, "shape", "ellipse");    
    agxset(r, a->index, "box");
    
    sprintf(label, "%s", Reaction_isSetName(re) ?
	    Reaction_getName(re) : Reaction_getId(re));
    agset(r, "label", label);
    
    sprintf(label, "%s.htm", Reaction_getId(re));
    a = agnodeattr(g, "URL", "");
    agxset(r, a->index, label);
    
    for ( j=0; j<Reaction_getNumModifiers(re); j++ ) {

      mref = Reaction_getModifier(re,j);
      sp = Model_getSpeciesById(m, ModifierSpeciesReference_getSpecies(mref));
      
      sprintf(name,"%s", Species_getId(sp));
      s = agnode(g,name);
      sprintf(label, "%s", Species_isSetName(sp) ? 
	      Species_getName(sp) : Species_getId(sp));
      agset(s, "label", label);

      if ( Species_getBoundaryCondition(sp) ) {
	a = agnodeattr(g, "color", "");
	agxset(s, a->index, "blue");
      }
      if ( Species_getConstant(sp) ) {
	a = agnodeattr(g, "color", "");
	agxset(s, a->index, "green4");
      }

      sprintf(label, "%s.htm", Species_getId(sp));
      a = agnodeattr(g, "URL", "");
      agxset(s, a->index, label);
	
      e = agedge(g,s,r);
      a = agedgeattr(g, "style", "");
      agxset(e, a->index, "dashed");
      a = agedgeattr(g, "arrowhead", "");
      agxset(e, a->index, "odot");
    }

    for ( j=0; j<Reaction_getNumReactants(re); j++ ) {

      sref = Reaction_getReactant(re,j);
      sp = Model_getSpeciesById(m, SpeciesReference_getSpecies(sref));
      
      sprintf(name,"%s", Species_getId(sp));
      s = agnode(g, name);
      sprintf(label, "%s", Species_isSetName(sp) ? 
	      Species_getName(sp) : Species_getId(sp));
      agset(s, "label", label);

      if ( Species_getBoundaryCondition(sp) ) {
	a = agnodeattr(g, "color", "");
	agxset(s, a->index, "blue");
      }
      if ( Species_getConstant(sp) ) {
	a = agnodeattr(g, "color", "");
	agxset(s, a->index, "green4");
      }

      sprintf(label, "%s.htm", Species_getId(sp));
      a = agnodeattr(g, "URL", "");
      agxset(s, a->index, label);
      
      e = agedge(g,s,r);
      a = agedgeattr(g, "label", "");
      
      if ( (SpeciesReference_isSetStoichiometryMath(sref)) ) {
	math = SpeciesReference_getStoichiometryMath(sref);
	if ( (strcmp(SBML_formulaToString(math),"1") !=
	      0) ) {
	  agxset (e, a->index, SBML_formulaToString(math));
	}
      }
      else {
	if ( SpeciesReference_getStoichiometry(sref) != 1 ) {
	  sprintf(name, "%g", SpeciesReference_getStoichiometry(sref));
	  agxset (e, a->index, name);
	}
      }
      if ( reversible == 1 ) {
	a = agedgeattr(g, "arrowtail", "");
	agxset(e, a->index, "onormal");
      }      
    }
    
    for ( j=0; j<Reaction_getNumProducts(re); j++ ) {
      sref = Reaction_getProduct(re,j);
      sp = Model_getSpeciesById(m, SpeciesReference_getSpecies(sref));
      sprintf(name,"%s", Species_getId(sp));
      s = agnode(g,name);
      sprintf(label, "%s", Species_isSetName(sp) ? 
	      Species_getName(sp) : Species_getId(sp));
      agset(s, "label", label);

      if ( Species_getBoundaryCondition(sp) ) {
	a = agnodeattr(g, "color", "");
	agxset(s, a->index, "blue");
      }
      if ( Species_getConstant(sp) ) {
	a = agnodeattr(g, "color", "");
	agxset(s, a->index, "green4");
      }

      sprintf(label, "%s.htm", Species_getId(sp));
      a = agnodeattr(g, "URL", "");
      agxset(s, a->index, label);
            
      e = agedge(g,r,s);
      a = agedgeattr(g, "label", "");
      if ( SpeciesReference_isSetStoichiometryMath(sref) ) {
	math = SpeciesReference_getStoichiometryMath(sref);
	if ( (strcmp(SBML_formulaToString(math),"1") !=
	      0) ) {
	  agxset (e, a->index, SBML_formulaToString(math));
	}
      }
      else {
	if ( SpeciesReference_getStoichiometry(sref) != 1 ) {
	  sprintf(name, "%g",SpeciesReference_getStoichiometry(sref));
	  agxset (e, a->index,name);
	}
      }
      if ( reversible == 1 ) {
	a = agedgeattr(g, "arrowtail", "");
	agxset(e, a->index, "onormal");
      }      
    }   
  }

  /* Compute a layout */
#if GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION <= 2
  gvBindContext(gvc, g);
  dot_layout(g);
#elif GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION == 4
  gvlayout_layout(gvc, g);
#elif GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION >= 6 || GRAPHVIZ_MAJOR_VERSION >= 3
  gvLayoutJobs(gvc, g);
#endif

  /* Write the graph according to -T and -o options */
#if GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION <= 2
  dotneato_write(gvc);
#elif GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION == 4
  emit_jobs(gvc, g);
#elif GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION >= 6 || GRAPHVIZ_MAJOR_VERSION >= 3
  gvRenderJobs(gvc, g);
#endif
  
  /* Clean out layout data */
#if GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION <= 2
  dot_cleanup(g);
#elif GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION == 4
  gvlayout_cleanup(gvc, g);
#elif GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION >= 6 || GRAPHVIZ_MAJOR_VERSION >= 3
  gvFreeLayout(gvc, g);
#endif
  
  /* Free graph structures */
#if GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION <= 2
  dot_cleanup(g);
#else
  agclose(g);
#endif

  /* Clean up output file and errors */
#if GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION <= 2
  gvFREEcontext(gvc);
  dotneato_eof(gvc);
#elif GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION == 4
  dotneato_terminate(gvc);
#elif GRAPHVIZ_MAJOR_VERSION == 2 && GRAPHVIZ_MINOR_VERSION >= 6 || GRAPHVIZ_MAJOR_VERSION >= 3
  gvFreeContext(gvc); 
#endif  

  xfree(formatopt);  
  xfree(outfile);
  
#endif
  
  return 1;

}
Esempio n. 21
0
static int
drawModelTxt(Model_t *m, char *file) {

  Species_t *s;
  Reaction_t *re;
  const ASTNode_t *math;
  SpeciesReference_t *sref;
  ModifierSpeciesReference_t *mref;
  int i,j;
  int reversible;
  char filename[WORDSIZE];
  FILE *f;
  
  sprintf(filename, "%s.dot", file);
  f = fopen(filename, "w");

  fprintf(f ,"digraph reactionnetwork {\n");
  fprintf(f ,"label=\"%s\";\n",
	  Model_isSetName(m) ?
	  Model_getName(m) : (Model_isSetId(m) ? Model_getId(m) : "noId") );
  fprintf(f ,"overlap=scale;\n");
 
  for ( i=0; i<Model_getNumReactions(m); i++ ) {
    
    re = Model_getReaction(m,i);
    reversible = Reaction_getReversible(re);
    
    for ( j=0; j<Reaction_getNumModifiers(re); j++ ) {
      mref = Reaction_getModifier(re,j);
      fprintf(f ,"%s->%s [style=dashed arrowhead=odot];\n",
	      ModifierSpeciesReference_getSpecies(mref), Reaction_getId(re));
    }
    for ( j=0; j<Reaction_getNumReactants(re); j++ ) {
      sref = Reaction_getReactant(re,j);
      fprintf(f ,"%s->%s [label=\"",
	      SpeciesReference_getSpecies(sref), Reaction_getId(re));
      
      if ( (SpeciesReference_isSetStoichiometryMath(sref)) ) {
	math = SpeciesReference_getStoichiometryMath(sref);
	if ( (strcmp(SBML_formulaToString(math),"1") !=
	      0) ) {
	  fprintf(f ,"%s", SBML_formulaToString(math));
	}	
      }
      else {
	if ( SpeciesReference_getStoichiometry(sref) != 1) {
	  fprintf(f ,"%g",SpeciesReference_getStoichiometry(sref));
	}
      }
      if ( reversible == 1 ) {
	fprintf(f ,"\" arrowtail=onormal];\n");
      }
      else {
	fprintf(f ,"\" ];\n");
      }
    }
    for ( j=0; j<Reaction_getNumProducts(re); j++ ) {
      sref = Reaction_getProduct(re,j);
      fprintf(f ,"%s->%s [label=\"",
	      Reaction_getId(re), SpeciesReference_getSpecies(sref));
      if ( (SpeciesReference_isSetStoichiometryMath(sref)) ) {
	math = SpeciesReference_getStoichiometryMath(sref);
	if ( (strcmp(SBML_formulaToString(math),"1") !=
	      0) ) {
	  fprintf(f ,"%s ", SBML_formulaToString(math));
	}
      }
      else {
	if ( SpeciesReference_getStoichiometry(sref) != 1) {
	  fprintf(f ,"%g ",SpeciesReference_getStoichiometry(sref));
	}
      }
      if ( reversible == 1 ) {
	fprintf(f ,"\" arrowtail=onormal];\n");
      }
      else {
	fprintf(f ,"\" ];\n");
      }    

    }
    
  }
  for ( i=0; i<Model_getNumReactions(m); i++ ) {
    re = Model_getReaction(m,i);
    fprintf(f ,"%s [label=\"%s\" shape=box];\n",
	    Reaction_getId(re),
	    Reaction_isSetName(re) ?
	    Reaction_getName(re) : Reaction_getId(re));
  }

  for ( i=0; i<Model_getNumSpecies(m); i++) {
    s = Model_getSpecies(m, i);
    fprintf(f ,"%s [label=\"%s\"];",
	    Species_getId(s),
	    Species_isSetName(s) ? Species_getName(s) : Species_getId(s));
  }  
  fprintf(f ,"}\n");
  return 1;
}
Esempio n. 22
0
int
main (int argc, char* argv[])
{
  unsigned int i,j,errors;
  const char* filename;
  SBMLDocument_t* document;
  Model_t* m;

  if (argc != 2)
  {
    printf("\nUsage: printNotes filename\n\n");
    return 1;
  }

  filename  = argv[1];
  document  = readSBML(filename);

  errors = SBMLDocument_getNumErrors( document);

  printf("\n%s\n\n", filename);

  if(errors > 0)
  {
    SBMLDocument_printErrors(document, stderr);
    SBMLDocument_free(document);
    return errors;
  }


  /* Model */

  m = SBMLDocument_getModel(document);
  printNotes((SBase_t*)m, Model_getId(m));

  for(i=0; i < Model_getNumReactions(m); i++)
  {
    Reaction_t* re = Model_getReaction( m, i);
    printNotes((SBase_t*)re, Reaction_getId(re));

    /* SpeciesReference (Reactant) */

    for(j=0; j < Reaction_getNumReactants( re); j++)
    {
      SpeciesReference_t* rt =  Reaction_getReactant(re, j);
      if (SBase_isSetNotes((SBase_t*) rt)) printf("   ");
      printNotes((SBase_t*)rt, SpeciesReference_getSpecies( rt ) );
    }

    /* SpeciesReference (Product) */

    for(j=0; j < Reaction_getNumProducts( re ); j++)
    {
      SpeciesReference_t* rt = Reaction_getProduct( re, j);
      if (SBase_isSetNotes((SBase_t*) rt)) printf("   ");
      printNotes((SBase_t*)rt, SpeciesReference_getSpecies( rt ) );
    }

    /* ModifierSpeciesReference (Modifiers) */

    for(j=0; j < Reaction_getNumModifiers( re ); j++)
    {
      SpeciesReference_t* md = Reaction_getModifier(re, j);
      if (SBase_isSetNotes((SBase_t*) md)) printf("   ");
      printNotes((SBase_t*)md, SpeciesReference_getSpecies( md ) );
    }

    /* KineticLaw */

    if(Reaction_isSetKineticLaw( re ))
    {
      KineticLaw_t* kl = Reaction_getKineticLaw( re );
      if (SBase_isSetNotes((SBase_t*) kl)) printf("   ");
      printNotes((SBase_t*)kl, "");

      /* Parameter */

      for(j=0; j < KineticLaw_getNumParameters( kl ); j++)
      {
        Parameter_t* pa = KineticLaw_getParameter( kl, j);
        if (SBase_isSetNotes((SBase_t*) pa)) printf("   ");
        printNotes((SBase_t*)pa, Parameter_getId(pa));
      }
    }

  }

  /* Species */

  for(i=0; i < Model_getNumSpecies(m); i++)
  {
    Species_t* sp = Model_getSpecies(m, i);
    printNotes((SBase_t*)sp, Species_getId(sp));
  }

  /* Compartments */

  for(i=0; i < Model_getNumCompartments( m ); i++)
  {
    Compartment_t* sp = Model_getCompartment(m, i);
    printNotes((SBase_t*)sp, Compartment_getId(sp));
  }

  /* FunctionDefinition */

  for(i=0; i < Model_getNumFunctionDefinitions(m); i++)
  {
    FunctionDefinition_t* sp = Model_getFunctionDefinition(m, i);
    printNotes((SBase_t*)sp, FunctionDefinition_getId(sp));
  }

  /* UnitDefinition */

  for(i=0; i < Model_getNumUnitDefinitions(m); i++)
  {
    UnitDefinition_t* sp = Model_getUnitDefinition( m, i);
    printNotes((SBase_t*)sp, UnitDefinition_getId(sp));
  }

  /* Parameter */

  for(i=0; i < Model_getNumParameters( m ); i++)
  {
    Parameter_t* sp = Model_getParameter( m, i);
    printNotes((SBase_t*)sp, Parameter_getId(sp));
  }

  /* Rule */

  for(i=0; i < Model_getNumReactions( m ); i++)
  {
    Rule_t* sp = Model_getRule(m, i);
    printNotes((SBase_t*)sp, "");
  }

  /* InitialAssignment */

  for(i=0; i < Model_getNumInitialAssignments(m); i++)
  {
    InitialAssignment_t* sp = Model_getInitialAssignment(m, i);
    printNotes((SBase_t*)sp, "");
  }

  /* Event */

  for(i=0; i < Model_getNumEvents(m); i++)
  {
    Event_t* sp = Model_getEvent(m, i);
    printNotes((SBase_t*)sp, Event_getId(sp));

    /* Trigger */

    if(Event_isSetTrigger( sp ))
    {
      Trigger_t* tg = Event_getTrigger(sp);
      if (SBase_isSetNotes( (SBase_t*) tg)) printf( "   " );
      printNotes((SBase_t*)tg, "");
    }

    /* Delay */

    if(Event_isSetDelay(sp))
    {
      Delay_t* dl = Event_getDelay(sp);
      if (SBase_isSetNotes( (SBase_t*) dl)) printf( "   " );
      printNotes((SBase_t*) dl, "");
    }

    /* EventAssignment */

    for(j=0; j < Event_getNumEventAssignments(sp); j++)
    {
      EventAssignment_t* ea = Event_getEventAssignment(sp, j);
      if (SBase_isSetNotes( (SBase_t*) ea)) printf( "   " );      
      printNotes((SBase_t*)ea, "");
    }
  }

  /* SpeciesType */

  for(i=0; i < Model_getNumSpeciesTypes(m); i++)
  {
    SpeciesType_t* sp = Model_getSpeciesType(m, i);
    printNotes((SBase_t*)sp, SpeciesType_getId(sp));
  }

  /* Constraints */

  for(i=0; i < Model_getNumConstraints(m); i++)
  {
    Constraint_t* sp = Model_getConstraint(m, i);
    printNotes((SBase_t*)sp, "");
  }

  SBMLDocument_free( document );
  return errors;
}