COPASI API  4.16.103
Public Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
SEDMLImporter Class Reference

#include <SEDMLImporter.h>

Collaboration diagram for SEDMLImporter:
Collaboration graph
[legend]

Public Member Functions

void deleteCopasiModel ()
 
const std::string getArchiveFileName ()
 
CProcessReportgetImportHandlerAddr ()
 
CModelimportFirstSBMLModel (CProcessReport *pImportHandler, SBMLDocument *&pSBMLDocument, std::map< CCopasiObject *, SBase * > &copasi2sbmlmap, CListOfLayouts *&prLol, CCopasiDataModel *pDataModel)
 
void importTasks (std::map< CCopasiObject *, SedBase * > &copasi2sedmlmap)
 
CModelparseSEDML (const std::string &sedmlDocumentText, CProcessReport *pImportHandler, SBMLDocument *&pSBMLDocument, SedDocument *&pSEDMLDocument, std::map< CCopasiObject *, SedBase * > &copasi2sedmlmap, std::map< CCopasiObject *, SBase * > &copasi2sbmlmap, CListOfLayouts *&prLol, COutputDefinitionVector *&plotList, CCopasiDataModel *pDataModel)
 
void readListOfPlotsFromSedMLOutput (COutputDefinitionVector *pPlotList, CModel *pModel, SedDocument *pSedDocument, std::map< CCopasiObject *, SedBase * > &copasi2sedmlmap)
 
CModelreadSEDML (std::string filename, CProcessReport *pImportHandler, SBMLDocument *&pSBMLDocument, SedDocument *&pSedDocument, std::map< CCopasiObject *, SedBase * > &copasi2sedmlmap, std::map< CCopasiObject *, SBase * > &copasi2sbmlmap, CListOfLayouts *&prLol, COutputDefinitionVector *&plotList, CCopasiDataModel *pDataModel)
 
void restoreFunctionDB ()
 
 SEDMLImporter ()
 
void setImportHandler (CProcessReport *pHandler)
 
void updateCopasiTaskForSimulation (SedSimulation *sedmlsim, std::map< CCopasiObject *, SedBase * > &copasi2sedmlmap)
 
 ~SEDMLImporter ()
 

Static Protected Member Functions

static bool areApproximatelyEqual (const double &x, const double &y, const double &t=1e-9)
 
static C_FLOAT64 round (const C_FLOAT64 &x)
 

Protected Attributes

std::string mArchiveFileName
 
size_t mhImportStep
 
std::set< unsigned int > mIgnoredSEDMLMessages
 
std::string mImportedModel
 
unsigned C_INT32 mImportStep
 
bool mIncompleteModel
 
unsigned int mLevel
 
unsigned int mOriginalLevel
 
CModelmpCopasiModel
 
CCopasiDataModelmpDataModel
 
CProcessReportmpImportHandler
 
SedDocument * mpSEDMLDocument
 
std::map< CReportDefinition
*, std::string > 
mReportMap
 
unsigned C_INT32 mTotalSteps
 
std::set< std::string > mUsedSEDMLIds
 
bool mUsedSEDMLIdsPopulated
 
unsigned int mVersion
 

Detailed Description

Definition at line 37 of file SEDMLImporter.h.

Constructor & Destructor Documentation

SEDMLImporter::SEDMLImporter ( )

Constructor that initializes speciesMap and the FunctionDB object

Definition at line 953 of file SEDMLImporter.cpp.

References mIgnoredSEDMLMessages.

953  :
955  mIncompleteModel(false),
956  mLevel(0),
957  mOriginalLevel(0),
958  mVersion(0),
959  mpDataModel(NULL),
960  mpCopasiModel(NULL),
961  mpSEDMLDocument(NULL),
962  mpImportHandler(NULL),
963  mImportStep(0),
965  mTotalSteps(0),
966  mUsedSEDMLIds(),
967  mUsedSEDMLIdsPopulated(false),
968  mImportedModel(),
969  mReportMap()
970 {
971 
972  this->mIgnoredSEDMLMessages.insert(10501);
973 }
std::set< unsigned int > mIgnoredSEDMLMessages
Definition: SEDMLImporter.h:49
std::set< std::string > mUsedSEDMLIds
Definition: SEDMLImporter.h:65
bool mUsedSEDMLIdsPopulated
Definition: SEDMLImporter.h:66
#define C_INVALID_INDEX
Definition: copasi.h:222
unsigned int mLevel
Definition: SEDMLImporter.h:51
CProcessReport * mpImportHandler
Definition: SEDMLImporter.h:60
std::map< CReportDefinition *, std::string > mReportMap
Definition: SEDMLImporter.h:70
unsigned int mVersion
Definition: SEDMLImporter.h:53
CModel * mpCopasiModel
Definition: SEDMLImporter.h:56
std::string mImportedModel
Definition: SEDMLImporter.h:68
SedDocument * mpSEDMLDocument
Definition: SEDMLImporter.h:58
unsigned int mOriginalLevel
Definition: SEDMLImporter.h:52
unsigned C_INT32 mTotalSteps
Definition: SEDMLImporter.h:63
size_t mhImportStep
Definition: SEDMLImporter.h:62
bool mIncompleteModel
Definition: SEDMLImporter.h:50
unsigned C_INT32 mImportStep
Definition: SEDMLImporter.h:61
CCopasiDataModel * mpDataModel
Definition: SEDMLImporter.h:55
SEDMLImporter::~SEDMLImporter ( )

Destructor that does nothing.

Definition at line 982 of file SEDMLImporter.cpp.

References mReportMap.

983 {
984  mReportMap.clear();
985 }
std::map< CReportDefinition *, std::string > mReportMap
Definition: SEDMLImporter.h:70

Member Function Documentation

static bool SEDMLImporter::areApproximatelyEqual ( const double &  x,
const double &  y,
const double &  t = 1e-9 
)
staticprotected
void SEDMLImporter::deleteCopasiModel ( )

This call deletes an existing COPASI model. The method can e.g. be called to clean up if an import fails.

Definition at line 987 of file SEDMLImporter.cpp.

References mpCopasiModel.

