Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*******************************************************************************
* PathVisio, a tool for data visualization and analysis using biological pathways
* Copyright 2006-2022 BiGCaT Bioinformatics, WikiPathways
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
******************************************************************************/
package org.pathvisio.libgpml.model;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import org.bridgedb.Xref;
import org.pathvisio.libgpml.model.Referenceable.Annotatable;
import org.pathvisio.libgpml.model.Referenceable.Citable;
import org.pathvisio.libgpml.model.Referenceable.Evidenceable;
import org.pathvisio.libgpml.model.type.AnnotationType;
import org.pathvisio.libgpml.prop.StaticProperty;
import org.pathvisio.libgpml.util.Utils;
import org.pathvisio.libgpml.util.XrefUtils;
/**
* Abstract class of pathway elements which are part of a pathway, have an
* elementId, have Comment,
*
* Children: DataNode, State, Interaction, GraphicalLine, Label, Shape, Group.
*
* @author unknown, AP20070508, finterly
*/
public abstract class PathwayElement extends PathwayObject implements Cloneable, Annotatable, Citable, Evidenceable {
private List comments;
/**
* Map for storing dynamic properties. Dynamic properties can have any String as
* key and value of type String. If a value is set to null the key should be
* removed.
*/
private Map dynamicProperties;
private List annotationRefs;
private List citationRefs;
private List evidenceRefs;
// ================================================================================
// Constructors
// ================================================================================
/**
* Instantiates a pathway element with meta data information.
*/
public PathwayElement() {
super();
this.comments = new ArrayList(); // 0 to unbounded
this.dynamicProperties = new TreeMap(); // 0 to unbounded
this.annotationRefs = new ArrayList(); // 0 to unbounded
this.citationRefs = new ArrayList(); // 0 to unbounded
this.evidenceRefs = new ArrayList(); // 0 to unbounded
}
// ================================================================================
// Comment and DynamicProperty Methods
// ================================================================================
/*
* Returns the list of comments.
*
* @return comments the list of comments.
*/
public List getComments() {
return comments;
}
/**
* Adds given comment to comments list.
*
* @param comment the comment to be added.
*/
public void addComment(Comment comment) {
comments.add(comment);
fireObjectModifiedEvent(PathwayObjectEvent.createSinglePropertyEvent(this, StaticProperty.COMMENT));
}
/**
* Creates a comment with given properties and adds to comments list. Calls
* {@link #addComment(Comment comment)}.
*
* @param commentText the text of the comment, between Comment tags in GPML.
* @param source the source of this comment.
* @return the created comment.
*/
public Comment addComment(String commentText, String source) {
Comment comment = new Comment(commentText, source);
addComment(comment);
return comment;
}
/**
* Removes given comment from comments list.
*
* @param comment the comment to be removed.
*/
public void removeComment(Comment comment) {
comments.remove(comment);
fireObjectModifiedEvent(PathwayObjectEvent.createSinglePropertyEvent(this, StaticProperty.COMMENT));
}
/**
* Sets comments to the given comments list.
*
* @param value the given comment list.
*/
public void setComments(List value) {
if (comments != value) {
comments = value;
fireObjectModifiedEvent(PathwayObjectEvent.createSinglePropertyEvent(this, StaticProperty.COMMENT));
}
}
/**
* Finds the first comment with a specific source.
*
* @param source the source of the comment to be found.
* @return the comment content with a given source.
*/
public String findComment(String source) {
for (Comment comment : comments) {
if (source.equals(comment.getSource())) {
return comment.getCommentText();
}
}
return null;
}
/**
* Returns the map of dynamic properties.
*
* @return dynamicProperties the map of dynamic properties.
*/
public Map getDynamicProperties() {
return dynamicProperties;
}
/**
* Returns a set of all dynamic property keys.
*
* @return a set of all dynamic property keys.
*/
public Set getDynamicPropertyKeys() {
return dynamicProperties.keySet();
}
/**
* Returns a dynamic property string value.
*
* @param key the key of a key value pair.
* @return the value or dynamic property.
*/
public String getDynamicProperty(String key) {
return dynamicProperties.get(key);
}
/**
* Sets a dynamic property. Setting to null means removing this dynamic property
* altogether.
*
* @param key the key of a key value pair.
* @param value the value of a key value pair.
*/
public void setDynamicProperty(String key, String value) {
if (value == null)
dynamicProperties.remove(key);
else
dynamicProperties.put(key, value);
fireObjectModifiedEvent(PathwayObjectEvent.createSinglePropertyEvent(this, key));
}
// ================================================================================
// AnnotationRef, CitationRef and EvidenceRef Methods
// ================================================================================
/**
* Returns the list of annotation references.
*
* @return annotationRefs the list of annotation references, an empty list if no
* properties are defined.
*/
@Override
public List getAnnotationRefs() {
return annotationRefs;
}
/**
* Checks whether annotationRefs has the given annotationRef.
*
* @param annotationRef the annotationRef to look for.
* @return true if has annotationRef, false otherwise.
*/
@Override
public boolean hasAnnotationRef(AnnotationRef annotationRef) {
return annotationRefs.contains(annotationRef);
}
/**
* Creates and adds an annotationRef to annotationRefs list. Sets annotable for
* the given annotationRef.
*
* @param annotation the annotation for annotationRef.
* @return the annotationRef of added annotation.
*/
@Override
public AnnotationRef addAnnotation(Annotation annotation) {
// add annotation to pathway model if applicable
if (pathwayModel != null && !pathwayModel.getAnnotations().contains(annotation)) {
annotation = pathwayModel.addAnnotation(annotation);
}
AnnotationRef annotationRef = new AnnotationRef(annotation);
// adds annotationRef
if (annotationRef != null && !hasAnnotationRef(annotationRef)) {
annotationRef.setAnnotatableTo(this);
assert (annotationRef.getAnnotatable() == this);
annotationRefs.add(annotationRef);
fireObjectModifiedEvent(PathwayObjectEvent.createSinglePropertyEvent(this, StaticProperty.ANNOTATIONREF));
}
return annotationRef;
}
/**
* Creates a annotation with given properties, and adds annotation to pathway
* model. Creates a annotationRef for annotation, and adds to annotationRefs
* list for this annotatable. Calls
* {@link #addAnnotation(Annotation annotation)}.
*
* @param value the name, term, or text of the annotation.
* @param type the type of the annotation, e.g. ontology.
* @param xref the annotation xref.
* @param urlLink the url link of the annotation.
* @return the annotationRef of added annotation.
*/
@Override
public AnnotationRef addAnnotation(String value, AnnotationType type, Xref xref, String urlLink) {
Annotation annotation = new Annotation(value, type, xref, urlLink);
// adds annotation to pathway model, creates and adds annotationRef
return addAnnotation(annotation);
}
/**
* Creates a annotation with given properties, and adds annotation to pathway
* model. Creates a annotationRef for annotation, and adds to annotationRefs
* list for this annotatable. Sets elementId for annotation. This method is used
* when reading gpml. Calls {@link #addAnnotation(Annotation annotation)}.
*
* @param elementId the elementId to set.
* @param value the name, term, or text of the annotation.
* @param type the type of the annotation, e.g. ontology.
* @param xref the annotation xref.
* @param urlLink the url link of the annotation.
* @return the annotationRef of added annotation.
*/
@Override
public AnnotationRef addAnnotation(String elementId, String value, AnnotationType type, Xref xref, String urlLink) {
Annotation annotation = new Annotation(value, type, xref, urlLink);
annotation.setElementId(elementId);
// adds annotation to pathway model, creates and adds annotationRef
return addAnnotation(annotation);
}
/**
* Removes given annotationRef from annotationRefs list. The annotationRef
* ceases to exist and is terminated.
*
* @param annotationRef the annotationRef to be removed.
*/
@Override
public void removeAnnotationRef(AnnotationRef annotationRef) {
if (annotationRef != null) {
annotationRefs.remove(annotationRef);
annotationRef.terminate();
fireObjectModifiedEvent(PathwayObjectEvent.createSinglePropertyEvent(this, StaticProperty.ANNOTATIONREF));
}
}
/**
* Removes all annotationRefs from annotationRefs list.
*/
@Override
public void removeAnnotationRefs() {
for (int i = annotationRefs.size() - 1; i >= 0; i--) {
removeAnnotationRef(annotationRefs.get(i));
}
}
/**
* Returns the list of citation references.
*
* @return citationRefs the list of citations referenced, an empty list if no
* properties are defined.
*/
@Override
public List getCitationRefs() {
return citationRefs;
}
/**
* Checks whether citationRefs has the given citationRef.
*
* @param citationRef the citationRef to look for.
* @return true if has citationRef, false otherwise.
*/
@Override
public boolean hasCitationRef(CitationRef citationRef) {
return citationRefs.contains(citationRef);
}
/**
* Creates and adds an citationRef to citationRefs list. Sets citable for the
* given citationRef.
*
* @param citation the citation for citationRef.
* @return the citationRef of added citation.
*/
@Override
public CitationRef addCitation(Citation citation) {
// add citation to pathway model if applicable
if (pathwayModel != null && !pathwayModel.getCitations().contains(citation)) {
citation = pathwayModel.addCitation(citation);
}
CitationRef citationRef = new CitationRef(citation);
// adds citationRef
if (citationRef != null && !hasCitationRef(citationRef)) {
citationRef.setCitableTo(this);
assert (citationRef.getCitable() == this);
citationRefs.add(citationRef);
fireObjectModifiedEvent(PathwayObjectEvent.createSinglePropertyEvent(this, StaticProperty.CITATIONREF));
}
return citationRef;
}
/**
* Creates a citation with given xref and urlLink, and adds citation to pathway
* model. Creates a citationRef for citation, and adds to citationRefs list for
* this citable.Calls {@link #addCitation(Citation citation)}.
*
* @param xref the citation xref.
* @param urlLink the url link and description (optional) for a web address.
* @return the citationRef of added citation.
*/
@Override
public CitationRef addCitation(Xref xref, String urlLink) {
Citation citation = new Citation(xref, urlLink);
// adds citation to pathway model, creates and adds citationRef
return addCitation(citation);
}
/**
* Creates a citation with given xref and urlLink, and adds citation to pathway
* model. Creates a citationRef for citation, and adds to citationRefs list for
* this citable. Sets elementId for citation. This method is used when reading
* gpml. Calls {@link #addCitation(Citation citation)}.
*
* @param elementId the elementId to set.
* @param xref the citation xref.
* @param urlLink the url link and description (optional) for a web address.
* @return the citationRef of added citation.
*/
@Override
public CitationRef addCitation(String elementId, Xref xref, String urlLink) {
Citation citation = new Citation(xref, urlLink);
// set elementId
citation.setElementId(elementId);
// adds citation to pathway model, creates and adds citationRef
return addCitation(citation);
}
/**
* Removes given citationRef from citationRefs list. The citationRef ceases to
* exist and is terminated.
*
* @param citationRef the citationRef to be removed.
*/
@Override
public void removeCitationRef(CitationRef citationRef) {
if (citationRef != null && hasCitationRef(citationRef)) {
citationRefs.remove(citationRef);
citationRef.terminate();
fireObjectModifiedEvent(PathwayObjectEvent.createSinglePropertyEvent(this, StaticProperty.CITATIONREF));
}
}
/**
* Removes all citationRef from citationRefs list.
*/
@Override
public void removeCitationRefs() {
for (int i = citationRefs.size() - 1; i >= 0; i--) {
removeCitationRef(citationRefs.get(i));
}
}
/**
* Returns the list of evidence references.
*
* @return evidenceRefs the list of evidences referenced, an empty list if no
* properties are defined.
*/
@Override
public List getEvidenceRefs() {
return evidenceRefs;
}
/**
* Checks whether evidenceRefs has the given evidenceRef.
*
* @param evidenceRef the evidenceRef to look for.
* @return true if has evidenceRef, false otherwise.
*/
@Override
public boolean hasEvidenceRef(EvidenceRef evidenceRef) {
return evidenceRefs.contains(evidenceRef);
}
/**
* Creates and adds an evidenceRef to evidenceRefs list. Sets evidenceable for
* the given evidenceRef.
*
* @param evidence the evidenceRef for evidenceRef.
* @return the evidenceRef of added evidence.
*/
@Override
public EvidenceRef addEvidence(Evidence evidence) {
// add evidence to pathway model if applicable
if (pathwayModel != null && !pathwayModel.getEvidences().contains(evidence)) {
evidence = pathwayModel.addEvidence(evidence);
}
EvidenceRef evidenceRef = new EvidenceRef(evidence);
// adds evidenceRef
if (evidenceRef != null && !hasEvidenceRef(evidenceRef)) {
evidenceRef.setEvidenceableTo(this);
assert (evidenceRef.getEvidenceable() == this);
evidenceRefs.add(evidenceRef);
fireObjectModifiedEvent(PathwayObjectEvent.createSinglePropertyEvent(this, StaticProperty.EVIDENCEREF));
}
return evidenceRef;
}
/**
* Creates an evidence with given properties, and adds evidence to pathway
* model. Creates a evidenceRef for evidence, and adds to evidenceRefs list for
* this evidenceable. Calls {@link #addEvidence(Evidence evidence)}.
*
* @param value the name, term, or text of the evidence.
* @param xref the evidence xref.
* @param urlLink the url link and description (optional) for a web address.
* @return the evidenceRef of added evidence.
*/
@Override
public EvidenceRef addEvidence(String value, Xref xref, String urlLink) {
Evidence evidence = new Evidence(value, xref, urlLink);
// adds evidence to pathway model, creates and adds evidenceRef
return addEvidence(evidence);
}
/**
* Creates an evidence with given properties, and adds evidence to pathway
* model. Creates a evidenceRef for evidence, and adds to evidenceRefs list for
* this evidenceable. Sets elementId for evidence. This method is used when
* reading gpml. Calls {@link #addEvidence(Evidence evidence)}.
*
* @param elementId the elementId to set.
* @param value the name, term, or text of the evidence.
* @param xref the evidence xref.
* @param urlLink the url link and description (optional) for a web address.
* @return the evidenceRef of added evidence.
*/
@Override
public EvidenceRef addEvidence(String elementId, String value, Xref xref, String urlLink) {
Evidence evidence = new Evidence(value, xref, urlLink);
// set elementId
evidence.setElementId(elementId);
// adds evidence to pathway model, creates and adds evidenceRef
return addEvidence(evidence);
}
/**
* Removes given evidenceRef from evidenceRefs list. The evidenceRef ceases to
* exist and is terminated.
*
* @param evidenceRef the evidenceRef to be removed.
*/
@Override
public void removeEvidenceRef(EvidenceRef evidenceRef) {
if (evidenceRef != null && hasEvidenceRef(evidenceRef)) {
evidenceRefs.remove(evidenceRef);
evidenceRef.terminate();
fireObjectModifiedEvent(PathwayObjectEvent.createSinglePropertyEvent(this, StaticProperty.EVIDENCEREF));
}
}
/**
* Removes all evidenceRefs from evidenceRefs list.
*/
@Override
public void removeEvidenceRefs() {
for (int i = evidenceRefs.size() - 1; i >= 0; i--) {
removeEvidenceRef(evidenceRefs.get(i));
}
}
/**
* Terminates this pathway element. The pathway model, if any, is unset from
* this pathway element. Links to all annotationRefs, citationRefs, and
* evidenceRefs are removed from this data node.
*/
@Override
protected void terminate() {
removeAnnotationRefs();
removeCitationRefs();
removeEvidenceRefs();
super.terminate();
}
// ================================================================================
// Copy Methods
// ================================================================================
/**
* Copies values from the given source pathway element.
*
*
* NB:
*
*
Doesn't change parent, only fields
*
Used by UndoAction.
*
AnnotationRefs, citationRefs, and evidenceRefs are copied later using
* {@link copyReferencesFrom}.
*
*
* @param src the source pathway element.
*/
public void copyValuesFrom(PathwayElement src) {
dynamicProperties = new TreeMap(src.dynamicProperties); // create copy
comments = new ArrayList();
for (Comment c : src.comments) {
try {
comments.add((Comment) c.clone());
} catch (CloneNotSupportedException e) {
assert (false);
/* not going to happen */
}
}
fireObjectModifiedEvent(PathwayObjectEvent.createAllPropertiesEvent(this));
}
/**
* Copies this pathway element.
*
* @return the copyElement for the new pathway element and this source pathway
* element.
*/
public abstract CopyElement copy();
/**
* Copies references from the given source pathway element.
*
* NB:
*
*
To be called after new pathway element is added to a pathway model.
*
The srcElement may be the immediate copy element source of the new
* pathway element, or an older source.
*
*
* @param srcElement the source element to copy references from.
*/
public void copyReferencesFrom(PathwayElement srcElement) {
if (srcElement != null && this.getObjectType() == srcElement.getObjectType()) {
copyAnnotationRefs(srcElement.getAnnotationRefs());
copyCitationRefs(srcElement.getCitationRefs());
copyEvidenceRefs(srcElement.getEvidenceRefs());
}
}
/**
* Copies citationsRefs and nested annotationRefs if applicable.
*
* @param citationRefs the citationsRefs list.
*/
private void copyCitationRefs(List citationRefs) {
for (CitationRef citationRef : citationRefs) {
this.addCitation(citationRef.getCitation().copyRef());
copyAnnotationRefs(citationRef.getAnnotationRefs());
}
}
/**
* Copies annotationRefs and nested citationRefs and evidenceRefs if applicable.
*
* @param annotationRefs the annotationRefs list.
*/
private void copyAnnotationRefs(List annotationRefs) {
for (AnnotationRef annotationRef : annotationRefs) {
this.addAnnotation(annotationRef.getAnnotation().copyRef());
copyCitationRefs(annotationRef.getCitationRefs());
copyEvidenceRefs(annotationRef.getEvidenceRefs());
}
}
/**
* Copies evidenceRefs.
*
* @param evidenceRefs the evidenceRefs list.
*/
private void copyEvidenceRefs(List evidenceRefs) {
for (EvidenceRef evidenceRef : evidenceRefs) {
this.addEvidence(evidenceRef.getEvidence().copyRef());
}
}
// ================================================================================
// Property Methods
// ================================================================================
/**
* Returns keys of available static properties and dynamic properties as an
* object list
*/
@Override
public Set