Class PathwayModel

java.lang.Object
org.pathvisio.libgpml.model.PathwayModel

public class PathwayModel
extends java.lang.Object
This class stores information for a Pathway model. Pathway model contains pathway elements and properties. The pathway model stores all information necessary for maintaining, loading and saving pathway data; reading in, writing from.
Author:
unknown, finterly
  • Field Details

    • pathway

      private Pathway pathway
    • elementIdToPathwayObject

      private java.util.Map<java.lang.String,​PathwayObject> elementIdToPathwayObject
    • elementRefToLinePoints

      private java.util.Map<GraphLink.LinkableTo,​java.util.Set<GraphLink.LinkableFrom>> elementRefToLinePoints
    • aliasRefToAliases

      private java.util.Map<Group,​java.util.Set<DataNode>> aliasRefToAliases
    • dataNodes

      private java.util.List<DataNode> dataNodes
    • interactions

      private java.util.List<Interaction> interactions
    • graphicalLines

      private java.util.List<GraphicalLine> graphicalLines
    • labels

      private java.util.List<Label> labels
    • shapes

      private java.util.List<Shape> shapes
    • groups

      private java.util.List<Group> groups
    • annotations

      private java.util.List<Annotation> annotations
    • citations

      private java.util.List<Citation> citations
    • evidences

      private java.util.List<Evidence> evidences
    • sourceFile

      private java.io.File sourceFile
    • changed

      private boolean changed
    • statusFlagListeners

      private java.util.List<PathwayModel.StatusFlagListener> statusFlagListeners
    • listeners

      private java.util.List<PathwayModelListener> listeners
  • Constructor Details

    • PathwayModel

      public PathwayModel()
      Initializes a pathway model object with default Pathway.
  • Method Details

    • getPathway

      public Pathway getPathway()
      Returns the pathway object containing metadata, e.g. title, organism.
      Returns:
      pathway the pathway meta information.
    • replacePathway

      protected void replacePathway​(Pathway newP)
      Replaces the Pathway, calls removeOldPathway(org.pathvisio.libgpml.model.Pathway) and then setNewPathway(org.pathvisio.libgpml.model.Pathway). NB: There can only be one pathway per pathway model.
      Parameters:
      newP - the new pathway info.
    • removeOldPathway

      private void removeOldPathway​(Pathway oldP)
      Parameters:
      oldP - the old pathway.
    • setNewPathway

      private void setNewPathway​(Pathway newP)
      Parameters:
      newP - the new pathway to be set.
    • getPathwayElements

      public java.util.List<PathwayElement> getPathwayElements()
      Returns all pathway elements for the pathway model (pathway, dataNodes, interactions, graphicalLines, labels, shapes, and groups). Includes Pathway.
      Returns:
      the pathway elements for this pathway model.
    • getShapedElements

      public java.util.List<ShapedElement> getShapedElements()
      Returns all shaped pathway elements for the pathway model (dataNodes, states, labels, shapes, and groups). NB: Includes states.
      Returns:
      the pathway elements for this pathway model.
    • getShapedElementsExclStates

      public java.util.List<ShapedElement> getShapedElementsExclStates()
      Returns all shaped pathway elements for the pathway model (dataNodes, labels, shapes, and groups). NB: Excludes states.
      Returns:
      the pathway elements for this pathway model.
    • getLineElements

      public java.util.List<LineElement> getLineElements()
      Returns all line pathway elements for the pathway model (interactions and graphicalLines).
      Returns:
      the pathway elements for this pathway model.
    • getUniqueElementId

      public java.lang.String getUniqueElementId()
      Returns a unique elementId.
      Returns:
      a unique elementId.
    • getPathwayObject

      public PathwayObject getPathwayObject​(java.lang.String elementId)
      Returns Pathway Object for the given String elementId key.
      Parameters:
      elementId - the given elementId key.
      Returns:
      the PathwayObject for the given elementId key.
    • getPathwayObjects

      public java.util.List<PathwayObject> getPathwayObjects()
      Returns all pathway objects for the pathway model.
      Returns:
      pathwayObjects the pathway objects for this pathway model.
    • hasPathwayObject

      public boolean hasPathwayObject​(PathwayObject pathwayObject)
      Checks if the pathway model has the given pathway object.
      Parameters:
      pathwayObject - the pathway object to check for.
      Returns:
      true if pathway model has given pathway object, false otherwise.
    • getElementIds

      public java.util.Set<java.lang.String> getElementIds()
      Returns a set view of String elementId keys from the elementIdToPathwayObject hash map.
      Returns:
      a list of elementId keys.
    • addElementId

      public void addElementId​(java.lang.String elementId, PathwayObject pathwayObject)
      Adds mapping of elementId key to PathwayObject value in the elementIdToPathwayObject hash map.
      Parameters:
      elementId - the elementId
      pathwayObject - the pathway object
      Throws:
      java.lang.IllegalArgumentException - if elementId or elementIdContainer are null.
      java.lang.IllegalArgumentException - if elementId is not unique.
    • removeElementId

      protected void removeElementId​(java.lang.String elementId)
      Removes the mapping of given elementId key from the elementIdToPathwayObject hash map.
      Parameters:
      elementId - the elementId key.
    • getUniqueId

      public static java.lang.String getUniqueId​(java.util.Set<java.lang.String> ids)
      Randomly generates a new unique ID, based on strings of hex digits (0..9 or a..f) given a set of existing IDs.
      Parameters:
      ids - the collection of already existing IDs.
      Returns:
      result the new unique ID.
    • getReferringLinkableFroms

      public java.util.Set<GraphLink.LinkableFrom> getReferringLinkableFroms​(GraphLink.LinkableTo elementRef)
      Returns all GraphLink.LinkableFrom LineElement.LinePoint that refer to a GraphLink.LinkableTo pathway element or anchor.
    • addElementRef

      protected void addElementRef​(GraphLink.LinkableTo elementRef, GraphLink.LinkableFrom linePoint)
      Register a link from a elementRef to a linePoint(s).
      Parameters:
      elementRef - the pathway element which can be linked to.
      linePoint - the linePoint with given elementRef.
    • removeElementRef

      protected void removeElementRef​(GraphLink.LinkableTo elementRef, GraphLink.LinkableFrom linePoint)
      Removes a linePoint linked to a elementRef.
      Parameters:
      elementRef - the pathway element which is linked to linePoint.
      linePoint - the linePoint with given elementRef.
    • getAliasRefs

      public java.util.Set<Group> getAliasRefs()
      Returns the set of Group aliasRef keys for this pathway model. A Group aliasRef can have or more DataNode aliases.
      Returns:
      the group aliasRef keys for this pathway model
    • getLinkedAliases

      public java.util.Set<DataNode> getLinkedAliases​(Group aliasRef)
      Returns the set of DataNode aliases for a Group aliasRef. When a DataNode has type="alias" it may be an alias for a Group pathway element. To get aliasRef for a dataNode use DataNode.getAliasRef().
      Parameters:
      aliasRef - the group which has datanode aliases.
      Returns:
      the datanode aliases for the group aliasRef.
    • hasAliasRef

      public boolean hasAliasRef​(Group aliasRef)
      Returns true if pathway model has Group aliasRef.
      Parameters:
      aliasRef - the group.
      Returns:
      true if pathway model has aliasRef.
    • hasLinkedAlias

      protected boolean hasLinkedAlias​(Group aliasRef, DataNode alias)
      Returns true if pathway model has DataNode alias and Group aliasRef.
      Parameters:
      aliasRef - the group.
      alias - the alias datanode.
      Returns:
      true if pathway model has alias and aliasRef.
    • linkAlias

      protected void linkAlias​(Group aliasRef, DataNode alias)
      Adds mapping of aliasRef to data node alias in the aliasRefToAliases hash map. NB: This method is not used directly.
      1. It is called from DataNode.setAliasRef(org.pathvisio.libgpml.model.Group).
      Parameters:
      aliasRef - the group for which a dataNode alias refers.
      alias - the datanode which has an aliasRef.
      Throws:
      java.lang.IllegalArgumentException - if elementRef or dataNode are null.
    • unlinkAlias

      protected void unlinkAlias​(Group aliasRef, DataNode alias)
      Removes the link between given aliasRef and alias, and removes mapping from aliasRefToAliases of this pathway model.

      NB: This method is not used directly.

      1. It is called from DataNode.unsetAliasRef().
      Parameters:
      aliasRef - the group for which a dataNode alias refers.
      alias - the datanode which has an aliasRef.
    • removeAliasRef

      protected void removeAliasRef​(Group aliasRef)
      Removes the mapping of given elementRef key from the elementRefToDataNode hash map.
      Parameters:
      aliasRef - the aliasRef key.
    • getDataNodes

      public java.util.List<DataNode> getDataNodes()
      Returns the list of data node pathway elements.
      Returns:
      dataNodes the list of data nodes.
    • addDataNode

      public void addDataNode​(DataNode dataNode)
      Adds the given dataNode to dataNodes list. Sets pathwayModel and elementId, and maps to elementIdToPathwayObject.
      Parameters:
      dataNode - the data node to be added.
    • removeDataNode

      public void removeDataNode​(DataNode dataNode)
      Removes the given dataNode from dataNodes list and elementIdToPathwayObject map.
      Parameters:
      dataNode - the data node to be removed.
    • getInteractions

      public java.util.List<Interaction> getInteractions()
      Returns the list of interaction pathway elements.
      Returns:
      interactions the list of interactions.
    • addInteraction

      public void addInteraction​(Interaction interaction)
      Adds the given interaction to interactions list. Sets pathwayModel and elementId, and maps to elementIdToPathwayObject.
      Parameters:
      interaction - the interaction to be added.
    • removeInteraction

      public void removeInteraction​(Interaction interaction)
      Removes the given interaction from interactions list and elementIdToPathwayObject map..
      Parameters:
      interaction - the interaction to be removed.
    • getGraphicalLines

      public java.util.List<GraphicalLine> getGraphicalLines()
      Returns the list of graphical line pathway elements.
      Returns:
      graphicalLines the list of graphicalLines.
    • addGraphicalLine

      public void addGraphicalLine​(GraphicalLine graphicalLine)
      Adds the given graphicalLine to graphicalLines list. Sets pathwayModel and elementId, and maps to elementIdToPathwayObject.
      Parameters:
      graphicalLine - the graphicalLine to be added.
    • removeGraphicalLine

      public void removeGraphicalLine​(GraphicalLine graphicalLine)
      Removes the given graphicalLine from graphicalLines list and elementIdToPathwayObject map..
      Parameters:
      graphicalLine - the graphicalLine to be removed.
    • getLabels

      public java.util.List<Label> getLabels()
      Returns the list of label pathway elements.
      Returns:
      labels the list of labels.
    • addLabel

      public void addLabel​(Label label)
      Adds the given label to labels list. Sets pathwayModel and elementId, and maps to elementIdToPathwayObject.
      Parameters:
      label - the label to be added.
    • removeLabel

      public void removeLabel​(Label label)
      Removes the given label from labels list and elementIdToPathwayObject map.
      Parameters:
      label - the label to be removed.
    • getShapes

      public java.util.List<Shape> getShapes()
      Returns the list of shape pathway elements.
      Returns:
      shapes the list of shapes.
    • addShape

      public void addShape​(Shape shape)
      Adds the given shape to shapes list.Sets pathwayModel and elementId, and maps to elementIdToPathwayObject.
      Parameters:
      shape - the shape to be added.
    • removeShape

      public void removeShape​(Shape shape)
      Removes the given shape from shapes list and elementIdToPathwayObject map.
      Parameters:
      shape - the shape to be removed.
    • getGroups

      public java.util.List<Group> getGroups()
      Returns the list of group pathway elements.
      Returns:
      groups the list of groups.
    • addGroup

      public void addGroup​(Group group)
      Adds the given group to groups list. Sets pathwayModel and elementId, and maps to elementIdToPathwayObject.
      Parameters:
      group - the group to be added.
    • removeGroup

      public void removeGroup​(Group group)
      Removes the given group from groups list and elementIdToPathwayObject map. Also removes group from aliasRefToAliases if applicable.
      Parameters:
      group - the group to be removed.
    • getAnnotations

      public java.util.List<Annotation> getAnnotations()
      Returns the list of annotations.
      Returns:
      annotations the list of annotations.
    • addAnnotation

      protected Annotation addAnnotation​(Annotation annotation)
      Adds given annotation to annotations list. If there is an annotation with equivalent properties in the pathway model, the given annotation is not added and the equivalent annotation is returned. Also sets pathwayModel and elementId, and maps to elementIdToPathwayObject.
      Parameters:
      annotation - the new annotation to be added.
      Returns:
      annotation the new annotation or annotationExisting the existing equivalent annotation.
    • hasEqualAnnotation

      private Annotation hasEqualAnnotation​(Annotation annotation)
      Checks if given annotation already exists for the pathway model.
      Parameters:
      annotation - the given annotation to be checked.
      Returns:
      annotationExisting the existing equivalent annotation, or null if no equivalent annotation exists for given citation.
    • removeAnnotation

      public void removeAnnotation​(Annotation annotation)
      Removes given annotation from annotations list and elementIdToPathwayObject map.
      Parameters:
      annotation - the annotation to be removed.
    • getCitations

      public java.util.List<Citation> getCitations()
      Returns the list of citations.
      Returns:
      citation the list of citations.
    • addCitation

      protected Citation addCitation​(Citation citation)
      Adds given citation to citations list. If there is an citation with equivalent properties in the pathway model, the given citation is not added and the equivalent citation is returned. Also sets pathwayModel and elementId, and maps to elementIdToPathwayObject.
      Parameters:
      citation - the new citation to be added.
      Returns:
      citation the new citation or citationExisting the existing equivalent citation.
    • hasEqualCitation

      private Citation hasEqualCitation​(Citation citation)
      Checks if given citation already exists for the pathway model.
      Parameters:
      citation - the given citation to be checked.
      Returns:
      citationExisting the existing equivalent citation, or null if no equivalent citation exists for given citation.
    • removeCitation

      public void removeCitation​(Citation citation)
      Removes given citation from citations list and elementIdToPathwayObject map.
      Parameters:
      citation - the citation to be removed.
    • getEvidences

      public java.util.List<Evidence> getEvidences()
      Returns the list of evidences.
      Returns:
      evidences the list of evidences.
    • addEvidence

      protected Evidence addEvidence​(Evidence evidence)
      Adds given evidence to evidences. If there is an evidence with equivalent properties in the pathway model, the given evidence is not added and the equivalent evidence is returned. Also sets pathwayModel and elementId, and maps to elementIdToPathwayObject.
      Parameters:
      evidence - the evidence to be added.
    • hasEqualEvidence

      private Evidence hasEqualEvidence​(Evidence evidence)
      Checks if given evidence already exists for the pathway model.
      Parameters:
      evidence - the given evidence to be checked.
      Returns:
      evidenceExisting the existing equivalent citation, or null if no equivalent citation exists for given citation.
    • removeEvidence

      public void removeEvidence​(Evidence evidence)
      Removes given evidence from evidences list and elementIdToPathwayObject map.
      Parameters:
      evidence - the evidence to be removed.
    • addPathwayObject

      protected void addPathwayObject​(PathwayObject o)
      Adds the given pathway object to pathway model. Sets pathwayModel for the given pathway object. Sets an unique elementId for given pathway object if not already set. Corresponding elementId and given pathway object are added to elementIdToPathwayObject map. Fires PathwayEvent.ADDED event after addition of the object
      Parameters:
      o - the pathway object to add.
    • removePathwayObject

      protected void removePathwayObject​(PathwayObject o)
      Removes the given pathway object from pathway model and elementIdToPathwayObject map. The pathway object is terminated in the process. Sets parent of object to null and removed elementId before removal of the object. Fires PathwayEvent.DELETED event after removal of the object
      Parameters:
      o - the pathway object to remove.
    • add

      public void add​(PathwayObject o)
      Adds a PathwayObject to this Pathway. Calls the appropriate add method based on PathwayObject class.
      Parameters:
      o - the pathway object to add
    • remove

      public void remove​(PathwayObject o)
      Removes a PathwayObject from this Pathway. Calls the appropriate remove method based on PathwayObject class.
      Parameters:
      o - the pathway object to remove
    • getDataNodeXrefs

      public java.util.List<org.bridgedb.Xref> getDataNodeXrefs()
      Returns the Xref of all DataNodes in this pathway as a List.
      Returns:
      result the list of xref of all datanodes or an empty arraylist if there are no datanodes in this pathway.
    • getStateXrefs

      public java.util.List<org.bridgedb.Xref> getStateXrefs()
      Returns the Xref of all States of all DataNodes in this pathway as a List.
      Returns:
      result the list of xref of all states or an empty arraylist if there are no interactions in this pathway.
    • getInteractionXrefs

      public java.util.List<org.bridgedb.Xref> getInteractionXrefs()
      Returns the Xref of all Interactions in this pathway as a List.
      Returns:
      result the list of xref of all interactions or an empty arraylist if there are no interactions in this pathway.
    • getGroupXrefs

      public java.util.List<org.bridgedb.Xref> getGroupXrefs()
      Returns the Xref of all Groups in this pathway as a List.
      Returns:
      result the list of xref of all groups or an empty arraylist if there are no interactions in this pathway.
    • clone

      public PathwayModel clone()
      Clones this pathway model.
      Overrides:
      clone in class java.lang.Object
      Returns:
      the clone of this pathway model.
    • getSourceFile

      public java.io.File getSourceFile()
      Returns the xml file containing the Gpml/mapp pathway currently displayed
      Returns:
      current xml file
    • setSourceFile

      public void setSourceFile​(java.io.File file)
    • writeToXml

      public void writeToXml​(java.io.File file, boolean validate) throws ConverterException
      Writes the JDOM document to the file specified
      Parameters:
      file - the file to which the JDOM document should be saved
      validate - if true, validate the dom structure before writing to file. If there is a validation error, or the xsd is not in the classpath, an exception will be thrown.
      Throws:
      ConverterException
    • readFromXml

      public void readFromXml​(java.io.Reader in, boolean validate) throws ConverterException
      Throws:
      ConverterException
    • readFromXml

      public void readFromXml​(java.io.InputStream in, boolean validate) throws ConverterException
      Throws:
      ConverterException
    • readFromXml

      public void readFromXml​(java.io.File file, boolean validate) throws ConverterException
      Throws:
      ConverterException
    • hasChanged

      public boolean hasChanged()
      The "changed" flag tracks if the Pathway has been changed since the file was opened or last saved. New pathways start changed.
    • clearChangedFlag

      public void clearChangedFlag()
      ClearChangedFlag should be called after when the current pathway is known to be the same as the one on disk. This happens when you just opened it, or when you just saved it.
    • markChanged

      private void markChanged()
      To be called after each edit operation
    • childModified

      void childModified​(PathwayObjectEvent e)
      Used by children of this Pathway to notify the parent of modifications. A coordinate change could trigger dependent objects such as states, groups and connectors to be updated as well.
      Parameters:
      e - the pathway object event.
    • checkMBoardSize

      protected void checkMBoardSize​(PathwayObject e)
      Checks whether the board size is still large enough for the given PathwayElement and increases the size if not
      Parameters:
      e - The element to check the board size for
    • addStatusFlagListener

      public void addStatusFlagListener​(PathwayModel.StatusFlagListener v)
      Registers a status flag listener
      Parameters:
      v - the given status flag listener to add.
    • removeStatusFlagListener

      public void removeStatusFlagListener​(PathwayModel.StatusFlagListener v)
      Removes a status flag listener
      Parameters:
      v - the given status flag listener to remove.
    • fireStatusFlagEvent

      public void fireStatusFlagEvent​(PathwayModel.StatusFlagEvent e)
      Fires status flag event. TODO make private if possible
      Parameters:
      e - the status flag event.
    • transferStatusFlagListeners

      public void transferStatusFlagListeners​(PathwayModel dest)
      Transfer statusflag listeners from one pathway to another. This is used needed when copies of the pathway are created / returned by UndoManager. The status flag listeners are only interested in status flag events of the active copy.
    • addListener

      public void addListener​(PathwayModelListener v)
      Adds listener to this pathway model.
      Parameters:
      v - the pathway model listener to add.
    • removeListener

      public void removeListener​(PathwayModelListener v)
      Removes listener from this pathway model.
      Parameters:
      v - the pathway model listener to removed.
    • fireObjectModifiedEvent

      public void fireObjectModifiedEvent​(PathwayModelEvent e)
      Firing the ObjectModifiedEvent has the side effect of marking the Pathway as changed.
      Parameters:
      e - the pathway model event.
    • summary

      public java.lang.String summary()
      Prints a summary of this pathway model.
      Returns:
      the string summary of this pathway model.