988 {
989  if (this->mpCopasiModel != NULL)
990  {
991  delete this->mpCopasiModel;
992  this->mpCopasiModel = NULL;
993  }
994 }
CModel * mpCopasiModel
Definition: SEDMLImporter.h:56
const std::string SEDMLImporter::getArchiveFileName ( )

Definition at line 87 of file SEDMLImporter.cpp.

References mArchiveFileName.

88 {return mArchiveFileName;}
std::string mArchiveFileName
Definition: SEDMLImporter.h:48
CProcessReport * SEDMLImporter::getImportHandlerAddr ( )

Definition at line 84 of file SEDMLImporter.cpp.

References mpImportHandler.

85 {return mpImportHandler;}
CProcessReport * mpImportHandler
Definition: SEDMLImporter.h:60
CModel * SEDMLImporter::importFirstSBMLModel ( CProcessReport pImportHandler,
SBMLDocument *&  pSBMLDocument,
std::map< CCopasiObject *, SBase * > &  copasi2sbmlmap,
CListOfLayouts *&  prLol,
CCopasiDataModel pDataModel 
)

Imports the first viable SBML model

Definition at line 805 of file SEDMLImporter.cpp.

References applyAttributeChange(), SBMLImporter::deleteCopasiModel(), CDirEntry::dirName(), CCopasiMessage::EXCEPTION, CDirEntry::exist(), CLocaleString::fromUtf8(), CCopasiRootContainer::getFunctionList(), CModel::getModelParameterSet(), MCSEDML, mImportedModel, mpCopasiModel, mpDataModel, mpSEDMLDocument, SBMLImporter::parseSBML(), SBMLImporter::restoreFunctionDB(), CDirEntry::Separator, SBMLImporter::setImportCOPASIMIRIAM(), SBMLImporter::setImportHandler(), CCopasiDataModel::setSBMLFileName(), and CCopasiMessage::WARNING.

Referenced by parseSEDML().

810 {
811  std::string SBMLFileName, fileContent;
812 
813  unsigned int ii, iiMax = mpSEDMLDocument->getListOfModels()->size();
814 
815  if (iiMax < 1)
816  {
818  }
819 
820  if (iiMax > 1)
821  {
822  CCopasiMessage(CCopasiMessage::WARNING, "COAPSI currently only supports the import of SED-ML models, that involve one model only. Only the simulations for the first model will be imported");
823  }
824 
825  std::string modelSource = ""; //must be taken from SEDML document.
826  std::string modelId = ""; // to ensure only one model is imported since only one model in SEDML file is supported
827  SedModel* sedmlModel = NULL;
828 
829  for (ii = 0; ii < iiMax; ++ii)
830  {
831  sedmlModel = mpSEDMLDocument->getModel(ii);
832 
833  // need to also allow for the specific urns like
834  // urn:sedml:language:sbml.level-3.version-1
835  if (sedmlModel->getLanguage().find("urn:sedml:language:sbml") == std::string::npos)
837  "Sorry currently, only SBML models are supported.");
838 
839  if (sedmlModel->getSource() != modelId)
840  {
841  modelId = sedmlModel->getId();
842 
843  if ((sedmlModel->getListOfChanges()->size()) > 0)
844  CCopasiMessage(CCopasiMessage::WARNING, "Currently there is only limited support for "
845  "changing model entities. Only value changes are imported into the model.");
846 
847  modelSource = sedmlModel->getSource();
848  break;
849  }
850  }
851 
852  assert(modelSource != "");
853 
854  //process the archive file and get the SBML model file
855  //SEDMLUtils utils;
856  //int success = utils.processArchive(pDataModel->getSEDMLFileName(), SBMLFileName, fileContent);
857 
858  std::string FileName;
859 
860  if (CDirEntry::exist(modelSource))
861  FileName = modelSource;
862  else
863  FileName = CDirEntry::dirName(pDataModel->getSEDMLFileName())
864  + CDirEntry::Separator + modelSource;
865 
866  std::ifstream file(CLocaleString::fromUtf8(FileName).c_str());
867 
868  if (!file)
869  {
871  FileName.c_str());
872  }
873 
874  //set the SBML file name for later use
875  pDataModel->setSBMLFileName(FileName);
876  std::ostringstream sbmlStringStream;
877  char c;
878 
879  while (file.get(c))
880  {
881  sbmlStringStream << c;
882  }
883 
884  file.clear();
885  file.close();
886 
887  std::ifstream File(CLocaleString::fromUtf8(FileName).c_str());
888 
889  SBMLImporter importer;
890  // Right now we always import the COPASI MIRIAM annotation if it is there.
891  // Later this will be settable by the user in the preferences dialog
892  importer.setImportCOPASIMIRIAM(true);
893  importer.setImportHandler(pImportHandler);
894 
895  mpCopasiModel = NULL;
896 
897  std::map<CCopasiObject*, SBase*> Copasi2SBMLMap;
898 
899  try
900  {
901  mpCopasiModel = importer.parseSBML(sbmlStringStream.str(),
902  CCopasiRootContainer::getFunctionList(), pSBMLDocument,
903  Copasi2SBMLMap, prLol, mpDataModel);
904  }
905 
906  catch (CCopasiException & except)
907  {
908  importer.restoreFunctionDB();
909  importer.deleteCopasiModel();
910  // popData();
911 
912  throw except;
913  }
914 
915  if (mpCopasiModel == NULL)
916  {
917  importer.restoreFunctionDB();
918  importer.deleteCopasiModel();
919  // popData();
920  return NULL;
921  }
922 
923  mImportedModel = modelId;
924 
925  // apply possible changes to the model
926  if (sedmlModel != NULL && sedmlModel->getNumChanges() > 0)
927  {
929  bool valueChanged = false;
930 
931  for (unsigned int i = 0; i < sedmlModel->getNumChanges(); ++i)
932  {
933  SedChangeAttribute* change = dynamic_cast<SedChangeAttribute*>(sedmlModel->getChange(i));
934 
935  if (change == NULL) continue;
936 
937  const std::string& target = change->getTarget();
938  const std::string& newValue = change->getNewValue();
939 
940  if (!applyAttributeChange(mpCopasiModel, set, target, newValue))
941  {
942  CCopasiMessage(CCopasiMessage::WARNING, "Could not apply change for target: '%s'", target.c_str());
943  }
944  }
945  }
946 
947  return mpCopasiModel;
948 }
void setImportCOPASIMIRIAM(bool import)
const CModelParameterSet & getModelParameterSet() const
Definition: CModel.cpp:1072
bool setSBMLFileName(const std::string &fileName)
void restoreFunctionDB()
void deleteCopasiModel()
void setImportHandler(CProcessReport *pHandler)
static std::string dirName(const std::string &path)
Definition: CDirEntry.cpp:135
static bool exist(const std::string &path)
Definition: CDirEntry.cpp:78
static const std::string Separator
Definition: CDirEntry.h:34
CModel * parseSBML(const std::string &sbmlDocumentText, CFunctionDB *funDB, SBMLDocument *&pSBMLDocument, std::map< CCopasiObject *, SBase * > &copasi2sbmlmap, CListOfLayouts *&prLol, CCopasiDataModel *pDataModel)
static CFunctionDB * getFunctionList()
CModel * mpCopasiModel
Definition: SEDMLImporter.h:56
#define MCSEDML
std::string mImportedModel
Definition: SEDMLImporter.h:68
SedDocument * mpSEDMLDocument
Definition: SEDMLImporter.h:58
static CLocaleString fromUtf8(const std::string &utf8)
CCopasiDataModel * mpDataModel
Definition: SEDMLImporter.h:55
bool applyAttributeChange(CModel *pCopasiModel, CModelParameterSet &set, const std::string &target, const std::string &newValue)
void SEDMLImporter::importTasks ( std::map< CCopasiObject *, SedBase * > &  copasi2sedmlmap)

