org.biopax.paxtools.controller
Class ModelUtils

java.lang.Object
  extended by org.biopax.paxtools.controller.ModelUtils

public class ModelUtils
extends java.lang.Object

An advanced BioPAX utility class that implements several useful algorithms to extract root or child BioPAX elements, remove dangling, replace elements or identifiers, etc.

Author:
rodche

Nested Class Summary
static class ModelUtils.RelationshipType
          Controlled vocabulary terms for the RelationshipType CV to be added with auto-generated/inferred comments and/or relationship xrefs.
 
Field Summary
static java.lang.String BIOPAX_URI_PREFIX
           
static java.lang.String COMMENT_FOR_GENERATED
          A comment (at least - prefix) to add to all generated objects
 
Constructor Summary
ModelUtils(Model model)
          Constructor.
 
Method Summary
 java.util.Map<java.lang.Class<? extends BioPAXElement>,java.lang.Integer> generateClassMetrics()
           
 void generateEntityOrganismXrefs()
          Auto-generates organism relationship xrefs - for BioPAX entities that do not have such property (but their children do), such as of Interaction, Protein, Complex, DNA, Protein, etc.
<T extends Process>
void
generateEntityProcessXrefs(java.lang.Class<T> processClass)
          Creates "process" (membership) relationship xrefs for each child Entity if possible.
static java.lang.String generateURIForXref(java.lang.String db, java.lang.String id, java.lang.Class<? extends Xref> type)
          Builds a "normalized" RelationshipXref URI.
 Model getAllChildren(BioPAXElement bpe, Filter<PropertyEditor>... filters)
          Gets all the child BioPAX elements of a given BioPAX element (using the "tuned" Fetcher) and adds them to a new model.
 java.util.Set<BioPAXElement> getAllChildrenAllowClones(BioPAXElement bpe, Filter<PropertyEditor>... filters)
          Collects all child BioPAX elements of a given BioPAX element (using the "tuned" Fetcher), although some of them might have the same ID (are "clones" - for a purpose of due to a mistake)
 java.util.Set<java.lang.String> getByXref(java.util.Set<? extends Xref> xrefs, java.lang.Class<? extends XReferrable> clazz)
          This is a special (not always applicable) utility method.
 Model getDirectChildren(BioPAXElement bpe)
          Gets direct children of a given BioPAX element and adds them to a new model.
 java.util.Set<BioPAXElement> getDirectChildrenAllowClones(BioPAXElement bpe)
          Collects direct children of a given BioPAX element, although some of them might have the same ID (are "clones" - for a purpose of due to a mistake)
 Model getModel()
           
<T extends BioPAXElement>
T
getObject(java.lang.String urn, java.lang.Class<T> clazz)
           
