COPASI API  4.16.103
CCellDesignerImporter.h
Go to the documentation of this file.
1 // Copyright (C) 2011 - 2013 by Pedro Mendes, Virginia Tech Intellectual
2 // Properties, Inc., University of Heidelberg, and The University
3 // of Manchester.
4 // All rights reserved.
5 
6 #ifndef CCellDesignerImporter_H__
7 #define CCellDesignerImporter_H__
8 
9 #include <vector>
10 #include <list>
11 #include <map>
12 #include <string>
13 #include <utility>
14 #include <limits>
15 
16 #include <sbml/packages/layout/sbml/BoundingBox.h>
17 #include <sbml/packages/layout/sbml/Curve.h>
18 #include <sbml/packages/layout/sbml/Dimensions.h>
19 #include <sbml/packages/layout/sbml/LineSegment.h>
20 #include <sbml/packages/layout/sbml/Point.h>
21 #include <sbml/packages/render/sbml/Text.h>
22 
24 
25 class ColorDefinition;
26 class GraphicalObject;
27 class RenderGroup;
28 class Layout;
29 class LocalRenderInformation;
30 class Model;
31 class Reaction;
32 class ReactionGlyph;
33 class SBase;
34 class SBMLDocument;
35 class SpeciesReferenceGlyphs;
36 class XMLNode;
37 
39 {
62  // the next three enums are actually not
63  // species classes but attributes on
64  // protein elements, but we will store them
65  // as a class enum
69 };
70 
72 {
88 };
89 
91 {
98 };
99 
101 {
120 };
121 
123 {
137 };
138 
140 {
159 };
160 
161 /**
162  * The positions are ordered so that the
163  * mid points of the edges come before corners
164  * and those come before the rest.
165  * This way the connection finding algorithm
166  * will favor connections to side midpoints
167  * before connections to other anchor points.
168  */
170 {
188 };
189 
191 {
195 };
196 
198 {
203 };
204 
206 {
210 };
211 
213 {
214  std::string mAlias;
215  std::string mSpecies;
217 
218  // Default constructor
219  LinkTarget();
220 };
221 
223 {
224  std::string mResidue;
226 
227  // default constructor
229 };
230 
231 // structure for the species state
233 {
234  std::vector<SpeciesModification> mModifications;
235 
236  // default constructor
237  SpeciesState();
238 };
239 
241 {
243  std::string mNameOrReference;
245 
246  // Default constructor
247  SpeciesIdentity();
248 };
249 
250 // structure for the modifications in a species state
252 {
254  std::string mParentComplex;
256 
257  // Default constructor
259 };
260 
262 {
263  std::string mName;
264 
265  // Default constructor
267 };
268 
269 struct Line
270 {
271  std::string mColor;
272  double mWidth;
273  bool mCurve;
274 
275  // Default constructor
276  Line();
277 };
278 
280 {
281  int mIndex;
282  int mArm;
284 
285  // default constructor
286  LineDirection();
287 };
288 
290 {
293  std::vector<LineDirection> mLineDirections;
294 
295  // default constructor
296  ConnectScheme();
297 };
298 
300 {
301  int mNum0;
302  int mNum1;
303  int mNum2;
306  std::vector<Point> mPoints;
307 
308  // default constructor
309  EditPoints();
310 };
311 
313 {
314  // attributes to the modification element
315  std::vector<std::string> mAliases;
316  std::vector<std::string> mModifiers;
319  // to calculate the absolute values
320  // of modification edit points,
321  // we need to calculate the vector from the
322  // anchor on the modifier to the anchor on the reaction
323  // The second vector is the vector with the same length that
324  // is orthogonal to the initial vector
325  // These two vectors seem to be used for the calculation
326  // of edit points
327  // Most modifications are unbranched, at least the ones we import
328  // so the edit points are listed from the modifier to the reaction symbol
330  int mNum0;
331  int mNum1;
332  int mNum2;
334  Point mOffset;
335 
336  // additional children to the modification element
338  std::vector<LinkTarget> mLinkTargets;
340 
341  // Default constructor
343 };
344 
346 {
347  // attributes
348  std::string mAlias;
349  std::string mReactant;
351 
352  // children
355 
356  // default constructor
357  ReactantLink();
358 };
359 
361 {
362  std::string mName;
364  std::vector<LinkTarget> mBaseReactants;
365  std::vector<LinkTarget> mBaseProducts;
366  std::vector<ReactantLink> mReactantLinks;
367  std::vector<ReactantLink> mProductLinks;
369  Point mOffset;
370 
371  // to calculate the absolute values
372  // of modification edit points we need to know
373  // if the reaction is branched or not.
374  // If it is an unbranched reaction with one base substrate
375  // and one base product
376  // we need to calculate the vector from the
377  // center of the base substrate to the center of the base product
378  // The second vector is the vector with the same length that
379  // is orthogonal to the initial vector
380  // These two vectors seem to be used for the calculation
381  // of edit points
382 
383  // for branched reactions we need the two vectors that run from the center
384  // of the first base substrate to the other two reactants centers
385  // These two vectors create a new coordinate system.
386  // The base points are listed from the reaction symbol to the reactant symbols
387  // if the reaction is branched
390  std::vector<ReactionModification> mModifications;
391 
392  // Default constructor
394 };
395 
396 // some structures for the general model annotation
397 //
399 {
400  std::string mId;
401  std::string mName;
402  std::string mCompartment;
403 
404  // we can use the same annotation as for the SBML species
406 
407  // default constructor
409 };
410 
411 struct Paint
412 {
413  // aRGB value
414  std::string mColor;
415  // optional scheme
416  // default seems to be Color
418 
419  // default constructor
420  Paint();
421 };
422 
424 {
425  double mInnerWidth;
426  double mOuterWidth;
427  double mThickness;
428 
429  // default constructor
430  DoubleLine();
431 };
432 
434 {
435  std::string mId;
436  std::string mCompartment;
437 
439  Point mNamePoint;
442  // a compartment alis either has a point or bounds
443  BoundingBox mBounds;
444  double mFontSize;
445 
446  // default constructor
448 };
449 
450 struct UsualView
451 {
453  Dimensions mBoxSize;
454  double mLineWidth;
456 
457  // default constructor
458  UsualView();
459 };
460 
461 // ComplexSpeciesAlias seems to have the
462 // same attributes and elements
463 // so we can use one structure for both
465 {
466  std::string mId;
467  std::string mSpecies;
468  std::string mComplexSpeciesAlias;
469  std::string mCompartmentAlias;
470  double mFontSize;
471  // store whether we are dealing with a complex
472  bool mComplex;
473 
474  BoundingBox mBounds;
476 
477  // default constructor
478  SpeciesAlias();
479 };
480 
482 {
483  std::string mId;
484  std::string mName;
485  double mAngle;
486 
487  // default constructor
489 };
490 
491 // data type to store protein data
492 // from the listOfProteins
493 struct Protein
494 {
495  std::string mId;
496  std::string mName;
498  std::vector<ProteinModification> mModifications;
499 
500  // default constructor
501  Protein();
502 };
503 
504 /**
505  * This class converts CellDesigner layout information
506  * into SBML layout.
507  * Maybe later versions will also be able to handle the
508  * render information part.
509  */
511 {
512 protected:
513 
514  // to work the class needs
515  // an SBMLDocument
516  SBMLDocument* mpDocument;
517 
518  // the result is stored in an instance of the
519  // SBML Layout class
520  Layout* mpLayout;
521 
522  // we also create local render information
523  LocalRenderInformation* mpLocalRenderInfo;
524 
525  // we need to store all ids so that we can create unique ids
526  // for new elements
527  std::map<std::string, const SBase*> mIdMap;
528 
529  // we need a map that associates the ids of CellDesigner aliases
530  // to the corresponding layout elements
531  // In case of complex species aliases, the id is assigned to
532  // the layout element that was created for the top most parent
533  std::map<std::string, GraphicalObject*> mCDIdToLayoutElement;
534 
535  // we need a map that associates the ids of CellDesigner aliases
536  // to their BoundingBoxes
537  std::map<std::string, BoundingBox> mCDBounds;
538 
539  // we need to store the associations between model element ids and layout elements
540  // Since there can be multiple representations in the layout per model element
541  // we have to use a multimap
542  std::multimap<std::string, GraphicalObject*> mModelIdToLayoutElement;
543 
544  // a map to store the location of compartment names
545  std::map<const CompartmentGlyph*, Point> mCompartmentNamePointMap;
546 
547  // we need a data structure that can store the dependencies of complex species aliases
548  std::list<CCopasiNode<std::string>*> mComplexDependencies;
549 
550  // a map that stores protein types for protein ids
551  std::map<std::string, Protein> mProteinInformationMap;
552 
553  // a map that stores antisense RNA names for antisense RNA ids
554  // These are used as TextGlyphs on antisense RNA nodes
555  //std::map<std::string,std::string> mASRNANameMap;
556 
557  // a map that stores RNA names for RNA ids
558  // These are used as TextGlyphs on RNA nodes
559  //std::map<std::string,std::string> mRNANameMap;
560 
561  // a map that stores gene names for gene ids
562  // These are used as TextGlyphs on gene nodes
563  //std::map<std::string,std::string> mGeneNameMap;
564 
565  // a map that maps color strings to the coorespnding id of the ColorDefinition
566  std::map<std::string, std::string> mColorStringMap;
567 
568  // a map that stores the CompartmentAlias information for a certain CompartmentGlyph
569  // We need this to create styles for the text glyphs
570  std::map<const CompartmentGlyph*, CompartmentAlias> mCompartmentAliasMap;
571 
572  // a map that stores the SpeciesAlias information for a certain SpeciesGlyph
573  // We need this to create styles for the text glyphs
574  std::map<const SpeciesGlyph*, SpeciesAlias> mSpeciesAliasMap;
575 
576  /**
577  * a map that associates the parsed alias data woth the id
578  * of the species alias or complex species alias
579  */
580  std::map<std::string, SpeciesAlias> mSpeciesAliases;
581 
582  /**
583  * a map that stores the species annotation with each species.
584  */
585  std::map<std::string, SpeciesAnnotation> mSpeciesAnnotationMap;
586 
587  /**
588  * a map that stores the compartment annotation with each compartment.
589  */
590  std::map<std::string, CompartmentAnnotation> mCompartmentAnnotationMap;
591 
592  /**
593  * a map that stores the name of a CellDesigner species with its id.
594  */
595  std::map<std::string, std::pair<std::string, SpeciesIdentity> > mIncludedSpeciesNameMap;;
596 
597  /**
598  * a map that associated a modifier type with the corresponding style.
599  */
600  std::map<MODIFICATION_LINK_TYPE, LocalStyle*> mModificationLinkStyleMap;
601 
602 public:
603  /**
604  * Constructor that takes a pointer to an
605  * SBMLDocument.
606  * The SBMLDocument will not be copied and it will not be
607  * owned by the importer.
608  * If the pointer is not NULL, the class will try
609  * to directly convert the CellDesigner layout if there is one.
610  */
611  CCellDesignerImporter(SBMLDocument* pDocument = 0);
612 
613  /**
614  * Method to set the SBMLDocument.
615  * If the pointer is not NULL, the class will try
616  * to directly convert the CellDesigner layout if there is one.
617  */
618  void setSBMLDocument(SBMLDocument* pDocument);
619 
620  /**
621  * Method to return a const poiner to the SBMLDocument.
622  */
623  const SBMLDocument* getSBMLDocument() const;
624 
625  /**
626  * Method to return the layout object.
627  * Since the laoyut object is owned by the importer,
628  * the caller should make a copy of the layout.
629  */
630  const Layout* getLayout() const;
631 
632  /**
633  * Goes through the SBMLDocument and tries to find a CellDesigner
634  * annotation.
635  * If one is found, a const pointer to the corresponding XMLNode
636  * is returned.
637  * If the current SBMLDocument is NULL or if no CellDesigner annotation
638  * is found, NULL is returned.
639  */
640  static const XMLNode* findCellDesignerAnnotation(SBMLDocument* pDocument, const XMLNode* pAnnotation);
641 
642  /**
643  * This method searches for the CellDesigner namespace in the annotation to the model
644  * as well as the annotation to the document.
645  * The method returns a pair of bool and string. The bool determines if the namespace was
646  * found and the string specifies the prefix for the namespace.
647  */
648  static std::pair<bool, std::string> findCellDesignerNamespace(const SBMLDocument* pDocument);
649 
650  /**
651  * Tries to find the version number of CellDesigner that was used to write
652  * this annotation.
653  * The node should be the CellDesigner annotation of the model.
654  * If the version number is not found or could not be parsed, we
655  * return -1.
656  */
657  static double determineVersion(const XMLNode* pNode);
658 
659 protected:
660  /**
661  * This method tries to convert the CellDesigner annotation to an SBML Layout.
662  * On success the method will return true and false otherwise.
663  */
664  bool convertCellDesignerLayout(const XMLNode* pCellDesignerAnnotation);
665 
666  /**
667  * Creates the compartment glyphs from the given node
668  * that represents the listOfCompartmentAliases.
669  */
670  bool createCompartmentGlyphs(const XMLNode* pLoCA);
671 
672  /**
673  * Creates the species glyphs from the given node
674  * that represents the listOfSpeciesAliases.
675  */
676  bool createSpeciesGlyphs(const XMLNode* pLoSA);
677 
678  /**
679  * Creates the compartment glyph from the given
680  * compartmentAliase structure.
681  */
683 
684  /**
685  * Creates the species glyph from the given
686  * SpeciesAliases structure.
687  */
688  bool createSpeciesGlyph(const SpeciesAlias& sa);
689 
690  /**
691  * Creates a unique id with the given prefix.
692  */
693  std::string createUniqueId(const std::string& prefix);
694 
695  /**
696  * Traverses the reactions of the model and looks for CellDesigner annotations.
697  * These are used to create reaction glyphs.
698  */
700 
701  /**
702  * Traverses the compartments of the model and looks for CellDesigner annotations.
703  * These are used to create text glyphs associated with compartments.
704  */
706 
707  /**
708  * Traverses the species of the model and looks for CellDesigner annotations.
709  * These are used to create text glyphs associated with species.
710  */
712 
713  /**
714  * Looks for CellDesigner annotation in the given reaction and ries to convert
715  * the information in that annotation into a ReactionGlyph.
716  */
717  bool convertReactionAnnotation(Reaction* pReaction, const Model* pModel);
718 
719  /**
720  * Takes a node that contains a number of baseReactants or baseProducts
721  * and creates species reference glyphs for each one.
722  */
723  bool createSpeciesReferenceGlyphs(ReactionGlyph* pRGlyph, const std::vector<LinkTarget>& link, std::map<SpeciesReferenceGlyph*, Point>& startsMap, bool reactants);
724 
725  /**
726  * Takes a bounding box and a position string and retirns the position on the bounding box that corresponds
727  * to the given position.
728  */
729  static Point getPositionPoint(const BoundingBox& box, POSITION position);
730 
731  /**
732  * Adds a new entry to the dependency tree for complex species aliases.
733  */
734  void addDependency(const std::string& parent, const std::string& child);
735 
736  /**
737  * Goes through the children of the given node which represents a list of
738  * protein definitions and check the types.
739  * If the type is RECEPTOR, ION_CHANNEL or TRUNCATED, store that information.
740  */
741  bool parseProteins(const XMLNode* pNode);
742 
743  /**
744  * Goes through the children of the given node which represents a list of protein definitions
745  * and collects the names for them.
746  * These names are converted to text glyphs for the proteins.
747  */
748  //bool parseGeneNames(const XMLNode* pNode);
749 
750  /**
751  * Goes through the children of the given node which represents a list of protein definitions
752  * and collects the names for them.
753  * These names are converted to text glyphs for the proteins.
754  */
755  //bool parseRNANames(const XMLNode* pNode);
756 
757  /**
758  * Goes through the children of the given node which represents a list of protein definitions
759  * and collects the names for them.
760  * These names are converted to text glyphs for the proteins.
761  */
762  //bool parseASRNANames(const XMLNode* pNode);
763 
764  /**
765  * Searches for a child with a certain name and a certain prefix
766  * in the tree based on pNode.
767  * The first child that fits the name and the prefix or NULL is returned.
768  * If recursive is true, the tree is searched recursively.
769  */
770  static const XMLNode* findChildNode(const XMLNode* pNode, const std::string& prefix, const std::string& name, bool recursive = false);
771 
772  /**
773  * Parses the node which represents a speciesIdentity node and fills the given SpeciesIdentity
774  * structure with the data.
775  * If the parsing fails, false is returned.
776  */
777  static bool parseSpeciesIdentity(const XMLNode* pNode, SpeciesIdentity& identity);
778 
779  /**
780  * Parses the node which represents the state in a speciesIdentity node and fills the given SpeciesState
781  * structure with the data.
782  * If the parsing fails, false is returned.
783  */
784  static bool parseSpeciesState(const XMLNode* pNode, SpeciesState& state);
785 
786  /**
787  * Parses the node which represents a modification ion a species node and fills the given SpeciesModification
788  * structure with the data.
789  * If the parsing fails, false is returned.
790  */
791  static bool parseSpeciesModification(const XMLNode* pNode, SpeciesModification& mod);
792 
793  /**
794  * Tries to parse the species annotation in the given node and stores the data in the given
795  * SpeciesAnnotation structure.
796  * If parsing fails, false is returned.
797  */
798  static bool parseSpeciesAnnotation(const XMLNode* pNode, SpeciesAnnotation& anno);
799 
800  /**
801  * Tries to parse the compartment annotation in the given node and stores the data in the given
802  * CompartmentAnnotation structure.
803  * If parsing fails, false is returned.
804  */
805  static bool parseCompartmentAnnotation(const XMLNode* pNode, CompartmentAnnotation& anno);
806 
807  /**
808  * Tries to parse the reaction annotation in the given node and stores the data in the given
809  * ReactionAnnotation structure.
810  * If parsing fails, false is returned.
811  */
812  static bool parseReactionAnnotation(const XMLNode* pNode, ReactionAnnotation& ranno);
813 
814  /**
815  * Parses the given node and stored the information iín the width and height attribute
816  * in the given dimensions object.
817  * If parsinf fails, false is returned.
818  */
819  static bool parseBoxSize(const XMLNode* pNode, Dimensions& d);
820 
821  /**
822  * Parses the data in the given node which represents a UsualView object and stores
823  * the parsed data in the given UsualView structure.
824  * If parsinf fails, false is returned.
825  */
826  static bool parseUsualView(const XMLNode* pNode, UsualView& view);
827 
828  /**
829  * Parse the data in the given node assuming that this is a node that represents a point
830  * and therefore contains an "x" and a "y" attribute.
831  * The data is stored in the given point object.
832  * If parsing fails, false is returned.
833  */
834  static bool parseBounds(const XMLNode* pNode, BoundingBox& box);
835 
836  /**
837  * Parse the data in the given node assuming that this is a node that represents a point
838  * and therefore contains an "x" and a "y" attribute.
839  * The data is stored in the given point object.
840  * If parsing fails, false is returned.
841  */
842  static bool parsePoint(const XMLNode* pNode, Point& p);
843 
844  /**
845  * Parses the data in the given node which represents a species
846  * (or ComplexSpecies) alias
847  * and stores it in the given SpeciesAlias structure.
848  * If parsing fails, false is returned.
849  */
850  static bool parseSpeciesAlias(const XMLNode* pNode, SpeciesAlias& sa);
851 
852  /**
853  * Parses the data in the given node which represents a compartment alias
854  * and stores it in the given CompartmentAlias structure.
855  * If parsing fails, false is returned.
856  */
857  static bool parseCompartmentAlias(const XMLNode* pNode, CompartmentAlias& ca, const Dimensions& layout_dimensions);
858 
859  /**
860  * Parses the given XMLNode which represents a double line element.
861  * The parsed data is stored in the given DoubleLine structure.
862  * If parsing fails, false is returned.
863  */
864  static bool parseDoubleLine(const XMLNode* pNode, DoubleLine& dl);
865 
866  /**
867  * Parses the modelDisplay data in the given XMLNode and stores the result in the
868  * given Dimensions structure.
869  * If parsing fails, false is returned.
870  */
871  static bool parseModelDisplay(const XMLNode* pNode, Dimensions& d);
872 
873  /**
874  * Parses the paint data in the given XMLNode and stores the result in the
875  * given Paint structure.
876  * If parsing fails, false is returned.
877  */
878  static bool parsePaint(const XMLNode* pNode, Paint& p);
879 
880  /**
881  * Tries to parse the reaction elements (baseReactants or baseProducts) in the given
882  * node and stores the data in the given ReactionAnnotation structure.
883  * If parsing fails, false is returned.
884  */
885  static bool parseReactionElements(const XMLNode* pNode, std::vector<LinkTarget>& elements);
886 
887  /**
888  * Tries to parse the connection scheme in the given node and stores the data in the given
889  * ConnectionScheme structure.
890  * If parsing fails, false is returned.
891  */
892  static bool parseConnectScheme(const XMLNode* pNode, ConnectScheme& scheme);
893 
894  /**
895  * Tries to parse the line data in the given node and stores the data in the given
896  * Line structure.
897  * If parsing fails, false is returned.
898  */
899  static bool parseLine(const XMLNode* pNode, Line& line);
900 
901  /**
902  * Tries to parse the extra reactant links in the given node and stores the data in the given
903  * vector of ReactantLinks structure.
904  * If parsing fails, false is returned.
905  */
906  static bool parseExtraLinks(const XMLNode* pNode, std::vector<ReactantLink>& rlinks);
907 
908  /**
909  * Tries to parse the edit points in the given node and stores the data in the given
910  * vector of Points.
911  * If parsing fails, false is returned.
912  */
913  static bool parseEditPoints(const XMLNode* pNode, EditPoints& editpoints);
914 
915  /**
916  * Tries to parse the reaction modifications in the given node and stores the data in the given
917  * vector of ReactionModifications.
918  * If parsing fails, false is returned.
919  */
920  static bool parseReactionModifications(const XMLNode* pNode, std::vector<ReactionModification>& rmods);
921 
922  /**
923  * Tries to parse the link target in the given node and stores the data in the given
924  * vector of LinkTarget structure.
925  * If parsing fails, false is returned.
926  */
927  static bool parseLinkTarget(const XMLNode* pNode, LinkTarget& l);
928 
929  /**
930  * Tries to parse the line direction in the given node and stores the data in the given
931  * vector of LineDirection structure.
932  * If parsing fails, false is returned.
933  */
934  static bool parseLineDirection(const XMLNode* pNode, LineDirection& d);
935 
936  /**
937  * Tries to parse the wreactant link in the given node and stores the data in the given
938  * vector of ReactionLink structure.
939  * If parsing fails, false is returned.
940  */
941  static bool parseExtraLink(const XMLNode* pNode, ReactantLink& l);
942 
943  /**
944  * Tries to parse the w2D points in the given string and stores the data in the given
945  * vector of Points.
946  * If parsing fails, false is returned.
947  */
948  static bool parsePointsString(const std::string& s, std::vector<Point>& points);
949 
950  /**
951  * Tries to parse the reaction modification in the given node and stores the data in the given
952  * ReactionModification structure.
953  * If parsing fails, false is returned.
954  */
955  static bool parseReactionModification(const XMLNode* pNode, ReactionModification& mod);
956 
957  /**
958  * Tries to parse the protein modification in the given node and stores the data in the given
959  * ProteinModification structure.
960  * If parsing fails, false is returned.
961  */
962  static bool parseProteinModification(const XMLNode* pNode, ProteinModification& mod);
963 
964  /**
965  * Tries to parse the CellDesigner species in the listOfincludedSpecies.
966  * If parsing fails, false is returned.
967  */
968  bool handleIncludedSpecies(const XMLNode* pNode);
969 
970  /**
971  * Converts the given paint scheme string to the correspnding PAINT_SCHEME enum value.
972  * If no enum is found, PAINT_UNDEFINED is returned.
973  */
974  static PAINT_SCHEME paintSchemeToEnum(std::string s);
975 
976  /*
977  * Converts the given modification string to the correspnding MODIFICATION_TYPE enum value.
978  * If no enum is found, UNDEFINED_MOD_TYPE is returned.
979  */
981 
982  /**
983  * Converts the given class string to the correspnding SPECIES_CLASS enum value.
984  * If no enum is found, UNDEFINED is returned.
985  */
986  static SPECIES_CLASS classToEnum(std::string cl);
987 
988  /**
989  * Converts the given position string to an enum.
990  */
991  static POSITION positionToEnum(std::string pos);
992 
993  /**
994  * Converts the given reaction type string to the corresponding enum.
995  * If there is no enum that corresponds to the string, UNDEFINED_RTYPE is returned.
996  */
997  static REACTION_TYPE reactionTypeToEnum(std::string s);
998 
999  /**
1000  * Converts the given modification link type string to the corresponding enum.
1001  * If there is no enum that corresponds to the string, UNDEFINED_ML_TYPE is returned.
1002  */
1003  static MODIFICATION_LINK_TYPE modificationLinkTypeToEnum(std::string s);
1004 
1005  /**
1006  * Converts the given modification type string to the corresponding enum.
1007  * If there is no enum that corresponds to the string, UNDEFINED_MTYPE is returned.
1008  */
1009  static MODIFICATION_TYPE modificationTypeToEnum(std::string s);
1010 
1011  /**
1012  * Converts the given position to compartment string to the corresponding enum.
1013  * If there is no enum that corresponds to the string, UNDEFINED_POSITION is returned.
1014  */
1016 
1017  /**
1018  * Converts the given connection policy string to the corresponding enum.
1019  * If there is no enum that corresponds to the string, POLICY_UNDEFINED is returned.
1020  */
1021  static CONNECTION_POLICY connectionPolicyToEnum(std::string s);
1022 
1023  /**
1024  * Converts the given direction string to the corresponding enum.
1025  * If there is no enum that corresponds to the string, DIRECTION_UNDEFINED is returned.
1026  */
1027  static DIRECTION_VALUE directionToEnum(std::string s);
1028 
1029  /**
1030  * Splits the given string at each character occurs in splitChars.
1031  * The parts generated are stored in the given vector.
1032  * The vector is cleared by the method.
1033  * If something goes wrong false is returned.
1034  */
1035  static bool splitString(const std::string& s, std::vector<std::string>& parts, const std::string& splitChars);
1036 
1037  /**
1038  * This method creates a new local style based on the passed in CompartmentAlias object.
1039  * The style is associated with the object via the given id.
1040  * If Creating the style fails, false is returned.
1041  */
1042  bool createCompartmentStyle(const CompartmentAlias& ca, const CompartmentGlyph* pCGlyph);
1043 
1044  /**
1045  * This method creates a new local style based on the passed in SpeciesAlias object.
1046  * The style is associated with the object via the given id.
1047  * If Creating the style fails, false is returned.
1048  bool createSpeciesStyle(const SpeciesAlias& sa,const std::string& objectReference);
1049  */
1050 
1051  /**
1052  * Creates a local style for a certain text glyph.
1053  * The style is associated with the text glyph via the id
1054  * of the text glyph.
1055  */
1056  bool createTextGlyphStyle(double size, Text::TEXT_ANCHOR hAlign, Text::TEXT_ANCHOR vAlign, const std::string& objectReference);
1057 
1058  /**
1059  * TODO right now, we use default styles for species reference glyphs
1060  * TODO and reaction glyphs.
1061  * TODO These are created here.
1062  * TODO later we have to create individual styles based on the type of reaction
1063  * TODO and the color set in the CellDesigner annotation.
1064  */
1065  bool createDefaultStyles();
1066 
1067  /**
1068  * Adds all possible POSITION enums to the given vector.
1069  * The vector is cleared first.
1070  */
1071  static void addAllPositions(std::vector<POSITION>& v);
1072 
1073  /**
1074  * Finds the shortest connection between two objects given the potential
1075  * connection positions for each object and the bounding boxes for each object.
1076  * The result is returned in the original vectors as position values.
1077  * If the method fails, e.g. because one of the vectors is empty or the bounding box contains
1078  * values we can't use for calculations (ing,NAN), false is returned.
1079  */
1080  static bool findShortestConnection(std::vector<POSITION>& pos1, std::vector<POSITION>& pos2, const BoundingBox& box1, const BoundingBox& box2);
1081 
1082  /**
1083  * Finds the shortest connection between the given point and the object which is
1084  * defined by its connection positions and its bounding box.
1085  * If the method fails, e.g. because one of the vectors is empty or the bounding box contains
1086  * values we can't use for calculations (ing,NAN), POSITION_UNDEFINED
1087  */
1088  static POSITION findShortestConnection(const Point& p, std::vector<POSITION>& pos, const BoundingBox& box);
1089 
1090  /**
1091  * Calculate the distance between the two points.
1092  */
1093  static double distance(const Point& p1, const Point& p2);
1094 
1095  /**
1096  * Checks if the given ReactantLink object has a valid linkAnchor
1097  * If not, we try to determine the best anchor be finding the one that is closest
1098  * to the given point.
1099  */
1100  void checkLinkAnchor(LinkTarget& link, const Point& p);
1101 
1102  /**
1103  * Checks if the given ReactantLink objects have valid linkAnchors
1104  * If not, we try to determine the best anchor be finding the ones that
1105  * give the shortest connection between the two objects
1106  */
1107  void checkLinkAnchors(LinkTarget& substrate, LinkTarget& product);
1108 
1109  /**
1110  * Calculates the absolute position for point p
1111  * based on the three other points (p1,p2,p3) given.
1112  * The formula for that is:
1113  * p1 + p.x * (p2 - p1) + p.y * (p3 - p1)
1114  */
1115  static Point calculateAbsoluteValue(const Point& p, const Point& p1, const Point& p2, const Point& p3);
1116 
1117  /**
1118  * Tries to set the species glyph id in the given species reference glyph.
1119  */
1120  bool setSpeciesGlyphId(SpeciesReferenceGlyph* pGlyph, const LinkTarget& link);
1121 
1122  /**
1123  * Tries to set the species reference id on the given SPeciesReferenceGlyph.
1124  */
1125  bool setSpeciesReferenceId(SpeciesReferenceGlyph* pGlyph, const LinkTarget& link, const std::string& reactionId);
1126 
1127  /**
1128  * Creates the structures for the extra product links.
1129  * If processing fails, false is returned;
1130  */
1131  bool handleExtraReactionElements(ReactionGlyph* pRGlyph, ReactionAnnotation& ranno, bool substrate);
1132 
1133  /**
1134  * Creates the structures for the modification links
1135  * in a reaction.
1136  * If processing fails, false is returned;
1137  */
1138  bool handleModificationLinks(ReactionGlyph* pRGlyph, ReactionAnnotation& ranno);
1139 
1140  /**
1141  * Create default style for reaction glyphs.
1142  */
1144 
1145  /**
1146  * Create default style for modifiers.
1147  */
1149 
1150  /**
1151  * Create style for catalysis.
1152  */
1153  bool createCatalysisStyles();
1154 
1155  /**
1156  * Create default style for inhibitors.
1157  */
1159 
1160  /**
1161  * Create default style for activators.
1162  */
1164 
1165  /**
1166  * Create default style for products.
1167  */
1169 
1170  /**
1171  * Create default style for substrates.
1172  */
1174 
1175  /**
1176  * Create a primitive that corresponds to the given species specific class
1177  * The primitive is created in the given group object.
1178  * The complete primitive is translated by the given offset.
1179  *
1180  * If creation of the primitive fails, false is returned.
1181  */
1182  bool createPrimitive(RenderGroup* pGroup,
1183  const SpeciesIdentity& si,
1184  const BoundingBox& bounds,
1185  const Point& offset,
1186  double stroke_width,
1187  const std::string& stroke_color,
1188  const std::string& fill_color,
1189  const std::string& text = ""
1190  );
1191 
1192  /**
1193  * Takes a protein modification description and creates the corresponding primitive.
1194  */
1195  bool createProteinModification(RenderGroup* pGroup,
1196  const SpeciesModification& smod,
1197  const BoundingBox& bounds,
1198  const std::string& stroke_color
1199  );
1200 
1201  /**
1202  * Creates styles for all species glyphs.
1203  */
1204  bool createSpeciesStyles();
1205 
1206  /**
1207  * Check if a color with the given color string already exists.
1208  * If so, the id of the color is set on the given id string.
1209  * If the color does not exist yet, a color definition for it is
1210  * created and the id of the newly created color is returned in
1211  * the id string.
1212  * If color creation fails, false is returned by the method.
1213  */
1214  bool findOrCreateColorDefinition(const std::string& color_string, std::string& id);
1215 
1216  /**
1217  * Tries to find the name for the given species identity.
1218  * If the name was found, it is returned in the name argument.
1219  * If something goes wrong, false is returend.
1220  */
1221  //bool findNameForSpeciesIdentity(const SpeciesIdentity& identity,std::string& name);
1222 
1223  /**
1224  * Goes through the dependency graph
1225  * and tries to find the root element for the given species alias id.
1226  */
1227  std::string findRootElementId(const std::string& id) const;
1228 
1229  /**
1230  * Creates a vector that is orthogonal to the given first vector.
1231  * If there is a problem, false is returned.
1232  */
1233  static bool createOrthogonal(const Point& v1, Point& v2);
1234 
1235  /**
1236  * Calculates the angle between the given vector and the positive x axis.
1237  * The result is returned in radians.
1238  */
1239  static double angle(const Point& v);
1240 
1241  /**
1242  * Calculates the position of point p after rotation by angle a
1243  * around the origin.
1244  * The angle is given in radians.
1245  * The result is returned in r.
1246  */
1247  static void rotate(const Point& p, double a, Point& r);
1248 
1249  /**
1250  * This method takes a pointer to a curve object
1251  * as well as a start iterator and an end iterator which
1252  * both iterate over a datastructure that contains points.
1253  * For each point pair, a line segment is created and added to
1254  * curve.
1255  * The new curve segments are added to the end of the curve.
1256  *
1257  * If no error occurs, true is returned, else false is returned.
1258  */
1259  template<typename ITERATOR>
1260  static bool createLineSegments(Curve* pCurve, ITERATOR start, ITERATOR end)
1261  {
1262  bool result = true;
1263 
1264  // check if there is a curve and if there are points
1265  if (pCurve != NULL && start != end)
1266  {
1267  ITERATOR tmpEnd = end;
1268  --tmpEnd;
1269 
1270  // make sure there is more than one point
1271  if (start != tmpEnd)
1272  {
1273  LineSegment* pLS = pCurve->createLineSegment();
1274  pLS->setStart(&(*start));
1275  ++start;
1276 
1277  while (start != tmpEnd)
1278  {
1279  pLS->setEnd(&(*start));
1280  pLS = pCurve->createLineSegment();
1281  pLS->setStart(&(*start));
1282  ++start;
1283  }
1284 
1285  pLS->setEnd(&(*start));
1286  }
1287  else
1288  {
1289  result = false;
1290  }
1291  }
1292  else
1293  {
1294  result = false;
1295  }
1296 
1297  return result;
1298  }
1299 
1300  /**
1301  * Returns the color string for the given color id
1302  * or an empty string if the color id was not found.
1303  */
1304  std::string getColorString(const std::string& color_id) const;
1305 };
1306 
1307 #endif // CCellDesignerImporter_H__
PAINT_SCHEME mScheme
std::vector< LineDirection > mLineDirections
const Layout * getLayout() const
SPECIES_CLASS mType
static Point getPositionPoint(const BoundingBox &box, POSITION position)
std::string mColor
std::vector< LinkTarget > mBaseProducts
void checkLinkAnchors(LinkTarget &substrate, LinkTarget &product)
std::string createUniqueId(const std::string &prefix)
DIRECTION_VALUE mValue
std::string findRootElementId(const std::string &id) const
std::string mCompartmentAlias
std::string mComplexSpeciesAlias
std::vector< ReactionModification > mModifications
bool createProteinModification(RenderGroup *pGroup, const SpeciesModification &smod, const BoundingBox &bounds, const std::string &stroke_color)
static POSITION_TO_COMPARTMENT positionToCompartmentToEnum(std::string s)
static bool parseEditPoints(const XMLNode *pNode, EditPoints &editpoints)
SPECIES_CLASS mSpeciesClass
bool createPrimitive(RenderGroup *pGroup, const SpeciesIdentity &si, const BoundingBox &bounds, const Point &offset, double stroke_width, const std::string &stroke_color, const std::string &fill_color, const std::string &text="")
static bool parseSpeciesState(const XMLNode *pNode, SpeciesState &state)
std::vector< ProteinModification > mModifications
bool createSpeciesReferenceGlyphs(ReactionGlyph *pRGlyph, const std::vector< LinkTarget > &link, std::map< SpeciesReferenceGlyph *, Point > &startsMap, bool reactants)
static CONNECTION_POLICY connectionPolicyToEnum(std::string s)
static bool parseExtraLinks(const XMLNode *pNode, std::vector< ReactantLink > &rlinks)
static POSITION positionToEnum(std::string pos)
static bool parseBoxSize(const XMLNode *pNode, Dimensions &d)
static bool parseModelDisplay(const XMLNode *pNode, Dimensions &d)
static const XMLNode * findCellDesignerAnnotation(SBMLDocument *pDocument, const XMLNode *pAnnotation)
static bool parseBounds(const XMLNode *pNode, BoundingBox &box)
static double distance(const Point &p1, const Point &p2)
std::list< CCopasiNode< std::string > * > mComplexDependencies
std::vector< std::string > mModifiers
std::map< const CompartmentGlyph *, Point > mCompartmentNamePointMap
static bool parseDoubleLine(const XMLNode *pNode, DoubleLine &dl)
std::map< std::string, CompartmentAnnotation > mCompartmentAnnotationMap
bool createSpeciesGlyphs(const XMLNode *pLoSA)
SPECIES_MODIFICATION_TYPE
static bool parseReactionModification(const XMLNode *pNode, ReactionModification &mod)
std::map< std::string, GraphicalObject * > mCDIdToLayoutElement
std::vector< std::string > mAliases
bool setSpeciesGlyphId(SpeciesReferenceGlyph *pGlyph, const LinkTarget &link)
bool createCompartmentGlyph(const CompartmentAlias &ca)
bool createCompartmentStyle(const CompartmentAlias &ca, const CompartmentGlyph *pCGlyph)
bool createCompartmentGlyphs(const XMLNode *pLoCA)
CONNECTION_POLICY mPolicy
SPECIES_MODIFICATION_TYPE mType
LocalRenderInformation * mpLocalRenderInfo
std::vector< LinkTarget > mLinkTargets
static bool parseLine(const XMLNode *pNode, Line &line)
bool findOrCreateColorDefinition(const std::string &color_string, std::string &id)
std::map< const SpeciesGlyph *, SpeciesAlias > mSpeciesAliasMap
std::vector< ReactantLink > mProductLinks
static void addAllPositions(std::vector< POSITION > &v)
std::string getColorString(const std::string &color_id) const
std::string mNameOrReference
static std::pair< bool, std::string > findCellDesignerNamespace(const SBMLDocument *pDocument)
std::map< std::string, std::pair< std::string, SpeciesIdentity > > mIncludedSpeciesNameMap
static bool parseSpeciesAnnotation(const XMLNode *pNode, SpeciesAnnotation &anno)
void setSBMLDocument(SBMLDocument *pDocument)
MODIFICATION_LINK_TYPE
std::map< std::string, SpeciesAnnotation > mSpeciesAnnotationMap
static bool createOrthogonal(const Point &v1, Point &v2)
MODIFICATION_LINK_TYPE mType
bool createTextGlyphStyle(double size, Text::TEXT_ANCHOR hAlign, Text::TEXT_ANCHOR vAlign, const std::string &objectReference)
static bool parseReactionModifications(const XMLNode *pNode, std::vector< ReactionModification > &rmods)
void addDependency(const std::string &parent, const std::string &child)
std::vector< SpeciesModification > mModifications
std::string mAlias
bool parseProteins(const XMLNode *pNode)
bool handleModificationLinks(ReactionGlyph *pRGlyph, ReactionAnnotation &ranno)
static bool parsePointsString(const std::string &s, std::vector< Point > &points)
bool handleIncludedSpecies(const XMLNode *pNode)
enum POSITION_TO_COMPARTMENT mPosition
static MODIFICATION_LINK_TYPE modificationLinkTypeToEnum(std::string s)
std::map< MODIFICATION_LINK_TYPE, LocalStyle * > mModificationLinkStyleMap
static SPECIES_MODIFICATION_TYPE speciesModificationTypeToEnum(std::string cl)
static bool parseUsualView(const XMLNode *pNode, UsualView &view)
std::map< std::string, BoundingBox > mCDBounds
const SBMLDocument * getSBMLDocument() const
std::map< std::string, const SBase * > mIdMap
static bool parseReactionAnnotation(const XMLNode *pNode, ReactionAnnotation &ranno)
std::vector< LinkTarget > mBaseReactants
static bool parseSpeciesModification(const XMLNode *pNode, SpeciesModification &mod)
POSITION_TO_COMPARTMENT
std::string mId
static double angle(const Point &v)
bool handleExtraReactionElements(ReactionGlyph *pRGlyph, ReactionAnnotation &ranno, bool substrate)
static MODIFICATION_TYPE modificationTypeToEnum(std::string s)
static bool parseReactionElements(const XMLNode *pNode, std::vector< LinkTarget > &elements)
std::string mSpecies
static bool findShortestConnection(std::vector< POSITION > &pos1, std::vector< POSITION > &pos2, const BoundingBox &box1, const BoundingBox &box2)
static bool parseLinkTarget(const XMLNode *pNode, LinkTarget &l)
static bool parseConnectScheme(const XMLNode *pNode, ConnectScheme &scheme)
static REACTION_TYPE reactionTypeToEnum(std::string s)
std::map< std::string, std::string > mColorStringMap
static bool parseCompartmentAlias(const XMLNode *pNode, CompartmentAlias &ca, const Dimensions &layout_dimensions)
std::string mName
static SPECIES_CLASS classToEnum(std::string cl)
Dimensions mBoxSize
std::map< const CompartmentGlyph *, CompartmentAlias > mCompartmentAliasMap
static DIRECTION_VALUE directionToEnum(std::string s)
static Point calculateAbsoluteValue(const Point &p, const Point &p1, const Point &p2, const Point &p3)
static bool parsePaint(const XMLNode *pNode, Paint &p)
bool setSpeciesReferenceId(SpeciesReferenceGlyph *pGlyph, const LinkTarget &link, const std::string &reactionId)
std::map< std::string, SpeciesAlias > mSpeciesAliases
bool convertReactionAnnotation(Reaction *pReaction, const Model *pModel)
MODIFICATION_TYPE mModType
static PAINT_SCHEME paintSchemeToEnum(std::string s)
CCellDesignerImporter(SBMLDocument *pDocument=0)
std::vector< ReactantLink > mReactantLinks
static bool createLineSegments(Curve *pCurve, ITERATOR start, ITERATOR end)
SpeciesAnnotation mAnnotation
static double determineVersion(const XMLNode *pNode)
static bool splitString(const std::string &s, std::vector< std::string > &parts, const std::string &splitChars)
static const XMLNode * findChildNode(const XMLNode *pNode, const std::string &prefix, const std::string &name, bool recursive=false)
std::string mColor
static bool parseExtraLink(const XMLNode *pNode, ReactantLink &l)
bool createSpeciesGlyph(const SpeciesAlias &sa)
static bool parseProteinModification(const XMLNode *pNode, ProteinModification &mod)
std::map< std::string, Protein > mProteinInformationMap
std::vector< Point > mPoints
static void rotate(const Point &p, double a, Point &r)
static bool parseSpeciesAlias(const XMLNode *pNode, SpeciesAlias &sa)
static bool parsePoint(const XMLNode *pNode, Point &p)
bool convertCellDesignerLayout(const XMLNode *pCellDesignerAnnotation)
static bool parseCompartmentAnnotation(const XMLNode *pNode, CompartmentAnnotation &anno)
void checkLinkAnchor(LinkTarget &link, const Point &p)
static bool parseLineDirection(const XMLNode *pNode, LineDirection &d)
static bool parseSpeciesIdentity(const XMLNode *pNode, SpeciesIdentity &identity)
std::multimap< std::string, GraphicalObject * > mModelIdToLayoutElement
SpeciesIdentity mIdentity