Import all tasks for the imported SBML model

Definition at line 613 of file SEDMLImporter.cpp.

References CCopasiVectorN< CType >::add(), CScanProblem::addScanItem(), CCopasiParameterGroup::getParameter(), CCopasiTask::getProblem(), CCopasiDataModel::getReportDefinitionList(), CCopasiDataModel::getTaskList(), CCopasiParameter::getValue(), mImportedModel, mpCopasiModel, mpDataModel, mpSEDMLDocument, mReportMap, CCopasiParameter::Value::pBOOL, CCopasiParameter::Value::pDOUBLE, SEDMLUtils::resolveXPath(), CScanProblem::SCAN_LINEAR, CScanProblem::SCAN_REPEAT, CReport::setAppend(), CReport::setConfirmOverwrite(), CScanProblem::setContinueFromCurrentState(), CScanProblem::setOutputInSubtask(), CReport::setReportDefinition(), CCopasiTask::setScheduled(), CScanProblem::setSubtask(), CReport::setTarget(), CCopasiTask::steadyState, CCopasiTask::timeCourse, updateCopasiTaskForSimulation(), and CCopasiMessage::WARNING.

Referenced by parseSEDML().

614 {
615 
616  for (unsigned int i = 0; i < mpSEDMLDocument->getNumTasks(); ++i)
617  {
618  SedTask * current = mpSEDMLDocument->getTask(i);
619 
620  // skip taks for models we did not import
621  if (current->isSetModelReference() && current->getModelReference() != this->mImportedModel)
622  continue;
623 
624  switch (current->getTypeCode())
625  {
626  case SEDML_TASK:
627  {
628  SedSimulation* sedmlsim =
629  mpSEDMLDocument->getSimulation(current->getSimulationReference());
630  updateCopasiTaskForSimulation(sedmlsim, copasi2sedmlmap);
631  break;
632  }
633 
634  case SEDML_TASK_REPEATEDTASK:
635  {
636  SedRepeatedTask *repeat = static_cast<SedRepeatedTask*>(current);
637  SedRange* range = repeat->getRange(repeat->getRangeId());
638 
639  if (range == NULL || range->getTypeCode() != SEDML_RANGE_UNIFORMRANGE)
640  {
641  CCopasiMessage(CCopasiMessage::WARNING, "This version of COPASI only supports uniform ranges.");
642  continue;
643  }
644 
645  SedUniformRange* urange = static_cast<SedUniformRange*>(range);
646  CScanTask *tTask = static_cast<CScanTask*>((*mpDataModel->getTaskList())["Scan"]);
647  tTask->setScheduled(true);
648  CScanProblem *pProblem = static_cast<CScanProblem*>(tTask->getProblem());
649 
650  if (urange != NULL && repeat->getNumTaskChanges() == 0)
651  {
652  pProblem->addScanItem(CScanProblem::SCAN_REPEAT, urange->getNumberOfPoints());
653  }
654  else
655  {
656  for (unsigned int j = 0; j < repeat->getNumTaskChanges(); ++j)
657  {
658  SedSetValue* sv = repeat->getTaskChange(j);
659 
660  if (SBML_formulaToString(sv->getMath()) != sv->getRange())
661  {
663  "This version of COPASI only supports setValue elements that apply range values.");
664  }
665 
666  std::string target = sv->getTarget();
667  const CCopasiObject * obj = SEDMLUtils::resolveXPath(mpCopasiModel, target, true);
668 
669  if (obj == NULL)
670  {
671  CCopasiMessage(CCopasiMessage::WARNING, "This version of COPASI only supports modifications of initial values.");
672  continue;
673  }
674 
675  CCopasiParameterGroup*group = pProblem->addScanItem(CScanProblem::SCAN_LINEAR, urange->getNumberOfPoints(), obj);
676  *group->getParameter("Minimum")->getValue().pDOUBLE = urange->getStart();
677  *group->getParameter("Maximum")->getValue().pDOUBLE = urange->getEnd();
678  *group->getParameter("log")->getValue().pBOOL =
679  (!urange->isSetType() || urange->getType().empty() || urange->getType() == "linear") ? false
680  : true;
681  }
682  }
683 
684  if (repeat->getNumSubTasks() != 1)
685  {
686  CCopasiMessage(CCopasiMessage::WARNING, "This version of COPASI only supports repeatedTasks with one subtask.");
687  continue;
688  }
689 
690  pProblem->setContinueFromCurrentState(!repeat->getResetModel());
691 
692  SedSubTask* subTask = repeat->getSubTask(0);
693 
694  if (!subTask->isSetTask())
695  {
696  CCopasiMessage(CCopasiMessage::WARNING, "This version of COPASI only supports repeatedTasks with one subtask that has a valid task reference.");
697  continue;
698  }
699 
700  SedTask* actualSubTask = mpSEDMLDocument->getTask(subTask->getTask());
701 
702  if (actualSubTask == NULL || !actualSubTask->isSetSimulationReference())
703  {
704  CCopasiMessage(CCopasiMessage::WARNING, "This version of COPASI only supports repeatedTasks with one subtask that itself is a task with simulation reference.");
705  continue;
706  }
707 
708  int code = mpSEDMLDocument->getSimulation(actualSubTask->getSimulationReference())->getTypeCode();
709 
710  if (code == SEDML_SIMULATION_STEADYSTATE)
711  {
713  pProblem->setOutputInSubtask(false);
714  }
715  else if (code == SEDML_SIMULATION_ONESTEP || code == SEDML_SIMULATION_UNIFORMTIMECOURSE)
716  {
718  }
719 
720  break;
721  }
722 
723  default:
724  {
725  const char* name = SedTypeCode_toString(current->getTypeCode());
727  "Encountered unsupported Task type '%s'. This task cannot be imported in COPASI",
728  name != NULL ? name : "unknown");
729  }
730  }
731  }
732 
733  std::map<CReportDefinition*, std::string>::const_iterator it = mReportMap.begin();
734 
735  for (; it != mReportMap.end(); ++it)
736  {
737  mpDataModel->getReportDefinitionList()->add(it->first);
738  CReport& report = ((*mpDataModel->getTaskList())[it->second])->getReport();
739  report.setReportDefinition(it->first);
740  report.setTarget(it->second + ".txt");
741  report.setConfirmOverwrite(false);
742  report.setAppend(false);
743  }
744 }
void setSubtask(CCopasiTask::Type type)
void setScheduled(const bool &scheduled)
CCopasiProblem * getProblem()
void updateCopasiTaskForSimulation(SedSimulation *sedmlsim, std::map< CCopasiObject *, SedBase * > &copasi2sedmlmap)
void setAppend(const bool &append)
Definition: CReport.cpp:98
void setConfirmOverwrite(const bool &confirmOverwrite)
Definition: CReport.cpp:104
CCopasiParameterGroup * addScanItem(CScanProblem::Type type, size_t steps=5, const CCopasiObject *obj=NULL)
const CReportDefinitionVector * getReportDefinitionList() const
virtual bool add(const CType &src)
std::map< CReportDefinition *, std::string > mReportMap
Definition: SEDMLImporter.h:70
const Value & getValue() const
CCopasiVectorN< CCopasiTask > * getTaskList()
CCopasiParameter * getParameter(const std::string &name)
CModel * mpCopasiModel
Definition: SEDMLImporter.h:56
void setTarget(const std::string &target)
Definition: CReport.cpp:92
void setContinueFromCurrentState(bool aic)
void setOutputInSubtask(bool ois)
std::string mImportedModel
Definition: SEDMLImporter.h:68
SedDocument * mpSEDMLDocument
Definition: SEDMLImporter.h:58
static const CCopasiObject * resolveXPath(const CModel *model, const std::string &xpath, bool initial=false)
Definition: SEDMLUtils.cpp:242
void setReportDefinition(CReportDefinition *reportDef)
Definition: CReport.cpp:86
CCopasiDataModel * mpDataModel
Definition: SEDMLImporter.h:55
CModel * SEDMLImporter::parseSEDML ( const std::string &  sedmlDocumentText,
CProcessReport pImportHandler,
SBMLDocument *&  pSBMLDocument,
SedDocument *&  pSEDMLDocument,
std::map< CCopasiObject *, SedBase * > &  copasi2sedmlmap,
std::map< CCopasiObject *, SBase * > &  copasi2sbmlmap,
CListOfLayouts *&  prLol,
COutputDefinitionVector *&  pPlotList,
CCopasiDataModel pDataModel 
)

