예제 #1
0
void
useStoichMath(Model & m, SpeciesReference &sr, bool isRule)
{
  // use stoichiometryMath instead
  StoichiometryMath *sm = sr.createStoichiometryMath();
  if (sm != NULL)
  {
    if (isRule == true)
    {
      sm->setMath(m.getRule(sr.getId())->getMath());
      m.removeRule(sr.getId());
    }
    else
    {
      sm->setMath(m.getInitialAssignment(sr.getId())->getMath());
      m.removeInitialAssignment(sr.getId());
    }
  }
}
예제 #2
0
void checkSpeciesRefs(Model* model, ListOfSpeciesReferences* losr, set<string>& components, set<string>& tests,  const map<string, vector<double> >& results)
{
  for (unsigned int rp=0; rp<losr->size(); rp++) {
    SpeciesReference* sr = static_cast<SpeciesReference*>(losr->get(rp));
    if (sr->isSetStoichiometry() && sr->getStoichiometry() != 1) {
      tests.insert("NonUnityStoichiometry");
    }
    if (sr->isSetStoichiometryMath()) {
      tests.insert("NonUnityStoichiometry");
      components.insert("StoichiometryMath");
      if (variesIn(sr->getStoichiometryMath()->getMath(), model, results)) {
        tests.insert("AssignedVariableStoichiometry");
      }
      else {
        tests.insert("AssignedConstantStoichiometry");
      }
    }
    else if (sr->isSetId()) {
      double initialResult = 1;
      if (results.find(sr->getId()) != results.end()) {
        tests.insert("SpeciesReferenceOutput");
      }
      if (variesIn(sr->getId(), model, results)) {
        tests.insert("AssignedVariableStoichiometry");
        tests.insert("NonUnityStoichiometry");
      }
      else if (initialOverriddenIn(sr->getId(), model, results, tests)) {
        tests.insert("AssignedConstantStoichiometry");
        if (getInitialResultFor(sr->getId(), results, initialResult)) {
          if (initialResult != 1) {
            tests.insert("NonUnityStoichiometry");
          }
        }
        else {
          //Don't know what the actual initial result is, so we'll assume it's not 1.0.
          tests.insert("NonUnityStoichiometry");
        }
      }
      if (initialOverriddenIn(sr->getId(), model, results, tests)) {
        tests.insert("InitialValueReassigned");
      }
      if (foundInMath(sr->getId(), model)) {
        tests.insert("SpeciesReferenceInMath");
      }
    }
  }
}
예제 #3
0
void
Model::convertStoichiometryMath()
{
  unsigned int n, j;
  Reaction * r;
  SpeciesReference *sr;
  unsigned int idCount = 0;
  char newid[15];
  std::string id;

  for (n = 0; n < getNumReactions(); n++)
  {
    r = getReaction(n);
    for (j = 0; j < r->getNumReactants(); j++)
    {
      sr = r->getReactant(j);
      if (sr->isSetStoichiometryMath())
      {
        if (!sr->isSetId())
        {
          sprintf(newid, "generatedId_%u", idCount);
          id.assign(newid);
          sr->setId(id);
          idCount++;
        }
        else
        {
          id = sr->getId();
        }
        sr->setConstant(false);

        AssignmentRule * ar = createAssignmentRule();
        ar->setVariable(id);
        if (sr->getStoichiometryMath()->isSetMath())
        {
          ar->setMath(sr->getStoichiometryMath()->getMath());
        }
      }
    }
    for (j = 0; j < r->getNumProducts(); j++)
    {
      sr = r->getProduct(j);
      if (sr->isSetStoichiometryMath())
      {
        if (!sr->isSetId())
        {
          sprintf(newid, "generatedId_%u", idCount);
          id.assign(newid);
          sr->setId(id);
          idCount++;
        }
        else
        {
          id = sr->getId();
        }

        sr->setConstant(false);
        AssignmentRule * ar = createAssignmentRule();
        ar->setVariable(id);
        if (sr->getStoichiometryMath()->isSetMath())
        {
          ar->setMath(sr->getStoichiometryMath()->getMath());
        }
      }
    }
  }
}
예제 #4
0
void
Model::dealWithStoichiometry()
{
  unsigned int idCount = 0;
  for (unsigned int i = 0; i < getNumReactions(); i++)
  {
    Reaction *r = getReaction(i);
    unsigned int j;

    for (j = 0; j < r->getNumReactants(); j++)
    {
      SpeciesReference *sr = r->getReactant(j);
      if (sr->isSetStoichiometry() == false)
      {
        if (sr->isSetId() == false)
        {
          createNoValueStoichMath(*this, *sr, idCount);
          idCount++;
        }
        else
        {
          // id is set it could be used by initialAssignment
          // used by rule
          // not used
          if (getInitialAssignment(sr->getId()) != NULL)
          {
            useStoichMath(*this, *sr, false);
          }
          else if (getRule(sr->getId()) != NULL)
          {
            //assignmentRule
            if (getRule(sr->getId())->getTypeCode() == SBML_ASSIGNMENT_RULE)
            {  
              useStoichMath(*this, *sr, true);
            }
            else if (getRule(sr->getId())->getTypeCode() == SBML_RATE_RULE)
            {
              createParameterAsRateRule(*this, *sr, *(getRule(sr->getId())), idCount);
              idCount++;
            }
          }
          else
          {
            createNoValueStoichMath(*this, *sr, idCount);
            idCount++;
          }
        }
      }
      else
      {
        // stoichiometry is set
        if (sr->isSetId())
        {
          // id is set it could be used by initialAssignment
          // used by rule
          // not used
          if (getInitialAssignment(sr->getId()) != NULL)
          {
            useStoichMath(*this, *sr, false);
          }
          else if (getRule(sr->getId()) != NULL)
          {
            //assignmentRule
            if (getRule(sr->getId())->getTypeCode() == SBML_ASSIGNMENT_RULE)
            {            
              useStoichMath(*this, *sr, true);
            }
            else if (getRule(sr->getId())->getTypeCode() == SBML_RATE_RULE)
            {
              createParameterAsRateRule(*this, *sr, *(getRule(sr->getId())), idCount);
              idCount++;
            }
          }
        }
        // no id set - do not need to do anything
      }
    }
    for (j = 0; j < r->getNumProducts(); j++)
    {
      SpeciesReference *sr = r->getProduct(j);
      if (sr->isSetStoichiometry() == false)
      {
        if (sr->isSetId() == false)
        {
          createNoValueStoichMath(*this, *sr, idCount);
          idCount++;
        }
        else
        {
          // id is set it could be used by initialAssignment
          // used by rule
          // not used
          if (getInitialAssignment(sr->getId()) != NULL)
          {
            useStoichMath(*this, *sr, false);
          }
          else if (getRule(sr->getId()) != NULL)
          {
            //assignmentRule
            if (getRule(sr->getId())->getTypeCode() == SBML_ASSIGNMENT_RULE)
            {  
              useStoichMath(*this, *sr, true);
            }
            else if (getRule(sr->getId())->getTypeCode() == SBML_RATE_RULE)
            {
              createParameterAsRateRule(*this, *sr, *(getRule(sr->getId())), idCount);
              idCount++;
            }
          }
          else
          {
            createNoValueStoichMath(*this, *sr, idCount);
            idCount++;
          }
        }
      }
      else
      {
        // stoichiometry is set
        if (sr->isSetId())
        {
          // id is set it could be used by initialAssignment
          // used by rule
          // not used
          if (getInitialAssignment(sr->getId()) != NULL)
          {
            useStoichMath(*this, *sr, false);
          }
          else if (getRule(sr->getId()) != NULL)
          {
            //assignmentRule
            if (getRule(sr->getId())->getTypeCode() == SBML_ASSIGNMENT_RULE)
            {            
              useStoichMath(*this, *sr, true);
            }
            else if (getRule(sr->getId())->getTypeCode() == SBML_RATE_RULE)
            {
              createParameterAsRateRule(*this, *sr, *(getRule(sr->getId())), idCount);
              idCount++;
            }
          }
        }
        // no id set - do not need to do anything
      }
    }
  }
}
예제 #5
0
void
CompIdBase::checkId (const SpeciesReference& x)
{
  if (x.isSetId()) doCheckId(x.getId(), x);
}
bool 
LayoutSpeciesReferencePlugin::readOtherXML (SBase* parentObject, XMLInputStream& stream)
{
  if (!parentObject) return false;

  bool readAnnotationFromStream = false;

  //
  // This plugin object is used only for SBML Level 2 Version 1.
  //
  if ( getURI() != LayoutExtension::getXmlnsL2() ) return false;
  if ( parentObject->getVersion() > 1 )       return false;

  XMLNode *pAnnotation = parentObject->getAnnotation();

  if (!pAnnotation)
  {
    //
    // (NOTES)
    //
    // annotation element has not been parsed by the parent element
    // (SpeciesReference) of this plugin object, thus annotation 
    // element is parsed via the given XMLInputStream object in this block. 
    //
  
    const string& name = stream.peek().getName();

    if (name == "annotation")
    {
      pAnnotation = new XMLNode(stream); 

      SpeciesReference *sr = static_cast<SpeciesReference*>(parentObject);

      parseSpeciesReferenceAnnotation(pAnnotation,*sr);
      std::string srId = sr->getId();

      if (!srId.empty())
      {
        //
        // Removes the annotation for layout extension from the annotation
        // of parent element (pAnnotation) and then set the new annotation 
        // (newAnnotation) to the parent element.
        //
        XMLNode *newAnnotation = deleteLayoutIdAnnotation(pAnnotation);
        parentObject->setAnnotation(newAnnotation);
       
        delete newAnnotation;
      }
      else
      {
        //
        // No layout annotation is included in the read annotation 
        // (pAnnotation) and thus just set the annotation to the parent
        // element.
        //
        parentObject->setAnnotation(pAnnotation);
      }

      delete pAnnotation;

      readAnnotationFromStream = true;
    }
    
  }
  else if (parentObject->getId().empty())
  {
    //
    // (NOTES)
    //
    // annotation element has been parsed by the parent element
    // (SpeciesReference) of this plugin object, thus the annotation element 
    // set to the above pAnnotation variable is parsed in this block.
    //
    SpeciesReference *sr = static_cast<SpeciesReference*>(parentObject);
    parseSpeciesReferenceAnnotation(pAnnotation, *sr);
    std::string srId = sr->getId();

    if (!srId.empty())
    {
      //
      // Removes the annotation for layout extension from the annotation
      // of parent element (pAnnotation) and then set the new annotation 
      // (newAnnotation) to the parent element.
      //
      XMLNode *newAnnotation = deleteLayoutIdAnnotation(pAnnotation);
      parentObject->setAnnotation(newAnnotation);

      delete newAnnotation;
    }
    readAnnotationFromStream = true;
  }
  return readAnnotationFromStream;
}