Beispiel #1
0
void CModelExpansion::replaceInMetab(CMetab* pX, const ElementsMap & emap)
{
  replaceInModelEntity(pX, emap);

  //is the metab in a compartment that needs to be replaced?
  if (emap.exists(pX->getCompartment()))
    {
      //move the metab to the new compartment
      CCompartment* oldComp = const_cast<CCompartment*>(pX->getCompartment());
      CCompartment* newComp = dynamic_cast<CCompartment*>(emap.getDuplicatePtr(pX->getCompartment()));
      bool success = false;

      do
        {
          success = newComp->addMetabolite(pX);

          if (success)
            {
              oldComp->getMetabolites().remove(pX->getObjectName());
              mpModel->setCompileFlag();
              mpModel->initializeMetabolites();
            }
          else
            {
              //rename the metab so that it can be added to the new compartment
              pX->setObjectName(pX->getObjectName() + "_");
              //TODO: check if the renaming actually worked
            }
        }
      while (!success);
    }
}
Beispiel #2
0
// virtual
CXMLHandler * MetaboliteHandler::processStart(const XML_Char * pszName,
    const XML_Char ** papszAttrs)
{
  CXMLHandler * pHandlerToCall = NULL;

  CCompartment * pCompartment = NULL;
  const char * Name;
  const char * simulationType;
  CModelEntity::Status SimulationType;
  const char reactions[] = "reactions";
  const char * Compartment;
  bool AddNoise;

  switch (mCurrentElement.first)
    {
      case Metabolite:
        mKey = mpParser->getAttributeValue("key", papszAttrs);
        Name = mpParser->getAttributeValue("name", papszAttrs);

        simulationType = mpParser->getAttributeValue("simulationType", papszAttrs, false);

        // We need to handle old files which used the attribute status.
        if (!simulationType)
          {
            simulationType = mpParser->getAttributeValue("status", papszAttrs, false);

            if (!simulationType) // status and simulationType are both missing
              simulationType = mpParser->getAttributeValue("simulationType", papszAttrs);
            else if (!strcmp(simulationType, "variable")) // reactions was named variable
              simulationType = reactions;
          }

        SimulationType = toEnum(simulationType, CModelEntity::XMLStatus, CModelEntity::REACTIONS);
        Compartment = mpParser->getAttributeValue("compartment", papszAttrs);
        AddNoise = mpParser->toBool(mpParser->getAttributeValue("addNoise", papszAttrs, "false"));

        mpMetabolite = new CMetab();
        addFix(mKey, mpMetabolite);
        mpMetabolite->setObjectName(Name);
        mpMetabolite->setStatus(SimulationType);
        mpMetabolite->setAddNoise(AddNoise);

        pCompartment =
          dynamic_cast< CCompartment* >(mpData->mKeyMap.get(Compartment));

        if (!pCompartment) fatalError();

        pCompartment->addMetabolite(mpMetabolite);
        mpData->pModel->getMetabolites().add(mpMetabolite, false);
        break;;

      case MiriamAnnotation:
      case Comment:
      case Expression:
      case InitialExpression:
      case NoiseExpression:
        pHandlerToCall = getHandler(mCurrentElement.second);
        break;

      case ListOfUnsupportedAnnotations:
        mpData->mUnsupportedAnnotations.clear();
        pHandlerToCall = getHandler(mCurrentElement.second);
        break;

      default:
        CCopasiMessage(CCopasiMessage::EXCEPTION, MCXML + 2,
                       mpParser->getCurrentLineNumber(), mpParser->getCurrentColumnNumber(), pszName);
        break;
    }

  return pHandlerToCall;
}