Function parses an SEDML document with libsedml and converts it to a COPASI CModel object which is returned. Deletion of the returned pointer is up to the caller.

Definition at line 435 of file SEDMLImporter.cpp.

References CProcessReport::addItem(), C_INT32, C_INVALID_INDEX, CCopasiMessage::ERROR, CCopasiMessage::ERROR_FILTERED, CCopasiMessage::EXCEPTION, CProcessReport::finishItem(), importFirstSBMLModel(), importTasks(), MCSEDML, MCXML, mhImportStep, mIgnoredSEDMLMessages, mImportStep, mLevel, mOriginalLevel, mpCopasiModel, mpDataModel, mpImportHandler, mpSEDMLDocument, mReportMap, mTotalSteps, mUsedSEDMLIdsPopulated, mVersion, CCopasiMessage::RAW, readListOfPlotsFromSedMLOutput(), CProcessReport::setName(), CCopasiMessage::WARNING, and CCopasiMessage::WARNING_FILTERED.

Referenced by readSEDML().

444 {
445  mReportMap.clear();
446  this->mUsedSEDMLIdsPopulated = false;
447 
448  mpDataModel = pDataModel;
449  assert(mpDataModel != NULL);
450 
451  this->mpCopasiModel = NULL;
452 
453  SedReader reader;
454 
455  mImportStep = 0;
456 
457  if (mpImportHandler)
458  {
459  mpImportHandler->setName("Importing SED-ML file...");
460  mTotalSteps = 11;
462  &mTotalSteps);
463  }
464 
465  unsigned C_INT32 step = 0, totalSteps = 0;
466  size_t hStep = C_INVALID_INDEX;
467 
468  if (this->mpImportHandler != 0)
469  {
470  step = 0;
471  totalSteps = 1;
472  hStep = mpImportHandler->addItem("Reading SED-ML file...", step,
473  &totalSteps);
474  }
475 
476  mpSEDMLDocument = reader.readSedMLFromString(sedmlDocumentText);
477 
478  assert(mpSEDMLDocument != NULL);
479 
480  if (mpImportHandler)
481  mpImportHandler->finishItem(hStep);
482 
483  if (this->mpImportHandler != 0)
484  {
485  step = 0;
486  totalSteps = 1;
487  hStep = mpImportHandler->addItem("Checking consistency...", step,
488  &totalSteps);
489  }
490 
491  if (mpImportHandler)
492  mpImportHandler->finishItem(hStep);
493 
494  int fatal = -1;
495  unsigned int i, iMax = mpSEDMLDocument->getNumErrors();
496 
497  for (i = 0; (i < iMax) && (fatal == -1); ++i)
498  {
499  const SedError* pSEDMLError = mpSEDMLDocument->getError(i);
500 
502 
503  switch (pSEDMLError->getSeverity())
504  {
505 
506  case LIBSEDML_SEV_WARNING:
507 
508  // if issued as warning, this message is to be disregarded,
509  // it was a bug in earlier versions of libSEDML
510  if (pSEDMLError->getErrorId() == SedInvalidNamespaceOnSed)
511  continue;
512 
513  if (mIgnoredSEDMLMessages.find(pSEDMLError->getErrorId())
514  != mIgnoredSEDMLMessages.end())
515  {
516  messageType = CCopasiMessage::WARNING_FILTERED;
517  }
518  else
519  {
520  messageType = CCopasiMessage::WARNING;
521  }
522 
523  CCopasiMessage(messageType, MCSEDML + 6, "WARNING",
524  pSEDMLError->getErrorId(), pSEDMLError->getLine(),
525  pSEDMLError->getColumn(),
526  pSEDMLError->getMessage().c_str());
527  break;
528 
529  case LIBSEDML_SEV_ERROR:
530 
531  if (mIgnoredSEDMLMessages.find(pSEDMLError->getErrorId())
532  != mIgnoredSEDMLMessages.end())
533  {
534  messageType = CCopasiMessage::ERROR_FILTERED;
535  }
536 
537  CCopasiMessage(messageType, MCSEDML + 6, "ERROR",
538  pSEDMLError->getErrorId(), pSEDMLError->getLine(),
539  pSEDMLError->getColumn(),
540  pSEDMLError->getMessage().c_str());
541  break;
542 
543  case LIBSEDML_SEV_FATAL:
544 
545  // treat unknown as fatal
546  default:
547 
548  if (pSEDMLError->getErrorId() == 10804)
549  {
550  // this error indicates a problem with a notes element
551  // although libsedml flags this as fatal, we would still
552  // like to read the model
553  CCopasiMessage(messageType, MCSEDML + 6, "ERROR",
554  pSEDMLError->getErrorId(), pSEDMLError->getLine(),
555  pSEDMLError->getColumn(),
556  pSEDMLError->getMessage().c_str());
557  }
558  else
559  {
560  fatal = i;
561  }
562 
563  break;
564  }
565  }
566 
567  if (fatal != -1)
568  {
569  const XMLError* pSEDMLError = mpSEDMLDocument->getError(fatal);
571  pSEDMLError->getLine(), pSEDMLError->getColumn(),
572  pSEDMLError->getMessage().c_str());
573 
574  if (mpImportHandler)
576 
577  return NULL;
578  }
579 
580  if (mpSEDMLDocument->getListOfModels() == NULL)
581  {
583 
584  if (mpImportHandler)
586 
587  return NULL;
588  }
589 
590  //delete reader;
591  pSEDMLDocument = mpSEDMLDocument;
592  this->mLevel = pSEDMLDocument->getLevel();
593 
594  this->mOriginalLevel = this->mLevel;
595  this->mVersion = pSEDMLDocument->getVersion();
596 
597  importFirstSBMLModel(pImportHandler, pSBMLDocument, copasi2sbmlmap, prLol, pDataModel);
598 
599  pPlotList = new COutputDefinitionVector("OutputDefinitions", mpDataModel);
600  readListOfPlotsFromSedMLOutput(pPlotList, mpCopasiModel, pSEDMLDocument, copasi2sedmlmap);
601 
602  importTasks(copasi2sedmlmap);
603 
604  if (mpImportHandler)
606 
607  return mpCopasiModel;
608 
609  return NULL;
610 }
std::set< unsigned int > mIgnoredSEDMLMessages
Definition: SEDMLImporter.h:49
bool mUsedSEDMLIdsPopulated
Definition: SEDMLImporter.h:66
void readListOfPlotsFromSedMLOutput(COutputDefinitionVector *pPlotList, CModel *pModel, SedDocument *pSedDocument, std::map< CCopasiObject *, SedBase * > &copasi2sedmlmap)
virtual bool setName(const std::string &name)
#define MCXML
CModel * importFirstSBMLModel(CProcessReport *pImportHandler, SBMLDocument *&pSBMLDocument, std::map< CCopasiObject *, SBase * > &copasi2sbmlmap, CListOfLayouts *&prLol, CCopasiDataModel *pDataModel)
#define C_INVALID_INDEX
Definition: copasi.h:222
#define C_INT32
Definition: copasi.h:90
unsigned int mLevel
Definition: SEDMLImporter.h:51
CProcessReport * mpImportHandler
Definition: SEDMLImporter.h:60
size_t addItem(const std::string &name, const std::string &value, const std::string *pEndValue=NULL)
struct MESSAGES Message
std::map< CReportDefinition *, std::string > mReportMap
Definition: SEDMLImporter.h:70
unsigned int mVersion
Definition: SEDMLImporter.h:53
virtual bool finishItem(const size_t &handle)
CModel * mpCopasiModel
Definition: SEDMLImporter.h:56
#define MCSEDML
SedDocument * mpSEDMLDocument
Definition: SEDMLImporter.h:58
unsigned int mOriginalLevel
Definition: SEDMLImporter.h:52
unsigned C_INT32 mTotalSteps
Definition: SEDMLImporter.h:63
size_t mhImportStep
Definition: SEDMLImporter.h:62
unsigned C_INT32 mImportStep
Definition: SEDMLImporter.h:61
CCopasiDataModel * mpDataModel
Definition: SEDMLImporter.h:55
void importTasks(std::map< CCopasiObject *, SedBase * > &copasi2sedmlmap)
void SEDMLImporter::readListOfPlotsFromSedMLOutput ( COutputDefinitionVector pPlotList,
CModel pModel,
SedDocument *  pSedDocument,
std::map< CCopasiObject *, SedBase * > &  copasi2sedmlmap 
)