<T extends BioPAXElement>
java.util.Set<T>
getRootElements(java.lang.Class<T> filterClass)
          Finds a subset of "root" BioPAX objects of specific class (incl.
 void inferPropertyFromParent(java.lang.String property, java.lang.Class<? extends BioPAXElement>... forClasses)
          For the current (internal) model, this method iteratively copies given property values from parent BioPAX elements to children.
static java.lang.String relationshipTypeVocabularyUri(java.lang.String relationshipType)
          Gets a URI for a special (internal, not standard, but useful) RelationshipTypeVocabulary, which can be used for such objects auto-generated by this class methods (also by any BioPAX reasoner/tool)
 void removeDependentsIfDangling(BioPAXElement parent)
          Deletes (recursively from the current model) only those child elements that would become "dangling" (not a property value of anything) if the parent element were (or already was) removed from the model.
<T extends BioPAXElement>
void
removeObjectsIfDangling(java.lang.Class<T> clazz)
          Iteratively removes dangling elements of given type, e.g., utility class, from current model.
 void replace(BioPAXElement existing, BioPAXElement replacement)
          Replaces an existing BioPAX element with another one, of the same or possibly equivalent type (or null), recursively updates all the references to it (parents' object properties).
<E extends BioPAXElement>
void
replace(java.util.Map<E,E> subs)
          Replaces existing BioPAX elements with ones from the map, and recursively updates all the object references (parents' object properties) in a single pass.
 void replaceID(java.lang.String oldId, java.lang.String newId)
          Replaces the RDFId of the BioPAX element and in the current model.
static java.lang.String uriPrefixForGeneratedXref(java.lang.Class<? extends Xref> clazz)
          This is to consistently create URI prefixes for auto-generated/inferred Xref objects (except for PublicationXref, where creating of something like, e.g., 'urn:miriam:pubmed:' is recommended).
 Model writeRead()
          Cuts the BioPAX model off other models and BioPAX objects by essentially performing write/read to/from OWL.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COMMENT_FOR_GENERATED

public static final java.lang.String COMMENT_FOR_GENERATED
A comment (at least - prefix) to add to all generated objects

See Also:
Constant Field Values

BIOPAX_URI_PREFIX

public static final java.lang.String BIOPAX_URI_PREFIX
See Also:
Constant Field Values
Constructor Detail

ModelUtils

public ModelUtils(Model model)
Constructor.

Parameters:
model -
Method Detail

uriPrefixForGeneratedXref

public static java.lang.String uriPrefixForGeneratedXref(java.lang.Class<? extends Xref> clazz)
This is to consistently create URI prefixes for auto-generated/inferred Xref objects (except for PublicationXref, where creating of something like, e.g., 'urn:miriam:pubmed:' is recommended).

Parameters:
clazz -
Returns:

relationshipTypeVocabularyUri

public static java.lang.String relationshipTypeVocabularyUri(java.lang.String relationshipType)
Gets a URI for a special (internal, not standard, but useful) RelationshipTypeVocabulary, which can be used for such objects auto-generated by this class methods (also by any BioPAX reasoner/tool)

Parameters:
relationshipType -
Returns:

replace

public void replace(BioPAXElement existing,
                    BioPAXElement replacement)
Replaces an existing BioPAX element with another one, of the same or possibly equivalent type (or null), recursively updates all the references to it (parents' object properties). If you're actually replacing multiple objects inthe same model, for better performance, consider using replace(Map) method instead.

Parameters:
existing -
replacement -

replace

public <E extends BioPAXElement> void replace(java.util.Map<E,E> subs)
Replaces existing BioPAX elements with ones from the map, and recursively updates all the object references (parents' object properties) in a single pass. It does not remove old or adds new elements to the model; so, one may want to do it or - consider using Model.repair() and removeObjectsIfDangling(Class) methods after all.

Parameters:
subs -

removeDependentsIfDangling

public void removeDependentsIfDangling(BioPAXElement parent)
Deletes (recursively from the current model) only those child elements that would become "dangling" (not a property value of anything) if the parent element were (or already was) removed from the model.

Parameters:
parent -

replaceID

public void replaceID(java.lang.String oldId,
                      java.lang.String newId)
Replaces the RDFId of the BioPAX element and in the current model. WARN: this hacker's method is to use with great care, because, if more than one BioPAX models share the (oldId) element, all these, except for current one, will be broken (contain the updated element under its oldId) One can call Model.repair() to fix. The method replace(BioPAXElement, BioPAXElement) is much safer but less efficient in special cases, such as when one just needs to create/import one model, quickly update several or all IDs, and save it to a file.

Parameters:
oldId -
newId -

getModel

public Model getModel()

getRootElements

public <T extends BioPAXElement> java.util.Set<T> getRootElements(java.lang.Class<T> filterClass)
Finds a subset of "root" BioPAX objects of specific class (incl. sub-classes) Note: however, such "root" elements may or may not be, a property of other elements, not included in the model.

Parameters:
filterClass -
Returns:

removeObjectsIfDangling

public <T extends BioPAXElement> void removeObjectsIfDangling(java.lang.Class<T> clazz)
Iteratively removes dangling elements of given type, e.g., utility class, from current model.


inferPropertyFromParent

public void inferPropertyFromParent(java.lang.String property,
                                    java.lang.Class<? extends BioPAXElement>... forClasses)
For the current (internal) model, this method iteratively copies given property values from parent BioPAX elements to children. If the property is multiple cardinality property, it will add new values, otherwise - it will set it only if was empty; in both cases it won't delete/override existing values!

Parameters:
property - property name
forClasses - (optional) infer/set the property for these types only
See Also:
PropertyReasoner

writeRead

public Model writeRead()
Cuts the BioPAX model off other models and BioPAX objects by essentially performing write/read to/from OWL. The resulting model contains new objects with same IDs and have object properties "fixed", i.e., dangling values become null/empty, and inverse properties (e.g. xrefOf) re-calculated. The original model is unchanged.

Returns:
copy of the model
Throws:
java.io.IOException

getAllChildren

public Model getAllChildren(BioPAXElement bpe,
                            Filter<PropertyEditor>... filters)
Gets all the child BioPAX elements of a given BioPAX element (using the "tuned" Fetcher) and adds them to a new model.

Parameters:
bpe -
filters - property filters (e.g., for Fetcher to skip some properties). Default is to skip 'nextStep'.
Returns:

getDirectChildren

public Model getDirectChildren(BioPAXElement bpe)
Gets direct children of a given BioPAX element and adds them to a new model.

Parameters:
bpe -
Returns:

getAllChildrenAllowClones

public java.util.Set<BioPAXElement> getAllChildrenAllowClones(BioPAXElement bpe,
                                                              Filter<PropertyEditor>... filters)
Collects all child BioPAX elements of a given BioPAX element (using the "tuned" Fetcher), although some of them might have the same ID (are "clones" - for a purpose of due to a mistake)

Parameters:
bpe -
filters - property filters (e.g., for Fetcher to skip some properties). Default is to skip 'nextStep'.
Returns:

getDirectChildrenAllowClones

public java.util.Set<BioPAXElement> getDirectChildrenAllowClones(BioPAXElement bpe)
Collects direct children of a given BioPAX element, although some of them might have the same ID (are "clones" - for a purpose of due to a mistake)

Parameters:
bpe -
Returns:

generateEntityProcessXrefs

public <T extends Process> void generateEntityProcessXrefs(java.lang.Class<T> processClass)
Creates "process" (membership) relationship xrefs for each child Entity if possible. This is Level3 specific. For each child Entity of every process (of the type given by the second argument), creates a relationship xref with the following properties: - db = provider (a name given by the second parameter) - id = the rdfId (URI) of the parent process - relationshipType = controlled vocabulary: "process" (MI:0359), urn:miriam:obo.mi:MI%3A0359 - comment = "Auto-generated by Paxtools" (also added to the CV and its unification xref)

Type Parameters:
T -
Parameters:
processClass - to relate entities with an interaction/pathway of this type

generateEntityOrganismXrefs

public void generateEntityOrganismXrefs()
Auto-generates organism relationship xrefs - for BioPAX entities that do not have such property (but their children do), such as of Interaction, Protein, Complex, DNA, Protein, etc. classes. Infers organisms in two steps: 1. add organisms as relationship xrefs of SimplePhysicalEntity objects (from EntityReference objects), except for smallmolecules. 2. infer organism information recursively via all children, but only when children are also Entity objects (not utility classes) (equivalently, this can be achieved by collecting all the children first, though not visiting properties who's range is a sub-class of UtilityClass)


generateURIForXref

public static java.lang.String generateURIForXref(java.lang.String db,
                                                  java.lang.String id,
                                                  java.lang.Class<? extends Xref> type)
Builds a "normalized" RelationshipXref URI.

Parameters:
db -
id -
type - TODO
Returns:
new ID (URI); not null (unless it's a bug :))

generateClassMetrics

public java.util.Map<java.lang.Class<? extends BioPAXElement>,java.lang.Integer> generateClassMetrics()

getObject

public <T extends BioPAXElement> T getObject(java.lang.String urn,
                                             java.lang.Class<T> clazz)

getByXref

public java.util.Set<java.lang.String> getByXref(java.util.Set<? extends Xref> xrefs,
                                                 java.lang.Class<? extends XReferrable> clazz)
This is a special (not always applicable) utility method. It finds the list of IDs of objects in the model that have a NORMALIZED xref equivalent (same db,id,type) to at least one of the specified xrefs.

Parameters:
xrefs -
clazz -
Returns:


Copyright © 2011 BioPAX. All Rights Reserved.