Definition at line 233 of file SEDMLImporter.cpp.

References CPlotItem::addChannel(), CPlotSpecification::createItem(), COutputDefinitionVector::createPlotSpec(), CPlotItem::curve2d, CCopasiMessage::EXCEPTION, CReportDefinition::getBodyAddr(), CCopasiObject::getCN(), CCopasiDataModel::getCopasi2SBMLMap(), CReportDefinition::getHeaderAddr(), SEDMLUtils::getNextId(), CCopasiObject::getObjectDataModel(), CCopasiObject::getObjectDisplayName(), CCopasiDataModel::getReportDefinitionList(), CReportDefinition::getSeparator(), isScan(), isTC(), mpDataModel, mpSEDMLDocument, mReportMap, CPlotItem::plot2d, SEDMLUtils::resolveDatagenerator(), CReportDefinition::setComment(), CReportDefinition::setIsTable(), CPlotSpecification::setLogX(), CPlotSpecification::setLogY(), CReportDefinition::setSeparator(), and CCopasiParameterGroup::setValue().

Referenced by parseSEDML().

237 {
238  size_t i, numOutput = pSEDMLDocument->getNumOutputs();
239 
240  std::map<CCopasiObject*, SBase*>& copasiMap = pModel->getObjectDataModel()->getCopasi2SBMLMap();
241 
243 
244  for (i = 0; i < numOutput; ++i)
245  {
246  SedOutput* current = pSEDMLDocument->getOutput(i);
247 
248  switch (current->getTypeCode())
249  {
250  case SEDML_OUTPUT_REPORT:
251  {
252  SedReport* r = static_cast<SedReport*>(current);
253  std::string name = current->isSetName() ? current->getName() : current->getId();
254  CReportDefinition* def = new CReportDefinition(name);
255  int count = 0;
256 
257  // creation fails on duplicated name!
258  while (def == NULL)
259  {
260  def = new CReportDefinition(SEDMLUtils::getNextId(name + " ", ++count));
261  }
262 
263  def->setComment("Import from SED-ML");
264 
265  def->setIsTable(false);
267 
268  std::vector<CRegisteredObjectName>* pHeader = def->getHeaderAddr();
269  std::vector<CRegisteredObjectName>* pBody = def->getBodyAddr();
270 
271  bool isTimeCourse = false;
272  bool isScanTask = false;
273 
274  for (size_t i = 0; i < r->getNumDataSets(); ++i)
275  {
276  SedDataSet* ds = r->getDataSet(i);
277  const SedDataGenerator* generator = pSEDMLDocument->getDataGenerator(ds->getDataReference());
278  const CCopasiObject * tmp = SEDMLUtils::resolveDatagenerator(pModel, generator);
279 
280  if (generator == NULL || tmp == NULL) continue;
281 
282  std::string title = ds->isSetLabel() ? ds->getLabel() : generator->isSetName() ? generator->getName() : ds->getId();
283 
284  pHeader->push_back(CCopasiStaticString(title).getCN());
285  pHeader->push_back(def->getSeparator().getCN());
286 
287  pBody->push_back(tmp->getCN());
288  pBody->push_back(def->getSeparator().getCN());
289 
290  if (!isTimeCourse && !isScanTask)
291  for (size_t j = 0; j < generator->getNumVariables(); ++j)
292  {
293  const SedTask* t = mpSEDMLDocument->getTask(generator->getVariable(j)->getTaskReference());
294 
295  if (t == NULL) continue;
296 
297  isScanTask = t->getTypeCode() == SEDML_TASK_REPEATEDTASK && isScan((const SedRepeatedTask*)t);
298  isTimeCourse = isTC(t);
299  }
300  }
301 
302  // assign report to scan task
303  if (isScanTask)
304  {
305  mReportMap[def] = "Scan";
306  }
307 
308  // assign report to Timecourse task
309  if (isTimeCourse)
310  {
311  mReportMap[def] = "Time-Course";
312  }
313 
314  break;
315  }
316 
317  case SEDML_OUTPUT_PLOT2D: //get the curves data
318  {
319  SedPlot2D* p = static_cast<SedPlot2D*>(current);
320  std::string name = current->isSetName() ? current->getName() :
321  current->getId();
322  CPlotSpecification* pPl = pLotList->createPlotSpec(
323  name, CPlotItem::plot2d);
324 
325  int count = 0;
326 
327  while (pPl == NULL)
328  {
329  // creation fails on duplicated name!
330  pPl = pLotList->createPlotSpec(
331  SEDMLUtils::getNextId(name + " ", ++count), CPlotItem::plot2d);
332  }
333 
334  bool logX = false;
335  bool logY = false;
336 
337  for (unsigned int ic = 0; ic < p->getNumCurves(); ++ic)
338  {
339  SedCurve *curve = p->getCurve(ic);
340 
341  std::string xDataReference = curve->getXDataReference();
342  std::string yDataReference = curve->getYDataReference();
343 
344  const SedDataGenerator* xGenerator = pSEDMLDocument->getDataGenerator(xDataReference);
345  const SedDataGenerator* yGenerator = pSEDMLDocument->getDataGenerator(yDataReference);
346 
347  //create the curves
348  const CCopasiObject * tmpX = SEDMLUtils::resolveDatagenerator(pModel, xGenerator);
349  const CCopasiObject * tmpY = SEDMLUtils::resolveDatagenerator(pModel, yGenerator);
350 
351  if (tmpX != NULL && tmpY != NULL)
352  {
353 
354  std::string itemTitle;
355 
356  if (curve->isSetName())
357  itemTitle = curve->getName();
358  else if (yGenerator != NULL && yGenerator->isSetName())
359  itemTitle = yGenerator->getName();
360  else
361  itemTitle = tmpY->getObjectDisplayName();
362 
363  CPlotItem * plItem = pPl->createItem(itemTitle, CPlotItem::curve2d);
364  plItem->setValue("Line width", 2.0);
365  plItem->addChannel(tmpX->getCN());
366  plItem->addChannel(tmpY->getCN());
367  }
368 
369  logX = logX || (curve->isSetLogX() && curve->getLogX());
370  logY = logY || (curve->isSetLogY() && curve->getLogY());
371  }
372 
373  pPl->setLogX(logX);
374  pPl->setLogY(logY);
375  break;
376  }
377 
378  default:
379  CCopasiMessage(CCopasiMessage::EXCEPTION, "SEDMLImporter Error: No support for this plot: typecode = %d", current->getTypeCode());
380  break;
381  }
382  }
383 }
CCopasiDataModel * getObjectDataModel()
virtual std::string getObjectDisplayName(bool regular=true, bool richtext=false) const
virtual CCopasiObjectName getCN() const
const CCopasiReportSeparator & getSeparator() const
void addChannel(const CPlotDataChannelSpec &channel)
Definition: CPlotItem.cpp:223
void setSeparator(const CCopasiReportSeparator &Separator)
static const CCopasiObject * resolveDatagenerator(const CModel *model, const SedDataGenerator *dataReference)
Definition: SEDMLUtils.cpp:203
CPlotItem * createItem(const std::string &name, CPlotItem::Type type)
void setIsTable(bool table)
const CReportDefinitionVector * getReportDefinitionList() const
bool isScan(const SedTask *task)
void setComment(const std::string &comment)
std::map< CReportDefinition *, std::string > mReportMap
Definition: SEDMLImporter.h:70
bool setValue(const std::string &name, const CType &value)
SedDocument * mpSEDMLDocument
Definition: SEDMLImporter.h:58
bool isTC(const SedTask *task)
std::vector< CRegisteredObjectName > * getBodyAddr()
static std::string getNextId(const std::string &base, int count)
Definition: SEDMLUtils.cpp:294
CCopasiDataModel * mpDataModel
Definition: SEDMLImporter.h:55
std::map< CCopasiObject *, SBase * > & getCopasi2SBMLMap()
std::vector< CRegisteredObjectName > * getHeaderAddr()
CModel * SEDMLImporter::readSEDML ( std::string  filename,
CProcessReport pImportHandler,
SBMLDocument *&  pSBMLDocument,
SedDocument *&  pSedDocument,
std::map< CCopasiObject *, SedBase * > &  copasi2sedmlmap,
std::map< CCopasiObject *, SBase * > &  copasi2sbmlmap,
CListOfLayouts *&  prLol,
COutputDefinitionVector *&  plotList,
CCopasiDataModel pDataModel 
)

Function reads an SEDML file with libsedml and converts it to a Copasi CModel

Definition at line 388 of file SEDMLImporter.cpp.

References CCopasiMessage::EXCEPTION, CLocaleString::fromUtf8(), MCSEDML, and parseSEDML().

397 {
398  // convert filename to the locale encoding
399  std::ifstream file(CLocaleString::fromUtf8(filename).c_str());
400 
401  if (!file)
402  {
403  CCopasiMessage(CCopasiMessage::EXCEPTION, MCSEDML + 5, filename.c_str());
404  }
405 
406  std::ostringstream stringStream;
407  char c;
408 
409  while (file.get(c))
410  {
411  stringStream << c;
412  }
413 
414  file.clear();
415  file.close();
416 
417  //using libzip to read SEDML file
418  /* SEDMLUtils utils;
419  std::string SEDMLFileName, fileContent("");
420  SEDMLFileName = "sedml.xml";
421 
422  int success = utils.processArchive(filename, SEDMLFileName, fileContent);*/
423 
424  pDataModel->setSEDMLFileName(filename);
425 
426  return this->parseSEDML(stringStream.str(), pImportHandler,
427  pSBMLDocument, pSedDocument, copasi2sedmlmap, copasi2sbmlmap, prLol, plotList, pDataModel);
428 }
CModel * parseSEDML(const std::string &sedmlDocumentText, CProcessReport *pImportHandler, SBMLDocument *&pSBMLDocument, SedDocument *&pSEDMLDocument, std::map< CCopasiObject *, SedBase * > &copasi2sedmlmap, std::map< CCopasiObject *, SBase * > &copasi2sbmlmap, CListOfLayouts *&prLol, COutputDefinitionVector *&plotList, CCopasiDataModel *pDataModel)
#define MCSEDML
static CLocaleString fromUtf8(const std::string &utf8)
void SEDMLImporter::restoreFunctionDB ( )

Definition at line 975 of file SEDMLImporter.cpp.

976 {
977 }
C_FLOAT64 SEDMLImporter::round ( const C_FLOAT64 x)
staticprotected

SEDMLImporter.cpp

Rev:

: Revision of last commit

Author:

: Author of last commit

Date:

: Date of last commit

HeadURL:
Id:

Definition at line 75 of file SEDMLImporter.cpp.

76 {
77  return
78  x < 0.0 ? -floor(-x + 0.5) : floor(x + 0.5);
79 }
void SEDMLImporter::setImportHandler ( CProcessReport pHandler)

Definition at line 81 of file SEDMLImporter.cpp.

References mpImportHandler.

82 {mpImportHandler = pHandler;}
CProcessReport * mpImportHandler
Definition: SEDMLImporter.h:60
void SEDMLImporter::updateCopasiTaskForSimulation ( SedSimulation *  sedmlsim,
std::map< CCopasiObject *, SedBase * > &  copasi2sedmlmap 
)

Updates COPASI tasks for a given SedML Simulation

Creates and returns a COPASI CTrajectoryTask from the SEDML simulation given as argument.

Definition at line 94 of file SEDMLImporter.cpp.

References CCopasiMessage::EXCEPTION, CCopasiTask::getProblem(), CCopasiDataModel::getTaskList(), mpDataModel, SEDML_KISAO_STOCHASTIC, CTrajectoryProblem::setContinueSimultaneousEvents(), CTrajectoryProblem::setDuration(), CTrajectoryTask::setMethodType(), CTrajectoryProblem::setOutputStartTime(), CCopasiTask::setScheduled(), CTrajectoryProblem::setStepNumber(), and CCopasiMethod::stochastic.

Referenced by importTasks().

96 {
97 
98  switch (sedmlsim->getTypeCode())
99  {
100  case SEDML_SIMULATION_UNIFORMTIMECOURSE:
101  {
102 
103  CTrajectoryTask *tTask = static_cast<CTrajectoryTask*>((*mpDataModel->getTaskList())["Time-Course"]);
104  tTask->setScheduled(true);
105 
106  CTrajectoryProblem* tProblem = static_cast<CTrajectoryProblem*>(tTask->getProblem());
107  SedUniformTimeCourse* tc = static_cast<SedUniformTimeCourse*>(sedmlsim);
108  tProblem->setOutputStartTime(tc->getOutputStartTime());
109  tProblem->setDuration(tc->getOutputEndTime() - tc->getOutputStartTime());
110  tProblem->setStepNumber(tc->getNumberOfPoints());
111  tProblem->setContinueSimultaneousEvents(true);
112 
113  // TODO read kisao terms
114  if (tc->isSetAlgorithm())
115  {
116  const SedAlgorithm* alg = tc->getAlgorithm();
117 
118  if (alg->isSetKisaoID())
119  {
120  if (alg->getKisaoID() == SEDML_KISAO_STOCHASTIC)
121  {
123  }
124  }
125  }
126 
127  break;
128  }
129 
130  case SEDML_SIMULATION_ONESTEP:
131  {
132 
133  CTrajectoryTask *tTask = static_cast<CTrajectoryTask*>((*mpDataModel->getTaskList())["Time-Course"]);
134  tTask->setScheduled(true);
135 
136  CTrajectoryProblem* tProblem = static_cast<CTrajectoryProblem*>(tTask->getProblem());
137  SedOneStep* step = static_cast<SedOneStep*>(sedmlsim);
138  tProblem->setOutputStartTime(0);
139  tProblem->setDuration(step->getStep());
140  tProblem->setStepNumber(1);
141 
142  // TODO read kisao terms
143 
144  break;
145  }
146 
147  case SEDML_SIMULATION_STEADYSTATE:
148  {
149  // nothing to be done for this one
150  CSteadyStateTask *tTask = static_cast<CSteadyStateTask*>((*mpDataModel->getTaskList())["Steady-State"]);
151  tTask->setScheduled(true);
152 
153  // TODO read kisao terms
154  //CCopasiProblem* tProblem = static_cast<CCopasiProblem*>(tTask->getProblem());
155  //SedSteadyState* tc = static_cast<SedSteadyState*>(sedmlsim);
156 
157  break;
158  }
159 
160  default:
161  CCopasiMessage(CCopasiMessage::EXCEPTION, "SEDMLImporter Error: encountered unknown simulation.");
162  break;
163  }
164 }
void setScheduled(const bool &scheduled)
CCopasiProblem * getProblem()
void setContinueSimultaneousEvents(const bool &continueSimultaneousEvents)
void setDuration(const C_FLOAT64 &duration)
CCopasiVectorN< CCopasiTask > * getTaskList()
void setStepNumber(const unsigned C_INT32 &stepNumber)
void setOutputStartTime(const C_FLOAT64 &endTime)
CCopasiDataModel * mpDataModel
Definition: SEDMLImporter.h:55
virtual bool setMethodType(const int &type)
#define SEDML_KISAO_STOCHASTIC
Definition: SEDMLUtils.h:22

Member Data Documentation

std::string SEDMLImporter::mArchiveFileName
protected

Definition at line 48 of file SEDMLImporter.h.

Referenced by getArchiveFileName().

size_t SEDMLImporter::mhImportStep
protected

Definition at line 62 of file SEDMLImporter.h.

Referenced by parseSEDML().

std::set<unsigned int> SEDMLImporter::mIgnoredSEDMLMessages
protected

Definition at line 49 of file SEDMLImporter.h.

Referenced by parseSEDML(), and SEDMLImporter().

std::string SEDMLImporter::mImportedModel
protected

Definition at line 68 of file SEDMLImporter.h.

Referenced by importFirstSBMLModel(), and importTasks().

unsigned C_INT32 SEDMLImporter::mImportStep
protected

Definition at line 61 of file SEDMLImporter.h.

Referenced by parseSEDML().

bool SEDMLImporter::mIncompleteModel
protected

Definition at line 50 of file SEDMLImporter.h.

unsigned int SEDMLImporter::mLevel
protected

Definition at line 51 of file SEDMLImporter.h.

Referenced by parseSEDML().

unsigned int SEDMLImporter::mOriginalLevel
protected

Definition at line 52 of file SEDMLImporter.h.

Referenced by parseSEDML().

CModel* SEDMLImporter::mpCopasiModel
protected

Definition at line 56 of file SEDMLImporter.h.

Referenced by deleteCopasiModel(), importFirstSBMLModel(), importTasks(), and parseSEDML().

CCopasiDataModel* SEDMLImporter::mpDataModel
protected
CProcessReport* SEDMLImporter::mpImportHandler
protected

Definition at line 60 of file SEDMLImporter.h.

Referenced by getImportHandlerAddr(), parseSEDML(), and setImportHandler().

SedDocument* SEDMLImporter::mpSEDMLDocument
protected
std::map<CReportDefinition*, std::string> SEDMLImporter::mReportMap
protected
unsigned C_INT32 SEDMLImporter::mTotalSteps
protected

Definition at line 63 of file SEDMLImporter.h.

Referenced by parseSEDML().

std::set<std::string> SEDMLImporter::mUsedSEDMLIds
protected

Definition at line 65 of file SEDMLImporter.h.

bool SEDMLImporter::mUsedSEDMLIdsPopulated
protected

Definition at line 66 of file SEDMLImporter.h.

Referenced by parseSEDML().

unsigned int SEDMLImporter::mVersion
protected

Definition at line 53 of file SEDMLImporter.h.

Referenced by parseSEDML().


The documentation for this class was generated from the following files: