code
stringlengths 67
466k
| docstring
stringlengths 1
13.2k
|
---|---|
protected void invokeMethod(Method method, D bean, R value)
{
assert bean != null;
try
{
method.invoke(domain.cast(bean), value);
}
catch (ClassCastException e)
{
String message = "Failed to set property: " + property;
if (!domain.isAssignableFrom(bean.getClass()))
{
message += " Invalid domain bean: " + domain.getSimpleName() + " is not assignable from " +
bean.getClass();
}
if (!range.isAssignableFrom(value.getClass()))
{
message += " Invalid range value: " + range + " is not assignable from " + value.getClass();
}
throw new IllegalBioPAXArgumentException(message, e);
}
catch (Exception e) //java.lang.reflect.InvocationTargetException
{
String valInfo = (value == null) ? null : value.getClass().getSimpleName() + ", " + value;
String message = "Failed to set " + property + " with " + method.getName() + " on "
+ domain.getSimpleName() + " (" + bean.getClass().getSimpleName() + ", " + bean + ")"
+ " with range: " + range.getSimpleName() + " (" + valInfo + ")";
throw new IllegalBioPAXArgumentException(message, e);
}
} | Calls the <em>method</em> onto <em>bean</em> with the <em>value</em> as its parameter. In this
context <em>method</em> can be one of these three: set, add, or remove.
@param method method that is going to be called
@param bean bean onto which the method is going to be applied
@param value the value which is going to be used by method |
protected void checkRestrictions(R value, D bean)
{
Integer max = this.maxCardinalities.get(value.getClass());
if (max != null)
{
if (max == 0)
{
throw new IllegalBioPAXArgumentException("Cardinality 0 restriction violated");
} else
{
assert multipleCardinality;
Set values = this.getValueFromBean(bean);
if (values.size() >= max)
{
throw new IllegalBioPAXArgumentException("Cardinality " + max + " restriction violated");
}
}
}
} | Checks if the <em>bean</em> and the <em>value</em> are consistent with the cardinality rules of
the model. This method is important for validations.
@param value Value that is related to the object
@param bean Object that is related to the value |
public static String getDataTypeURI(String datatypeKey)
{
Datatype datatype = getDatatype(datatypeKey);
return getOfficialDataTypeURI(datatype);
} | Retrieves the unique (official) URI of a data type (example: "urn:miriam:uniprot").
@param datatypeKey - ID, name, synonym, or (incl. deprecated) URI (URN or URL) of a data type (examples: "UniProt")
@return unique URI of the data type
@throws IllegalArgumentException when datatype not found |
public static String[] getDataTypeURIs(String datatypeKey)
{
Set<String> alluris = new HashSet<String>();
Datatype datatype = getDatatype(datatypeKey);
for(Uris uris : datatype.getUris()) {
for(Uri uri : uris.getUri()) {
alluris.add(uri.getValue());
}
}
return alluris.toArray(ARRAY_OF_STRINGS);
} | Retrieves all the URIs of a data type, including all the deprecated ones
(examples: "urn:miriam:uniprot", "http://www.uniprot.org/", "urn:lsid:uniprot.org:uniprot", ...).
@param datatypeKey name (or synonym), ID, or URI (URN or URL) of the data type (examples: "ChEBI", "UniProt")
@return all the URIs of a data type (including the deprecated ones)
@throws IllegalArgumentException when datatype not found |
public static String getResourceLocation(String resourceId)
{
Resource resource = getResource(resourceId);
return resource.getDataLocation();
} | Retrieves the location (or country) of a resource (example: "United Kingdom").
@param resourceId identifier of a resource (example: "MIR:00100009")
@return the location (the country) where the resource is managed |
public static String getResourceInstitution(String resourceId)
{
Resource resource = getResource(resourceId);
return resource.getDataInstitution();
} | Retrieves the institution which manages a resource (example: "European Bioinformatics Institute").
@param resourceId identifier of a resource (example: "MIR:00100009")
@return the institution managing the resource |
public static String getURI(String name, String id)
{
Datatype datatype = getDatatype(name);
String db = datatype.getName();
if(checkRegExp(id, db)) {
try {
return getOfficialDataTypeURI(datatype) + ":" + URLEncoder.encode(id, "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("UTF-8 encoding error of id=" + id, e);
}
} else
throw new IllegalArgumentException(
"ID pattern mismatch. db=" + db + ", id=" + id
+ ", regexp: " + datatype.getPattern());
} | Retrieves the unique MIRIAM URI of a specific entity (example: "urn:miriam:obo.go:GO%3A0045202").
@param name - name, URI/URL, or ID of a data type (examples: "ChEBI", "MIR:00000005")
@param id identifier of an entity within the data type (examples: "GO:0045202", "P62158")
@return unique standard MIRIAM URI of a given entity
@throws IllegalArgumentException when datatype not found |
public static String getDataTypeDef(String datatypeKey)
{
Datatype datatype = getDatatype(datatypeKey);
return datatype.getDefinition();
} | Retrieves the definition of a data type.
@param datatypeKey - ID, name or URI (URN or URL) of a data type
@return definition of the data type
@throws IllegalArgumentException when datatype not found |
public static String[] getLocations(String datatypeKey, String entityId)
{
Set<String> locations = new HashSet<String>();
Datatype datatype = getDatatype(datatypeKey);
for (Resource resource : getResources(datatype)) {
String link = resource.getDataEntry();
try {
link = link.replaceFirst("\\$id", URLEncoder.encode(entityId, "UTF-8"));
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
locations.add(link);
}
return locations.toArray(ARRAY_OF_STRINGS);
} | Retrieves the physical locationS (URLs) of web pageS providing knowledge about an entity.
@param datatypeKey name (can be a synonym), ID, or URI of a data type (examples: "Gene Ontology", "UniProt")
@param entityId identifier of an entity within the given data type (examples: "GO:0045202", "P62158")
@return physical locationS (URL templates) of web pageS providing knowledge about the given entity
@throws IllegalArgumentException when datatype not found |
public static String[] getDataResources(String datatypeKey)
{
Set<String> locations = new HashSet<String>();
Datatype datatype = getDatatype(datatypeKey);
for (Resource resource : getResources(datatype)) {
String link = resource.getDataResource();
locations.add(link);
}
return locations.toArray(ARRAY_OF_STRINGS);
} | Retrieves home page URLs of a datatype.
@param datatypeKey - name (can be a synonym), ID, or URI (URL or URN) of a data type
@return array of strings containing all the address of the main page of the resources of the data type
@throws IllegalArgumentException when datatype not found |
public static boolean isDeprecated(String uri)
{
Datatype datatype = datatypesHash.get(uri);
String urn = getOfficialDataTypeURI(datatype);
return !uri.equalsIgnoreCase(urn);
} | To know if a URI of a data type is deprecated.
@param uri (URN or URL) of a data type
@return answer ("true" or "false") to the question: is this URI deprecated? |
public static String getDataTypePattern(String datatypeKey)
{
Datatype datatype = getDatatype(datatypeKey);
return datatype.getPattern();
} | Retrieves the pattern (regular expression) used by the identifiers within a data type.
@param datatypeKey data type ID, name (or synonym), or URI (URL or URN)
@return pattern of the data type
@throws IllegalArgumentException when datatype not found |
public static String getName(String datatypeKey)
{
Datatype datatype = getDatatype(datatypeKey);
return datatype.getName();
} | Retrieves the preferred name of a data type.
@param datatypeKey URI (URL or URN), ID, or nickname of a data type
@return the common name of the data type
@throws IllegalArgumentException when not found |
public static String[] getNames(String datatypeKey)
{
Set<String> names = new HashSet<String>();
Datatype datatype = getDatatype(datatypeKey);
names.add(datatype.getName());
Synonyms synonyms = datatype.getSynonyms();
if(synonyms != null)
for(String name : synonyms.getSynonym()) {
names.add(name);
}
return names.toArray(ARRAY_OF_STRINGS);
} | Retrieves all the synonyms (incl. the preferred name) of a data type.
@param datatypeKey ID, any name, or URI (URL or URN) of a data type
@return all the data type's synonyms (incl. preferred name) |
public static String[] getDataTypesName()
{
Set<String> dataTypeNames = new HashSet<String>();
for(Datatype datatype : miriam.getDatatype()) {
dataTypeNames.add(datatype.getName());
}
return dataTypeNames.toArray(ARRAY_OF_STRINGS);
} | Retrieves the list of preferred names of all the data types available.
@return list of names of all the data types |
public static String[] getDataTypesId()
{
Set<String> dataTypeIds = new HashSet<String>();
for(Datatype datatype : miriam.getDatatype()) {
dataTypeIds.add(datatype.getId());
}
return dataTypeIds.toArray(new String[] {});
} | Retrieves the internal identifier (stable and perennial) of
all the data types (for example: "MIR:00000005").
@return list of the identifier of all the data types |
public static boolean checkRegExp(String identifier, String datatype)
{
Datatype dt = getDatatype(datatype);
return Pattern.compile(dt.getPattern()).matcher(identifier).find();
} | Checks if the identifier given follows the regular expression
of its data type (also provided).
@param identifier internal identifier used by the data type
@param datatype name, synonym or URI of a data type
@return "true" if the identifier follows the regular expression, "false" otherwise
@throws IllegalArgumentException when datatype not found |
public static String getOfficialDataTypeURI(Datatype datatype) {
for(Uris uris : datatype.getUris()) {
for(Uri uri : uris.getUri()) {
if(!isDeprecated(uri) && uri.getType() == UriType.URN) {
return uri.getValue();
}
}
}
return null;
} | Retrieves the unique (official) URI of a data type
(example: "http://identifiers.org/uniprot").
@param datatype net.biomodels.miriam.Miriam.Datatype
@return URI |
public static Datatype getDatatype(String datatypeKey)
{
Datatype dt = null;
if(containsIdOrName(datatypeKey))
dt = datatypesHash.get(datatypeKey.toUpperCase());
else if(containsUri(datatypeKey))
dt = datatypesHash.get(datatypeKey);
else
throw new IllegalArgumentException("Datatype not found : " + datatypeKey);
if(!useObsoleteDatatypes
&& dt.isObsolete() != null
&& dt.isObsolete().booleanValue() == true)
throw new IllegalArgumentException("Datatype " +
datatypeKey + "(" + dt.getName() + ") is obsolete" +
" (and useObsoleteDatatypes=false)");
// return
return dt;
} | Gets Miriam Datatype by its ID, Name, Synonym, or URI (URN/URL)
@param datatypeKey - a datatype ID, name, synonym, or URI
@return MIRIAM Datatype bean
@throws IllegalArgumentException when not found |
public static String[] getResourcesId()
{
Set<String> ids = new HashSet<String>();
for(Datatype datatype : miriam.getDatatype()) {
for (Resource resource : getResources(datatype)) {
ids.add(resource.getId());
}
}
return ids.toArray(new String[] {});
} | Retrieves the internal identifier (stable and perennial) of
all the resources (for example: "MIR:00100008" (bind) ).
@return list of the identifiers of all data types |
public static Resource getResource(String resourceId)
{
for(Datatype datatype : miriam.getDatatype()) {
for (Resource resource : getResources(datatype)) {
if (resource.getId().equalsIgnoreCase(resourceId))
return resource;
}
}
throw new IllegalArgumentException("Resource not found : " + resourceId);
} | Retrieves the resource by id (for example: "MIR:00100008" (bind) ).
@param resourceId - resource identifier (similar to, but not a data type identifier!)
@return MIRIAM Resource bean |
private static List<Resource> getResources(Datatype datatype) {
List<Resource> toReturn = new ArrayList<Resource>();
Resources resources = datatype.getResources();
if (resources != null) {
for (Resource resource : resources.getResource()) {
if(useObsoleteResources // ok to collect (- do not care about obsolete)
|| resource.isObsolete() == null // undefined - here means non-obsolete (ok)
|| !resource.isObsolete().booleanValue()) {
toReturn.add(resource);
}
}
}
return toReturn;
} | Gets the list of Miriam {@link Resource} from
the datatype, also taking the 'obsolete' flag/state
into account.
@param datatype a MIRIAM Datatype
@return the list of MIRIAM Resources in that datatype |
public static String convertUrn(String urn) {
String[] tokens = urn.split(":");
return "http://identifiers.org/" + tokens[tokens.length-2]
+ "/" + URLDecoder.decode(tokens[tokens.length-1]);
} | Converts a MIRIAM URN into its equivalent Identifiers.org URL.
@see #getURI(String, String) - use this to get the URN
@see #getIdentifiersOrgURI(String, String) - prefered URI
@param urn - an existing Miriam URN, e.g., "urn:miriam:obo.go:GO%3A0045202"
@return the Identifiers.org URL corresponding to the data URN, e.g., "http://identifiers.org/obo.go/GO:0045202"
@deprecated this method applies {@link URLDecoder#decode(String)} to the last part of the URN, which may not always work as expected (test yours!) |
public static String getIdentifiersOrgURI(String name, String id)
{
String url = null;
Datatype datatype = getDatatype(name);
String db = datatype.getName();
if(checkRegExp(id, db)) {
uris:
for(Uris uris : datatype.getUris()) {
for(Uri uri : uris.getUri()) {
if(uri.getValue().startsWith("http://identifiers.org/")) {
url = uri.getValue() + id;
break uris;
}
}
}
} else
throw new IllegalArgumentException(
"ID pattern mismatch. db=" + db + ", id=" + id
+ ", regexp: " + datatype.getPattern());
return url;
} | Gets the Identifiers.org URI/URL of the entity (example: "http://identifiers.org/obo.go/GO:0045202").
@param name - name, URI/URL, or ID of a data type (examples: "ChEBI", "MIR:00000005")
@param id identifier of an entity within the data type (examples: "GO:0045202", "P62158")
@return Identifiers.org URL for the id
@throws IllegalArgumentException when datatype not found |
public int equivalenceCode()
{
int result =
29 + (STRUCTURE_FORMAT != null ? STRUCTURE_FORMAT.hashCode() : 0);
result = 29 * result +
(STRUCTURE_DATA != null ? STRUCTURE_DATA.hashCode() : 0);
return result;
} | ------------------------ CANONICAL METHODS ------------------------ |
protected boolean semanticallyEquivalent(BioPAXElement element)
{
final chemicalStructure that = (chemicalStructure) element;
return
(STRUCTURE_DATA != null ?
STRUCTURE_DATA.equals(that.getSTRUCTURE_DATA()) :
that.getSTRUCTURE_DATA() == null)
&&
(STRUCTURE_FORMAT != null ?
STRUCTURE_FORMAT.equals(that.getSTRUCTURE_FORMAT()) :
that.getSTRUCTURE_FORMAT() == null);
} | --------------------- Interface BioPAXElement --------------------- |
@Override
protected R parseValueFromString(String s)
{
Class<R> range = this.getRange();
R value = null;
try
{
if (range.equals(double.class))
{
value= (R) Double.valueOf(s);
}
else if (range.equals(float.class))
{
value= (R) Float.valueOf(s);
}
else if (range.equals(int.class))
{
value= (R) Integer.valueOf(s);
}
else if (range.equals(Boolean.class))
{
value= (R) Boolean.valueOf(s);
}
}
catch (NumberFormatException e)
{
throw new IllegalBioPAXArgumentException(
"Failed to convert literal " + s +
" to " + range.getSimpleName()
+ " for " + property, e);
}
return value;
} | -------------------------- OTHER METHODS -------------------------- |
@Override
public boolean isUnknown(Object value)
{
return (value instanceof Set)
? emptySetOrContainsOnlyUnknowns((Set)value)
: emptySetOrContainsOnlyUnknowns(Collections.singleton(value));
} | According the editor type, this methods checks if value equals
to one of the unknown values defined under {@link org.biopax.paxtools.model.BioPAXElement}
or is an empty set or set of "unknown" values.
@param value the value to be checked if it is unknown
@return true, if value equals to the predefined unknown value |
@Override
protected R parseValueFromString(String value)
{
value = value.replaceAll("-", "_");
value = value.replaceAll("^\\s+","");
value = value.replaceAll("\\s+$","");
return (R)Enum.valueOf(this.getRange(), value);
} | -------------------------- OTHER METHODS -------------------------- |
@Override
public boolean satisfies(Match match, int... ind)
{
int x = -1;
for (MappedConst mc : con)
{
if (mc.satisfies(match, ind)) x *= -1;
}
return x == 1;
} | Checks if constraints satisfy in xor pattern.
@param match match to validate
@param ind mapped indices
@return true if all satisfy |
@Override
public Collection<BioPAXElement> generate(Match match, int... ind)
{
Collection<BioPAXElement> gen = new HashSet<BioPAXElement> (
con[0].generate(match, ind));
for (int i = 1; i < con.length; i++)
{
if (gen.isEmpty()) break;
Collection<BioPAXElement> subset = con[i].generate(match, ind);
Set<BioPAXElement> copy = new HashSet<BioPAXElement>(subset);
copy.removeAll(gen);
gen.removeAll(subset);
gen.addAll(copy);
}
return gen;
} | Gets xor of the generated elements by the member constraints.
@param match match to process
@param ind mapped indices
@return satisfying elements |
@Override
public boolean satisfies(Match match, int... ind)
{
assert ind.length == 1;
return clazz.isAssignableFrom(match.get(ind[0]).getModelInterface());
} | Checks if the element is assignable to a variable of the desired type.
@param match current pattern match
@param ind mapped indices
@return true if the element is assignable to a variable of the desired type |
@Override
protected boolean semanticallyEquivalent(BioPAXElement element) {
if(! (element instanceof Evidence) ) return false;
Evidence that = (Evidence) element; // not null (guaranteed by here)
boolean hasAllEquivEvidenceCodes = false;
if(this.getEvidenceCode().isEmpty()) {
if(that.getEvidenceCode().isEmpty()) {
hasAllEquivEvidenceCodes = true;
}
} else {
if(!that.getEvidenceCode().isEmpty()) {
Set<EvidenceCodeVocabulary> shorter;
Set<EvidenceCodeVocabulary> longer;
if (this.getEvidenceCode().size() < that.getEvidenceCode().size())
{
shorter = this.getEvidenceCode();
longer = that.getEvidenceCode();
} else {
longer = this.getEvidenceCode();
shorter = that.getEvidenceCode();
}
/* each ECV in the 'shorter' set must find its equivalent
* in the 'longer' set;
* otherwise two Evidence objects (this and that) are not equiv.
*/
hasAllEquivEvidenceCodes = true; // initial guess
for(EvidenceCodeVocabulary secv : shorter) {
boolean foundEquiv = false;
for(EvidenceCodeVocabulary lecv : longer) {
if(secv.isEquivalent(lecv)) {
foundEquiv = true;
}
}
if(!foundEquiv) {
hasAllEquivEvidenceCodes = false;
break;
}
}
}
}
//consider publication xrefs!
boolean hasCommonPublicationXref = hasEquivalentIntersection(
new ClassFilterSet<Xref, PublicationXref>(getXref(), PublicationXref.class),
new ClassFilterSet<Xref, PublicationXref>(that.getXref(), PublicationXref.class));
return super.semanticallyEquivalent(element) && hasAllEquivEvidenceCodes && hasCommonPublicationXref;
} | Answers whether two Evidence objects are semantically equivalent.
(Currently, it considers only member UnificationXrefs and EvidenceCodeVocabularies
for comparison...)
TODO: review; compare ExperimentalForm and Confidence values; or - simply always return false! |
private String getIdent(BioPAXElement bpe) {
String ident = "----";
if(bpe instanceof pathway) {
ident = "-pw-";
} else if(bpe instanceof interaction) {
ident = "-in-";
} else if (bpe instanceof protein) {
ident = "-pr-";
} else if (bpe instanceof complex) {
ident = "-co-";
}
return ident;
} | get remarks |
public void run(Entry entry) {
// get availabilities
final Set<String> avail = new HashSet<String>();
if(entry.hasAvailabilities()) {
for (Availability a : entry.getAvailabilities())
if (a.hasValue())
avail.add(a.getValue());
}
// get data source
final Provenance pro = createProvenance(entry.getSource());
//build a skip-set of "interactions" linked by participant.interactionRef element;
//we'll then create Complex type participants from these in-participant interactions.
Set<Interaction> participantInteractions = new HashSet<Interaction>();
for(Interaction interaction : entry.getInteractions()) {
for(Participant participant : interaction.getParticipants()) {
//checking for hasInteraction()==true only is sufficient;
//i.e., we ignore hasInteractionRef(), getInteractionRefs(),
//because these in fact get cleared by the PSI-MI parser:
if(participant.hasInteraction()) {
participantInteractions.add(participant.getInteraction());
}
}
}
// iterate through the "root" psimi interactions only and create biopax interactions or complexes
for (Interaction interaction : entry.getInteractions()) {
if(!participantInteractions.contains(interaction)) {
// TODO future (hard): make a Complex or Interaction based on the interaction type ('direct interaction' or 'physical association' (IntAct) -> complex)
processInteraction(interaction, avail, pro, false);
}
}
} | Convert a PSIMI entry to BioPAX
interactions, participants, etc. objects
and add to the target BioPAX model.
@param entry |
private Entity processInteraction(Interaction interaction, Set<String> avail,
Provenance pro, boolean isComplex)
{
Entity bpInteraction = null; //interaction or complex
boolean isGeneticInteraction = false;
// get interaction name/short name
String name = null;
String shortName = null;
if (interaction.hasNames()) {
Names names = interaction.getNames();
name = (names.hasFullName()) ? names.getFullName() : "";
shortName = (names.hasShortLabel()) ? names.getShortLabel() : "";
}
final Set<InteractionVocabulary> interactionVocabularies = new HashSet<InteractionVocabulary>();
if (interaction.hasInteractionTypes()) {
for(CvType interactionType : interaction.getInteractionTypes()) {
//generate InteractionVocabulary and set interactionType
InteractionVocabulary cv = findOrCreateControlledVocabulary(interactionType, InteractionVocabulary.class);
if(cv != null)
interactionVocabularies.add(cv);
}
}
// using experiment descriptions, create Evidence objects
// (yet, no experimental forms/roles/entities are created here)
Set<Evidence> bpEvidences = new HashSet<Evidence>();
if (interaction.hasExperiments()) {
bpEvidences = createBiopaxEvidences(interaction);
}
//A hack for e.g. IntAct or BIND "gene-protein" interactions (ChIp and EMSA experiments)
// where the interactor type should probably not be 'gene' (but 'dna' or 'rna')
Set<String> participantTypes = new HashSet<String>();
for(Participant p : interaction.getParticipants()) {
if(p.hasInteractor()) {
String type = getName(p.getInteractor().getInteractorType().getNames());
if(type==null) type = "protein"; //default type (if unspecified)
participantTypes.add(type.toLowerCase());
} else if (p.hasInteraction()) {
participantTypes.add("complex"); //hierarchical complex build up
} // else? (impossible!)
}
// If there are both genes and physical entities present, let's
// replace 'gene' with 'dna' (esp. true for "ch-ip", "emsa" experiments);
// (this won't affect experimental form entities if experimentalInteractor element exists)
if(participantTypes.size() > 1 && participantTypes.contains("gene")) {
//TODO a better criteria to reliably detect whether 'gene' interactor type actually means Dna/DnaRegion or Rna/RnaRegion, or indeed Gene)
LOG.warn("Interaction: " + interaction.getId() + ", name(s): " + shortName + " " + name
+ "; has both 'gene' and physical entity type participants: " + participantTypes
+ "; so we'll replace 'gene' with 'dna' (a quick fix)");
for(Participant p : interaction.getParticipants()) {
if(p.hasInteractor() && p.getInteractor().getInteractorType().hasNames()) {
String type = getName(p.getInteractor().getInteractorType().getNames());
if("gene".equalsIgnoreCase(type)) {
p.getInteractor().getInteractorType().getNames().setShortLabel("dna");
}
}
}
}
// interate through the psi-mi participants, create corresp. biopax entities
final Set<Entity> bpParticipants = new HashSet<Entity>();
for (Participant participant : interaction.getParticipants()) {
// get paxtools physical entity participant and add to participant list
// (this also adds experimental evidence and forms)
Entity bpParticipant = createBiopaxEntity(participant, avail, pro);
if (bpParticipant != null) {
if(!bpParticipants.contains(bpParticipant))
bpParticipants.add(bpParticipant);
}
}
// Process interaction attributes.
final Set<String> comments = new HashSet<String>();
// Set GeneticInteraction flag.
// As of BioGRID v3.1.72 (at least), genetic interaction code can reside
// as an attribute of the Interaction via "BioGRID Evidence Code" key
if (interaction.hasAttributes()) {
for (Attribute attribute : interaction.getAttributes()) {
String key = attribute.getName(); //may be reset below
String value = (attribute.hasValue()) ? attribute.getValue() : "";
if(key.equalsIgnoreCase(BIOGRID_EVIDENCE_CODE)
&& GENETIC_INTERACTIONS.contains(value))
{
isGeneticInteraction = true; // important!
}
comments.add(key + ":" + value);
}
}
// or, if all participants are 'gene' type, make a biopax GeneticInteraction
if(participantTypes.size() == 1 && participantTypes.contains("gene")) {
isGeneticInteraction = true;
}
//or, check another genetic interaction flag (criteria)
if(!isGeneticInteraction) {
isGeneticInteraction = isGeneticInteraction(bpEvidences);
}
if ((isComplex || forceInteractionToComplex) && !isGeneticInteraction) {
bpInteraction = createComplex(bpParticipants, interaction.getImexId(), interaction.getId());
} else if(isGeneticInteraction) {
bpInteraction = createGeneticInteraction(bpParticipants, interactionVocabularies,
interaction.getImexId(), interaction.getId()
);
} else {
bpInteraction = createMolecularInteraction(bpParticipants, interactionVocabularies,
interaction.getImexId(), interaction.getId());
}
for(String c : comments) {
bpInteraction.addComment(c);
}
//add evidences to the interaction/complex bpEntity
for (Evidence evidence : bpEvidences) {
bpInteraction.addEvidence(evidence);
//TODO: shall we add IntAct "figure legend" comment to the evidences as well?
}
addAvailabilityAndProvenance(bpInteraction, avail, pro);
if (name != null)
bpInteraction.addName(name);
if (shortName != null) {
if(shortName.length()<51)
bpInteraction.setDisplayName(shortName);
else
bpInteraction.addName(shortName);
}
// add xrefs
Set<Xref> bpXrefs = new HashSet<Xref>();
if (interaction.hasXref()) {
bpXrefs.addAll(getXrefs(interaction.getXref()));
}
for (Xref bpXref : bpXrefs) {
bpInteraction.addXref(bpXref);
}
return bpInteraction;
} | /*
Creates a paxtools object that
corresponds to the psi interaction.
Note:
psi.interactionElementType -> biopax Complex, MolecularInteraction, or GeneticInteraction
psi.interactionElementType.participantList -> biopax interaction/complex participants/components |
@Override
public Collection<BioPAXElement> generate(Match match, int... ind)
{
Interaction inter = (Interaction) match.get(ind[0]);
Set<Entity> taboo = new HashSet<Entity>();
for (int i = 1; i < getVariableSize() - 1; i++)
{
taboo.add((Entity) match.get(ind[i]));
}
if (direction == null) return generate(inter, taboo);
else return generate((Conversion) inter, direction, taboo);
} | Iterated over non-taboo participants and collectes related ER.
@param match current pattern match
@param ind mapped indices
@return related participants |
protected Collection<BioPAXElement> generate(Interaction inter, Set<Entity> taboo)
{
Set<BioPAXElement> simples = new HashSet<BioPAXElement>();
for (Entity part : inter.getParticipant())
{
if (part instanceof PhysicalEntity && !taboo.contains(part))
{
simples.addAll(linker.getLinkedElements((PhysicalEntity) part));
}
}
return pe2ER.getValueFromBeans(simples);
} | Gets the related entity references of the given interaction.
@param inter interaction
@param taboo entities to ignore/skip
@return entity references |
protected Collection<BioPAXElement> generate(Conversion conv, Direction direction,
Set<Entity> taboo)
{
if (direction == null) throw new IllegalArgumentException("Direction cannot be null");
if (!(direction == Direction.BOTHSIDERS || direction == Direction.ONESIDERS))
{
Set<BioPAXElement> simples = new HashSet<BioPAXElement>();
for (Entity part : direction == Direction.ANY ? conv.getParticipant() :
direction == Direction.LEFT ? conv.getLeft() : conv.getRight())
{
if (part instanceof PhysicalEntity && !taboo.contains(part))
{
simples.addAll(linker.getLinkedElements((PhysicalEntity) part));
}
}
return pe2ER.getValueFromBeans(simples);
}
else
{
Set<BioPAXElement> leftSimples = new HashSet<BioPAXElement>();
Set<BioPAXElement> rightSimples = new HashSet<BioPAXElement>();
for (PhysicalEntity pe : conv.getLeft())
{
if (!taboo.contains(pe)) leftSimples.addAll(linker.getLinkedElements(pe));
}
for (PhysicalEntity pe : conv.getRight())
{
if (!taboo.contains(pe)) rightSimples.addAll(linker.getLinkedElements(pe));
}
Set leftERs = pe2ER.getValueFromBeans(leftSimples);
Set rightERs = pe2ER.getValueFromBeans(rightSimples);
if (direction == Direction.ONESIDERS)
{
// get all but intersection
Set temp = new HashSet(leftERs);
leftERs.removeAll(rightERs);
rightERs.removeAll(temp);
leftERs.addAll(rightERs);
}
else // BOTHSIDERS
{
// get intersection
leftERs.retainAll(rightERs);
}
return leftERs;
}
} | Gets the related entity references of the given interaction,
@param conv conversion interaction
@param direction which side(s) participants of the conversion to consider
@param taboo skip list of entities
@return entity references |
boolean compareParticipantSets(
Set<InteractionParticipant> set1,
Set<InteractionParticipant> set2)
{
if (set1.size() == set2.size())
{
for (InteractionParticipant ip : set1)
{
//TODO
}
}
return false;
} | TODO |
void updatePARTICIPANTS(
Set<? extends InteractionParticipant> oldSet,
Set<? extends InteractionParticipant> newSet)
{
if (oldSet != null)
{
PARTICIPANTS.removeComposited(oldSet);
for (InteractionParticipant ip : oldSet)
{
setParticipantInverse(ip, true);
}
}
if (newSet != null)
{
PARTICIPANTS.addComposited(newSet);
for (InteractionParticipant ip : newSet)
{
setParticipantInverse(ip, false);
}
}
} | --------------------- ACCESORS and MUTATORS--------------------- |
public static <D extends BioPAXElement, R> PropertyAccessor<D,R> create(PropertyAccessor<D,R> pa,
Class filter)
{
return new FilteredPropertyAccessor<D, R>(pa, filter);
} | FactoryMethod that creates a filtered property accessor by decorating a given accessor with a class filter.
@param pa to be decorated
@param filter Class to be filtered, must extend from R.
@param <D> Domain of the original accessor
@param <R> Range of the original accessor
@return A filtered accessor. |
public void visit(BioPAXElement domain, Object range, Model model, PropertyEditor<?,?> editor) {
// actions
visit(range, domain, model, editor);
} | Calls the protected abstract method visit that is to be
implemented in subclasses of this abstract class.
@param domain BioPAX Element
@param range property value (can be BioPAX element, primitive, enum, string)
@param model the BioPAX model of interest
@param editor parent's property PropertyEditor |
public String getXmlStreamInfo()
{
StringBuilder sb = new StringBuilder();
int event = r.getEventType();
if (event == START_ELEMENT || event == END_ELEMENT || event == ENTITY_REFERENCE)
{
sb.append(r.getLocalName());
}
if (r.getLocation() != null)
{
sb.append(" line ");
sb.append(r.getLocation().getLineNumber());
sb.append(" column ");
sb.append(r.getLocation().getColumnNumber());
}
return sb.toString();
} | This may be required for external applications to access the specific information (e.g.,
location) when reporting XML exceptions.
@return current XML stream state summary |
private void bindValue(Triple triple, Model model)
{
if (log.isDebugEnabled())
log.debug(String.valueOf(triple));
BioPAXElement domain = model.getByID(triple.domain);
PropertyEditor editor = this.getEditorMap().getEditorForProperty(triple.property, domain.getModelInterface());
bindValue(triple.range, editor, domain, model);
} | Binds property.
This method also throws exceptions related to binding.
@param triple A java object that represents an RDF Triple - domain-property-range.
@param model that is being populated. |
public void convertToOWL(Model model, OutputStream outputStream)
{
initializeExporter(model);
try
{
Writer out = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8"));
writeObjects(out, model);
out.close();
}
catch (IOException e)
{
throw new BioPaxIOException("Cannot convert to OWL!", e);
}
} | Converts a model into BioPAX (OWL) format, and writes it into
the outputStream. Saved data can be then read via {@link BioPAXIOHandler}
interface (e.g., {@link SimpleIOHandler}).
Note: When the model is incomplete (i.e., contains elements that refer externals,
dangling BioPAX elements) and is exported by this method, it works; however one
will find corresponding object properties set to NULL later,
after converting such data back to Model.
Note: if the model is very very large, and the output stream is a byte array stream,
then you can eventually get OutOfMemoryError "Requested array size exceeds VM limit"
(max. array size is 2Gb)
@param model model to be converted into OWL format
@param outputStream output stream into which the output will be written
@throws BioPaxIOException in case of I/O problems |
public void writeObject(Writer out, BioPAXElement bean) throws IOException
{
String name = "bp:" + bean.getModelInterface().getSimpleName();
writeIDLine(out, bean, name);
Set<PropertyEditor> editors = editorMap.getEditorsOf(bean);
if (editors == null || editors.isEmpty())
{
log.info("no editors for " + bean.getUri() + " | " + bean.getModelInterface().getSimpleName());
out.write(newline + "</" + name + ">");
return;
}
for (PropertyEditor editor : editors)
{
Set value = editor.getValueFromBean(bean); //is never null
for (Object valueElement : value)
{
if (!editor.isUnknown(valueElement)) writeStatementFor(bean, editor, valueElement, out);
}
}
out.write(newline + "</" + name + ">");
} | Writes the XML representation of individual BioPAX element that
is BioPAX-like but only for display or debug purpose (incomplete).
Note: use {@link BioPAXIOHandler#convertToOWL(org.biopax.paxtools.model.Model, java.io.OutputStream)}
convertToOWL(org.biopax.paxtools.model.Model, Object)} instead
if you have a model and want to save and later restore it.
@param out output
@param bean BioPAX object
@throws IOException when the output writer throws |
public static String convertToOwl(Model model)
{
if (model == null) throw new IllegalArgumentException();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
(new SimpleIOHandler(model.getLevel())).convertToOWL(model, outputStream);
try
{
return outputStream.toString("UTF-8");
}
catch (UnsupportedEncodingException e)
{
log.error("convertToOwl, outputStream.toString failed", e);
return outputStream.toString();
}
} | Serializes a (not too large) BioPAX model to the RDF/XML (OWL) formatted string.
@param model a BioPAX object model to convert to the RDF/XML format
@return the BioPAX data in the RDF/XML format
@throws IllegalArgumentException if model is null
@throws OutOfMemoryError when it cannot be stored in a byte array (max 2Gb). |
@Override
public boolean satisfies(Match match, int... ind)
{
PhysicalEntity pe1 = (PhysicalEntity) match.get(ind[0]);
PhysicalEntity pe2 = (PhysicalEntity) match.get(ind[1]);
Set<ModificationFeature>[] mods =
DifferentialModificationUtil.getChangedModifications(pe1, pe2);
Set<String> terms;
if (type == Type.GAIN) terms = collectTerms(mods[0]);
else if (type == Type.LOSS) terms = collectTerms(mods[1]);
else terms = collectTerms(mods);
return termsContainDesired(terms);
} | Checks the any of the changed modifications match to any of the desired modifications.
@param match current pattern match
@param ind mapped indices
@return true if a modification change is among desired modifications |
private boolean termsContainDesired(Set<String> terms)
{
if (terms.isEmpty()) return false;
if (featureSubstring.length == 0) return true;
for (String term : terms)
{
for (String sub : featureSubstring)
{
if (term.contains(sub)) return true;
}
}
return false;
} | Checks if any element in the set contains the term.
@param terms changed terms
@return true if any changed terms contains a desired substring |
@Override
public boolean satisfies(Match match, int... ind)
{
for (MappedConst mc : con)
{
if (mc.satisfies(match, ind)) return true;
}
return false;
} | Checks if any of the wrapped constraints satisfy.
@param match current pattern match
@param ind mapped indices
@return true if any of the wrapped constraints satisfy |
@Override
public int getVariableSize()
{
int size = 0;
for (MappedConst mc : con)
{
int m = max(mc.getInds());
if (m > size) size = m;
}
return size + 1;
} | Checks the inner mapping of the wrapped constraints and figures the size.
@return the size |
protected int max(int[] v)
{
int x = 0;
for (int i : v)
{
if (i > x) x = i;
}
return x;
} | Gets the max value.
@param v array to check
@return max value |
@Override
public Collection<BioPAXElement> generate(Match match, int... ind)
{
Collection<BioPAXElement> gen = new HashSet<BioPAXElement>();
for (MappedConst mc : con)
{
gen.addAll(mc.generate(match, ind));
}
return gen;
} | Gets the intersection of the generated values of wrapped constraints.
@param match current pattern match
@param ind mapped indices
@return intersection of the generated values of wrapped constraints |
public static Pattern controlsStateChange()
{
Pattern p = new Pattern(SequenceEntityReference.class, "controller ER");
p.add(linkedER(true), "controller ER", "generic controller ER");
p.add(erToPE(), "generic controller ER", "controller simple PE");
p.add(linkToComplex(), "controller simple PE", "controller PE");
p.add(peToControl(), "controller PE", "Control");
p.add(controlToConv(), "Control", "Conversion");
p.add(new NOT(participantER()), "Conversion", "controller ER");
p.add(new Participant(RelType.INPUT, true), "Control", "Conversion", "input PE");
p.add(new NOT(new ConversionSide(ConversionSide.Type.OTHER_SIDE)), "input PE", "Conversion", "input PE");
p.add(linkToSpecific(), "input PE", "input simple PE");
p.add(new Type(SequenceEntity.class), "input simple PE");
p.add(peToER(), "input simple PE", "changed generic ER");
p.add(new ConversionSide(ConversionSide.Type.OTHER_SIDE), "input PE", "Conversion", "output PE");
p.add(new NOT(new ConversionSide(ConversionSide.Type.OTHER_SIDE)), "output PE", "Conversion", "output PE");
p.add(equal(false), "input PE", "output PE");
p.add(linkToSpecific(), "output PE", "output simple PE");
p.add(peToER(), "output simple PE", "changed generic ER");
p.add(linkedER(false), "changed generic ER", "changed ER");
return p;
} | Pattern for a EntityReference has a member PhysicalEntity that is controlling a state change
reaction of another EntityReference.
@return the pattern |
public static Pattern controlsTransport()
{
Pattern p = controlsStateChange();
p.add(new OR(
new MappedConst(hasDifferentCompartments(), 0, 1),
new MappedConst(hasDifferentCompartments(), 2, 3)),
"input simple PE", "output simple PE", "input PE", "output PE");
return p;
} | Pattern for a ProteinReference has a member PhysicalEntity that is controlling a
transportation of another ProteinReference.
@return the pattern |
public static Pattern controlsTransportOfChemical(Blacklist blacklist)
{
Pattern p = new Pattern(SequenceEntityReference.class, "controller ER");
p.add(linkedER(true), "controller ER", "controller generic ER");
p.add(erToPE(), "controller generic ER", "controller simple PE");
p.add(linkToComplex(), "controller simple PE", "controller PE");
p.add(peToControl(), "controller PE", "Control");
p.add(controlToConv(), "Control", "Conversion");
p.add(new Participant(RelType.INPUT, blacklist, true), "Control", "Conversion", "input PE");
p.add(linkToSimple(blacklist), "input PE", "input simple PE");
p.add(new Type(SmallMolecule.class), "input simple PE");
p.add(notGeneric(), "input simple PE");
p.add(peToER(), "input simple PE", "changed generic SMR");
p.add(new ConversionSide(ConversionSide.Type.OTHER_SIDE, blacklist, RelType.OUTPUT), "input PE", "Conversion", "output PE");
p.add(equal(false), "input PE", "output PE");
p.add(linkToSimple(blacklist), "output PE", "output simple PE");
p.add(new Type(SmallMolecule.class), "output simple PE");
p.add(notGeneric(), "output simple PE");
p.add(peToER(), "output simple PE", "changed generic SMR");
p.add(linkedER(false), "changed generic SMR", "changed SMR");
p.add(new OR(
new MappedConst(hasDifferentCompartments(), 0, 1),
new MappedConst(hasDifferentCompartments(), 2, 3)),
"input simple PE", "output simple PE", "input PE", "output PE");
return p;
} | Pattern for a ProteinReference has a member PhysicalEntity that is controlling a reaction
that changes cellular location of a small molecule.
@param blacklist a skip-list of ubiquitous molecules
@return the pattern |
public static Pattern controlsStateChangeBothControlAndPart()
{
Pattern p = new Pattern(SequenceEntityReference.class, "controller ER");
p.add(linkedER(true), "controller ER", "controller generic ER");
p.add(erToPE(), "controller generic ER", "controller simple PE");
p.add(linkToComplex(), "controller simple PE", "controller PE");
p.add(peToControl(), "controller PE", "Control");
p.add(controlToConv(), "Control", "Conversion");
// the controller PE is also an input
p.add(new ParticipatesInConv(RelType.INPUT), "controller PE", "Conversion");
// same controller simple PE is also an output
p.add(linkToComplex(), "controller simple PE", "special output PE");
p.add(equal(false), "special output PE", "controller PE");
p.add(new ParticipatesInConv(RelType.OUTPUT), "special output PE", "Conversion");
stateChange(p, "Control");
// non-generic input and outputs are only associated with one side
p.add(equal(false), "input simple PE", "output simple PE");
p.add(new NOT(simplePEToConv(RelType.OUTPUT)), "input simple PE", "Conversion");
p.add(new NOT(simplePEToConv(RelType.INPUT)), "output simple PE", "Conversion");
p.add(equal(false), "controller ER", "changed ER");
p.add(type(SequenceEntityReference.class), "changed ER");
return p;
} | Pattern for a EntityReference has a member PhysicalEntity that is controlling a state change
reaction of another EntityReference. In this case the controller is also an input to the
reaction. The affected protein is the one that is represented with different non-generic
physical entities at left and right of the reaction.
@return the pattern |
public static Pattern controlsStateChangeButIsParticipant()
{
Pattern p = new Pattern(SequenceEntityReference.class, "controller ER");
p.add(linkedER(true), "controller ER", "controller generic ER");
p.add(erToPE(), "controller generic ER", "controller simple PE");
p.add(linkToComplex(), "controller simple PE", "controller PE");
p.add(participatesInConv(), "controller PE", "Conversion");
p.add(left(), "Conversion", "controller PE");
p.add(right(), "Conversion", "controller PE");
// The controller ER is not associated with the Conversion in another way.
p.add(new NOT(new InterToPartER(1)), "Conversion", "controller PE", "controller ER");
stateChange(p, null);
p.add(equal(false), "controller ER", "changed ER");
p.add(equal(false), "controller PE", "input PE");
p.add(equal(false), "controller PE", "output PE");
return p;
} | Pattern for a EntityReference has a member PhysicalEntity that is controlling a state change
reaction of another EntityReference. This pattern is different from the original
controls-state-change. The controller in this case is not modeled as a controller, but as a
participant of the conversion, and it is at both sides.
@return the pattern |
public static Pattern stateChange(Pattern p, String ctrlLabel)
{
if (p == null) p = new Pattern(Conversion.class, "Conversion");
if (ctrlLabel == null) p.add(new Participant(RelType.INPUT), "Conversion", "input PE");
else p.add(new Participant(RelType.INPUT, true), ctrlLabel, "Conversion", "input PE");
p.add(linkToSpecific(), "input PE", "input simple PE");
p.add(peToER(), "input simple PE", "changed generic ER");
p.add(new ConversionSide(ConversionSide.Type.OTHER_SIDE), "input PE", "Conversion", "output PE");
p.add(equal(false), "input PE", "output PE");
p.add(linkToSpecific(), "output PE", "output simple PE");
p.add(peToER(), "output simple PE", "changed generic ER");
p.add(linkedER(false), "changed generic ER", "changed ER");
return p;
} | Pattern for a Conversion has an input PhysicalEntity and another output PhysicalEntity that
belongs to the same EntityReference.
@param p pattern to update
@param ctrlLabel label
@return the pattern |
public static Pattern controlsStateChangeThroughControllerSmallMolecule(Blacklist blacklist)
{
Pattern p = new Pattern(SequenceEntityReference.class, "upper controller ER");
p.add(linkedER(true), "upper controller ER", "upper controller generic ER");
p.add(erToPE(), "upper controller generic ER", "upper controller simple PE");
p.add(linkToComplex(), "upper controller simple PE", "upper controller PE");
p.add(peToControl(), "upper controller PE", "upper Control");
p.add(controlToConv(), "upper Control", "upper Conversion");
p.add(new NOT(participantER()), "upper Conversion", "upper controller ER");
p.add(new Participant(RelType.OUTPUT, blacklist), "upper Conversion", "controller PE");
p.add(type(SmallMolecule.class), "controller PE");
if (blacklist != null) p.add(new NonUbique(blacklist), "controller PE");
// the linker small mol is at also an input
p.add(new NOT(new ConstraintChain(
new ConversionSide(ConversionSide.Type.OTHER_SIDE), linkToSpecific())),
"controller PE", "upper Conversion", "controller PE");
p.add(peToControl(), "controller PE", "Control");
p.add(controlToConv(), "Control", "Conversion");
p.add(equal(false), "upper Conversion", "Conversion");
// p.add(nextInteraction(), "upper Conversion", "Conversion");
stateChange(p, "Control");
p.add(type(SequenceEntityReference.class), "changed ER");
p.add(equal(false), "upper controller ER", "changed ER");
p.add(new NOT(participantER()), "Conversion", "upper controller ER");
return p;
} | Pattern for an entity is producing a small molecule, and the small molecule controls state
change of another molecule.
@param blacklist a skip-list of ubiquitous molecules
@return the pattern |
public static Pattern controlsStateChangeThroughDegradation()
{
Pattern p = new Pattern(SequenceEntityReference.class, "upstream ER");
p.add(linkedER(true), "upstream ER", "upstream generic ER");
p.add(erToPE(), "upstream generic ER", "upstream SPE");
p.add(linkToComplex(), "upstream SPE", "upstream PE");
p.add(peToControl(), "upstream PE", "Control");
p.add(controlToConv(), "Control", "Conversion");
p.add(new NOT(participantER()), "Conversion", "upstream ER");
p.add(new Empty(new Participant(RelType.OUTPUT)), "Conversion");
p.add(new Participant(RelType.INPUT), "Conversion", "input PE");
p.add(linkToSpecific(), "input PE", "input SPE");
p.add(peToER(), "input SPE", "downstream generic ER");
p.add(type(SequenceEntityReference.class), "downstream generic ER");
p.add(linkedER(false), "downstream generic ER", "downstream ER");
return p;
} | Finds cases where proteins affect their degradation.
@return the pattern |
public static Pattern controlsMetabolicCatalysis(Blacklist blacklist, boolean consumption)
{
Pattern p = new Pattern(SequenceEntityReference.class, "controller ER");
p.add(linkedER(true), "controller ER", "controller generic ER");
p.add(erToPE(), "controller generic ER", "controller simple PE");
p.add(linkToComplex(), "controller simple PE", "controller PE");
p.add(peToControl(), "controller PE", "Control");
p.add(controlToConv(), "Control", "Conversion");
p.add(new NOT(participantER()), "Conversion", "controller ER");
p.add(new Participant(consumption ? RelType.INPUT : RelType.OUTPUT, blacklist, true),
"Control", "Conversion", "part PE");
p.add(linkToSimple(blacklist), "part PE", "part SM");
p.add(notGeneric(), "part SM");
p.add(type(SmallMolecule.class), "part SM");
p.add(peToER(), "part SM", "part SMR");
// The small molecule is associated only with left or right, but not both.
p.add(new XOR(
new MappedConst(new InterToPartER(InterToPartER.Direction.LEFT), 0, 1),
new MappedConst(new InterToPartER(InterToPartER.Direction.RIGHT), 0, 1)),
"Conversion", "part SMR");
return p;
} | Pattern for a Protein controlling a reaction whose participant is a small molecule.
@param blacklist a skip-list of ubiquitous molecules
@param consumption true/false (TODO explain)
@return the pattern |
public static Pattern catalysisPrecedes(Blacklist blacklist)
{
Pattern p = new Pattern(SequenceEntityReference.class, "first ER");
p.add(linkedER(true), "first ER", "first generic ER");
p.add(erToPE(), "first generic ER", "first simple controller PE");
p.add(linkToComplex(), "first simple controller PE", "first controller PE");
p.add(peToControl(), "first controller PE", "first Control");
p.add(controlToConv(), "first Control", "first Conversion");
p.add(new Participant(RelType.OUTPUT, blacklist, true), "first Control", "first Conversion", "linker PE");
p.add(new NOT(new ConstraintChain(new ConversionSide(ConversionSide.Type.OTHER_SIDE), linkToSpecific())), "linker PE", "first Conversion", "linker PE");
p.add(type(SmallMolecule.class), "linker PE");
p.add(new ParticipatesInConv(RelType.INPUT, blacklist), "linker PE", "second Conversion");
p.add(new NOT(new ConstraintChain(new ConversionSide(ConversionSide.Type.OTHER_SIDE), linkToSpecific())), "linker PE", "second Conversion", "linker PE");
p.add(equal(false), "first Conversion", "second Conversion");
// make sure that conversions are not replicates or reverse of each other
// and also outward facing sides of reactions contain at least one non ubique
p.add(new ConstraintAdapter(3, blacklist)
{
@Override
public boolean satisfies(Match match, int... ind)
{
Conversion cnv1 = (Conversion) match.get(ind[0]);
Conversion cnv2 = (Conversion) match.get(ind[1]);
SmallMolecule linker = (SmallMolecule) match.get(ind[2]);
Set<PhysicalEntity> input1 = cnv1.getLeft().contains(linker) ? cnv1.getRight() : cnv1.getLeft();
Set<PhysicalEntity> input2 = cnv2.getLeft().contains(linker) ? cnv2.getLeft() : cnv2.getRight();
Set<PhysicalEntity> output1 = cnv1.getLeft().contains(linker) ? cnv1.getLeft() : cnv1.getRight();
Set<PhysicalEntity> output2 = cnv2.getLeft().contains(linker) ? cnv2.getRight() : cnv2.getLeft();
if (input1.equals(input2) && output1.equals(output2)) return false;
if (input1.equals(output2) && output1.equals(input2)) return false;
if (blacklist != null)
{
Set<PhysicalEntity> set = new HashSet<PhysicalEntity>(input1);
set = blacklist.getNonUbiques(set, RelType.INPUT);
set.removeAll(output2);
if (set.isEmpty())
{
set.addAll(output2);
set = blacklist.getNonUbiques(set, RelType.OUTPUT);
set.removeAll(input1);
if (set.isEmpty()) return false;
}
}
return true;
}
}, "first Conversion", "second Conversion", "linker PE");
p.add(new RelatedControl(RelType.INPUT, blacklist), "linker PE", "second Conversion", "second Control");
p.add(controllerPE(), "second Control", "second controller PE");
p.add(new NOT(compToER()), "second controller PE", "first ER");
p.add(linkToSpecific(), "second controller PE", "second simple controller PE");
p.add(type(SequenceEntity.class), "second simple controller PE");
p.add(peToER(), "second simple controller PE", "second generic ER");
p.add(linkedER(false), "second generic ER", "second ER");
p.add(equal(false), "first ER", "second ER");
return p;
} | Pattern for detecting two EntityReferences are controlling consecutive reactions, where
output of one reaction is input to the other.
@param blacklist to detect ubiquitous small molecules
@return the pattern |
public static Pattern controlsExpressionWithTemplateReac()
{
Pattern p = new Pattern(SequenceEntityReference.class, "TF ER");
p.add(linkedER(true), "TF ER", "TF generic ER");
p.add(erToPE(), "TF generic ER", "TF SPE");
p.add(linkToComplex(), "TF SPE", "TF PE");
p.add(peToControl(), "TF PE", "Control");
p.add(controlToTempReac(), "Control", "TempReac");
p.add(product(), "TempReac", "product PE");
p.add(linkToSpecific(), "product PE", "product SPE");
p.add(new Type(SequenceEntity.class), "product SPE");
p.add(peToER(), "product SPE", "product generic ER");
p.add(linkedER(false), "product generic ER", "product ER");
p.add(equal(false), "TF ER", "product ER");
return p;
} | Finds transcription factors that trans-activate or trans-inhibit an entity.
@return the pattern |
public static Pattern controlsExpressionWithConversion()
{
Pattern p = new Pattern(SequenceEntityReference.class, "TF ER");
p.add(linkedER(true), "TF ER", "TF generic ER");
p.add(erToPE(), "TF generic ER", "TF SPE");
p.add(linkToComplex(), "TF SPE", "TF PE");
p.add(peToControl(), "TF PE", "Control");
p.add(controlToConv(), "Control", "Conversion");
p.add(new Size(right(), 1, Size.Type.EQUAL), "Conversion");
p.add(new OR(new MappedConst(new Empty(left()), 0), new MappedConst(new ConstraintAdapter(1)
{
@Override
public boolean satisfies(Match match, int... ind)
{
Conversion cnv = (Conversion) match.get(ind[0]);
Set<PhysicalEntity> left = cnv.getLeft();
if (left.size() > 1) return false;
if (left.isEmpty()) return true;
PhysicalEntity pe = left.iterator().next();
if (pe instanceof NucleicAcid)
{
PhysicalEntity rPE = cnv.getRight().iterator().next();
return rPE instanceof Protein;
}
return false;
}
}, 0)), "Conversion");
p.add(right(), "Conversion", "right PE");
p.add(linkToSpecific(), "right PE", "right SPE");
p.add(new Type(SequenceEntity.class), "right SPE");
p.add(peToER(), "right SPE", "product generic ER");
p.add(linkedER(false), "product generic ER", "product ER");
p.add(equal(false), "TF ER", "product ER");
return p;
} | Finds the cases where transcription relation is shown using a Conversion instead of a
TemplateReaction.
@return the pattern |
public static Pattern controlsDegradationIndirectly()
{
Pattern p = controlsStateChange();
p.add(new Size(new ParticipatesInConv(RelType.INPUT), 1, Size.Type.EQUAL), "output PE");
p.add(new Empty(peToControl()), "output PE");
p.add(new ParticipatesInConv(RelType.INPUT), "output PE", "degrading Conv");
p.add(new NOT(type(ComplexAssembly.class)), "degrading Conv");
p.add(new Size(participant(), 1, Size.Type.EQUAL), "degrading Conv");
p.add(new Empty(new Participant(RelType.OUTPUT)), "degrading Conv");
p.add(new Empty(convToControl()), "degrading Conv");
p.add(equal(false), "degrading Conv", "Conversion");
return p;
} | Finds cases where protein A changes state of B, and B is then degraded.
NOTE: THIS PATTERN DOES NOT WORK. KEEPING ONLY FOR HISTORICAL REASONS.
@return the pattern |
public static Pattern inComplexWith()
{
Pattern p = new Pattern(SequenceEntityReference.class, "Protein 1");
p.add(linkedER(true), "Protein 1", "generic Protein 1");
p.add(erToPE(), "generic Protein 1", "SPE1");
p.add(linkToComplex(), "SPE1", "PE1");
p.add(new PathConstraint("PhysicalEntity/componentOf"), "PE1", "Complex");
p.add(new PathConstraint("Complex/component"), "Complex", "PE2");
p.add(equal(false), "PE1", "PE2");
p.add(linkToSpecific(), "PE2", "SPE2");
p.add(peToER(), "SPE2", "generic Protein 2");
p.add(linkedER(false), "generic Protein 2", "Protein 2");
p.add(equal(false), "Protein 1", "Protein 2");
p.add(new Type(SequenceEntityReference.class), "Protein 2");
return p;
} | Two proteins have states that are members of the same complex. Handles nested complexes and
homologies. Also guarantees that relationship to the complex is through different direct
complex members.
@return pattern |
public static Pattern chemicalAffectsProteinThroughBinding(Blacklist blacklist)
{
Pattern p = new Pattern(SmallMoleculeReference.class, "SMR");
p.add(erToPE(), "SMR", "SPE1");
p.add(notGeneric(), "SPE1");
if (blacklist != null) p.add(new NonUbique(blacklist), "SPE1");
p.add(linkToComplex(), "SPE1", "PE1");
p.add(new PathConstraint("PhysicalEntity/componentOf"), "PE1", "Complex");
p.add(new PathConstraint("Complex/component"), "Complex", "PE2");
p.add(equal(false), "PE1", "PE2");
p.add(linkToSpecific(), "PE2", "SPE2");
p.add(new Type(SequenceEntity.class), "SPE2");
p.add(peToER(), "SPE2", "generic ER");
p.add(linkedER(false), "generic ER", "ER");
return p;
} | A small molecule is in a complex with a protein.
@param blacklist a skip-list of ubiquitous molecules
@return pattern |
public static Pattern neighborOf()
{
Pattern p = new Pattern(SequenceEntityReference.class, "Protein 1");
p.add(linkedER(true), "Protein 1", "generic Protein 1");
p.add(erToPE(), "generic Protein 1", "SPE1");
p.add(linkToComplex(), "SPE1", "PE1");
p.add(peToInter(), "PE1", "Inter");
p.add(interToPE(), "Inter", "PE2");
p.add(linkToSpecific(), "PE2", "SPE2");
p.add(equal(false), "SPE1", "SPE2");
p.add(type(SequenceEntity.class), "SPE2");
p.add(peToER(), "SPE2", "generic Protein 2");
p.add(linkedER(false), "generic Protein 2", "Protein 2");
p.add(equal(false), "Protein 1", "Protein 2");
return p;
} | Constructs a pattern where first and last proteins are related through an interaction. They
can be participants or controllers. No limitation.
@return the pattern |
public static Pattern reactsWith(Blacklist blacklist)
{
Pattern p = new Pattern(SmallMoleculeReference.class, "SMR1");
p.add(erToPE(), "SMR1", "SPE1");
p.add(notGeneric(), "SPE1");
p.add(linkToComplex(blacklist), "SPE1", "PE1");
p.add(new ParticipatesInConv(RelType.INPUT, blacklist), "PE1", "Conv");
p.add(type(BiochemicalReaction.class), "Conv");
p.add(new InterToPartER(InterToPartER.Direction.ONESIDERS), "Conv", "SMR1");
p.add(new ConversionSide(ConversionSide.Type.SAME_SIDE, blacklist, RelType.INPUT), "PE1", "Conv", "PE2");
p.add(type(SmallMolecule.class), "PE2");
p.add(linkToSpecific(), "PE2", "SPE2");
p.add(notGeneric(), "SPE2");
p.add(new PEChainsIntersect(false), "SPE1", "PE1", "SPE2", "PE2");
p.add(peToER(), "SPE2", "SMR2");
p.add(equal(false), "SMR1", "SMR2");
p.add(new InterToPartER(InterToPartER.Direction.ONESIDERS), "Conv", "SMR2");
return p;
} | Constructs a pattern where first and last small molecules are substrates to the same
biochemical reaction.
@param blacklist a skip-list of ubiquitous molecules
@return the pattern |
public static Pattern usedToProduce(Blacklist blacklist)
{
Pattern p = new Pattern(SmallMoleculeReference.class, "SMR1");
p.add(erToPE(), "SMR1", "SPE1");
p.add(notGeneric(), "SPE1");
p.add(linkToComplex(blacklist), "SPE1", "PE1");
p.add(new ParticipatesInConv(RelType.INPUT, blacklist), "PE1", "Conv");
p.add(type(BiochemicalReaction.class), "Conv");
p.add(new InterToPartER(InterToPartER.Direction.ONESIDERS), "Conv", "SMR1");
p.add(new ConversionSide(ConversionSide.Type.OTHER_SIDE, blacklist, RelType.OUTPUT), "PE1", "Conv", "PE2");
p.add(type(SmallMolecule.class), "PE2");
p.add(linkToSimple(blacklist), "PE2", "SPE2");
p.add(notGeneric(), "SPE2");
p.add(equal(false), "SPE1", "SPE2");
p.add(peToER(), "SPE2", "SMR2");
p.add(equal(false), "SMR1", "SMR2");
p.add(new InterToPartER(InterToPartER.Direction.ONESIDERS), "Conv", "SMR2");
return p;
} | Constructs a pattern where first small molecule is an input a biochemical reaction that
produces the second small molecule.
biochemical reaction.
@param blacklist a skip-list of ubiquitous molecules
@return the pattern |
public static Pattern molecularInteraction()
{
Pattern p = new Pattern(SequenceEntityReference.class, "Protein 1");
p.add(linkedER(true), "Protein 1", "generic Protein 1");
p.add(erToPE(), "generic Protein 1", "SPE1");
p.add(linkToComplex(), "SPE1", "PE1");
p.add(new PathConstraint("PhysicalEntity/participantOf:MolecularInteraction"), "PE1", "MI");
p.add(participant(), "MI", "PE2");
p.add(equal(false), "PE1", "PE2");
// participants are not both baits or preys
p.add(new NOT(new AND(new MappedConst(isPrey(), 0), new MappedConst(isPrey(), 1))), "PE1", "PE2");
p.add(new NOT(new AND(new MappedConst(isBait(), 0), new MappedConst(isBait(), 1))), "PE1", "PE2");
p.add(linkToSpecific(), "PE2", "SPE2");
p.add(type(SequenceEntity.class), "SPE2");
p.add(new PEChainsIntersect(false), "SPE1", "PE1", "SPE2", "PE2");
p.add(peToER(), "SPE2", "generic Protein 2");
p.add(linkedER(false), "generic Protein 2", "Protein 2");
p.add(equal(false), "Protein 1", "Protein 2");
return p;
} | Constructs a pattern where first and last molecules are participants of a
MolecularInteraction.
@return the pattern |
public static Pattern relatedProteinRefOfInter(Class<? extends Interaction>... seedType)
{
Pattern p = new Pattern(Interaction.class, "Interaction");
if (seedType.length == 1)
{
p.add(new Type(seedType[0]), "Interaction");
}
else if (seedType.length > 1)
{
MappedConst[] mc = new MappedConst[seedType.length];
for (int i = 0; i < mc.length; i++)
{
mc[i] = new MappedConst(new Type(seedType[i]), 0);
}
p.add(new OR(mc), "Interaction");
}
p.add(new OR(new MappedConst(participant(), 0, 1),
new MappedConst(new PathConstraint(
"Interaction/controlledOf*/controller:PhysicalEntity"), 0, 1)),
"Interaction", "PE");
p.add(linkToSpecific(), "PE", "SPE");
p.add(peToER(), "SPE", "generic PR");
p.add(new Type(ProteinReference.class), "generic PR");
p.add(linkedER(false), "generic PR", "PR");
return p;
} | Finds ProteinsReference related to an interaction. If specific types of interactions are
desired, they should be sent as parameter, otherwise leave the parameter empty.
@param seedType specific BioPAX interaction sub-types (interface classes)
@return pattern |
public static Pattern inSameComplex()
{
Pattern p = new Pattern(EntityReference.class, "first ER");
p.add(erToPE(), "first ER", "first simple PE");
p.add(linkToComplex(), "first simple PE", "Complex");
p.add(new Type(Complex.class), "Complex");
p.add(linkToSpecific(), "Complex", "second simple PE");
p.add(equal(false), "first simple PE", "second simple PE");
p.add(new PEChainsIntersect(false, true), "first simple PE", "Complex", "second simple PE", "Complex");
p.add(peToER(), "second simple PE", "second ER");
p.add(equal(false), "first ER", "second ER");
return p;
} | Pattern for two different EntityReference have member PhysicalEntity in the same Complex.
Complex membership can be through multiple nesting and/or through homology relations.
@return the pattern |
public static Pattern inSameActiveComplex()
{
Pattern p = inSameComplex();
p.add(new ActivityConstraint(true), "Complex");
return p;
} | Pattern for two different EntityReference have member PhysicalEntity in the same Complex, and
the Complex has an activity. Complex membership can be through multiple nesting and/or
through homology relations.
@return the pattern |
public static Pattern inSameComplexHavingTransActivity()
{
Pattern p = inSameComplex();
p.add(peToControl(), "Complex", "Control");
p.add(controlToTempReac(), "Control", "TR");
p.add(new NOT(participantER()), "TR", "first ER");
p.add(new NOT(participantER()), "TR", "second ER");
return p;
} | Pattern for two different EntityReference have member PhysicalEntity in the same Complex, and
the Complex has transcriptional activity. Complex membership can be through multiple nesting
and/or through homology relations.
@return the pattern |
public static Pattern inSameComplexEffectingConversion()
{
Pattern p = inSameComplex();
p.add(peToControl(), "Complex", "Control");
p.add(controlToConv(), "Control", "Conversion");
p.add(new NOT(participantER()), "Control", "first ER");
p.add(new NOT(participantER()), "Control", "second ER");
return p;
} | Pattern for two different EntityReference have member PhysicalEntity in the same Complex, and
the Complex is controlling a Conversion. Complex membership can be through multiple nesting
and/or through homology relations.
@return the pattern |
public static Pattern modifiedPESimple()
{
Pattern p = new Pattern(EntityReference.class, "modified ER");
p.add(erToPE(), "modified ER", "first PE");
p.add(participatesInConv(), "first PE", "Conversion");
p.add(new ConversionSide(ConversionSide.Type.OTHER_SIDE), "first PE", "Conversion", "second PE");
p.add(equal(false), "first PE", "second PE");
p.add(peToER(), "second PE", "modified ER");
return p;
} | Pattern for an EntityReference has distinct PhysicalEntities associated with both left and
right of a Conversion.
@return the pattern |
public static Pattern actChange(boolean activating,
Map<EntityReference, Set<ModificationFeature>> activityFeat,
Map<EntityReference, Set<ModificationFeature>> inactivityFeat)
{
Pattern p = peInOut();
p.add(new OR(
new MappedConst(differentialActivity(activating), 0, 1),
new MappedConst(new ActivityModificationChangeConstraint(
activating, activityFeat, inactivityFeat), 0, 1)),
"input simple PE", "output simple PE");
return p;
} | Pattern for the activity of an EntityReference is changed through a Conversion.
@param activating desired change
@param activityFeat modification features associated with activity
@param inactivityFeat modification features associated with inactivity
@return the pattern |
public static Pattern modifierConv()
{
Pattern p = new Pattern(EntityReference.class, "ER");
p.add(erToPE(), "ER", "SPE");
p.add(linkToComplex(), "SPE", "PE");
p.add(participatesInConv(), "PE", "Conversion");
return p;
} | Pattern for finding Conversions that an EntityReference is participating.
@return the pattern |
public static Pattern hasNonSelfEffect()
{
Pattern p = new Pattern(PhysicalEntity.class, "SPE");
p.add(peToER(), "SPE", "ER");
p.add(linkToComplex(), "SPE", "PE");
p.add(peToControl(), "PE", "Control");
p.add(controlToInter(), "Control", "Inter");
p.add(new NOT(participantER()), "Inter", "ER");
return p;
} | Pattern for detecting PhysicalEntity that controls a Conversion whose participants are not
associated with the EntityReference of the initial PhysicalEntity.
@return the pattern |
public static Pattern bindsTo()
{
Pattern p = new Pattern(ProteinReference.class, "first PR");
p.add(erToPE(), "first PR", "first simple PE");
p.add(linkToComplex(), "first simple PE", "Complex");
p.add(new Type(Complex.class), "Complex");
p.add(linkToSpecific(), "Complex", "second simple PE");
p.add(peToER(), "second simple PE", "second PR");
p.add(equal(false), "first PR", "second PR");
return p;
} | Finds two Protein that appear together in a Complex.
@return the pattern |
public static void main(String[] args)
{
if (args.length != 1)
{
System.out.println("\nUse Parameter: path (to biopax OWL files)\n");
System.exit(-1);
}
BioPAXIOHandler reader = new SimpleIOHandler();
final String pathname = args[0];
File testDir = new File(pathname);
/*
* Customized Fetcher is to fix the issue with Level2
* - when NEXT-STEP leads out of the pathway...
* (do not worry - those pathway steps that are part of
* the pathway must be in the PATHWAY-COMPONENTS set)
*/
Filter<PropertyEditor> nextStepPropertyFilter = new Filter<PropertyEditor>()
{
public boolean filter(PropertyEditor editor)
{
return !editor.getProperty().equals("NEXT-STEP");
}
};
fetcher = new Fetcher(SimpleEditorMap.L2, nextStepPropertyFilter);
FilenameFilter filter = new FilenameFilter()
{
public boolean accept(File dir, String name)
{
return (name.endsWith("owl"));
}
};
for (String s : testDir.list(filter))
{
try
{
process(pathname, s, reader);
}
catch (Exception e)
{
log.error("Failed at testing " + s, e);
}
}
} | --------------------------- main() method --------------------------- |
public static void listUnificationXrefsPerPathway(Model model)
{
// This is a visitor for elements in a pathway - direct and indirect
Visitor visitor = new Visitor()
{
public void visit(BioPAXElement domain, Object range, Model model, PropertyEditor editor)
{
if (range instanceof physicalEntity)
{
// Do whatever you want with the pe and xref here
physicalEntity pe = (physicalEntity) range;
ClassFilterSet<xref,unificationXref> unis = new ClassFilterSet<xref,unificationXref>(pe.getXREF(),
unificationXref.class);
for (unificationXref uni : unis)
{
System.out.println("pe.getNAME() = " + pe.getNAME());
System.out.println("uni = " + uni.getID());
}
}
}
};
Traverser traverser = new Traverser(SimpleEditorMap.L2, visitor);
Set<pathway> pathways = model.getObjects(pathway.class);
for (pathway pathway : pathways)
{
traverser.traverse(pathway, model);
}
} | Here is a more elegant way of doing the previous method!
@param model BioPAX object Model |
public int equivalenceCode()
{
int result = 29 + (TAXON_XREF != null ? TAXON_XREF.hashCode() : 0);
result = 29 * result + (CELLTYPE != null ? CELLTYPE.hashCode() : 0);
result = 29 * result + (TISSUE != null ? TISSUE.hashCode() : 0);
return result;
} | ------------------------ CANONICAL METHODS ------------------------ |
protected boolean semanticallyEquivalent(BioPAXElement element)
{
final bioSource bioSource = (bioSource) element;
return
(CELLTYPE != null ?
CELLTYPE.equals(bioSource.getCELLTYPE()) :
bioSource.getCELLTYPE() == null)
&&
(TAXON_XREF != null ?
TAXON_XREF.equals(bioSource.getTAXON_XREF()) :
bioSource.getTAXON_XREF() == null)
&&
(TISSUE != null ?
!TISSUE.equals(bioSource.getTISSUE()) :
bioSource.getTISSUE() != null);
} | --------------------- Interface BioPAXElement --------------------- |
protected boolean semanticallyEquivalent(BioPAXElement o)
{
if (o!= null && o instanceof openControlledVocabulary)
{
openControlledVocabulary that =
(openControlledVocabulary) o;
return
this.equals(that) ||
hasCommonTerm(that) ||
!this.findCommonUnifications(that).isEmpty();
}
return false;
} | TODO: think about this.
@return false |
@Override
public boolean satisfies(Match match, int... ind)
{
PhysicalEntity pe0 = (PhysicalEntity) match.get(ind[0]);
PhysicalEntity pe1 = (PhysicalEntity) match.get(ind[1]);
PhysicalEntity pe2 = (PhysicalEntity) match.get(ind[2]);
PhysicalEntity pe3 = (PhysicalEntity) match.get(ind[3]);
PhysicalEntityChain ch1 = new PhysicalEntityChain(pe0, pe1);
PhysicalEntityChain ch2 = new PhysicalEntityChain(pe2, pe3);
return ch1.intersects(ch2, ignoreEndPoints) == intersectionDesired;
} | Creates two PhysicalEntity chains with the given endpoints, and checks if they are
intersecting.
@param match current pattern match
@param ind mapped indices
@return true if the chains are intersecting or not intersecting as desired |
public <T extends BioPAXElement> T create(Class<T> aClass, String uri)
{
// //could use the following shortcut, but it might hurt performance of creating/reading large valid models
// if(!canInstantiate(aClass)) {
// log.error("Non-instantiable: cannot create BioPAX object, uri:"+uri+", with abstract type: " + aClass);
// return null;
// }
T bpe = null;
// create a new instance of the BioPAX type
try {
Class<T> t = getImplClass(aClass);
if(t != null) {
Constructor<T> c = t.getDeclaredConstructor();
c.setAccessible(true);
bpe = (T) c.newInstance();
setUriMethod.invoke(bpe, uri);
} else {
log.error("Could not find a class implementing " + aClass);
}
} catch (InvocationTargetException e) { //this happened, weird (might due to lack of memory or busy...)
log.error("Failed creating BioPAX object: " + aClass + ", URI: " + uri + " - " + e, e.getCause());
} catch (Exception e) {
log.error("Failed creating BioPAX object: " + aClass + ", URI: " + uri, e);
}
return bpe;
} | Universal method that creates a new BioPAX object.
(works with non-public, other package, implementations)
@param <T> type
@param aClass the class that corresponds to the BioPAX type
@param uri absolute URI of the new BioPAX object
@return new BioPAX object |
public boolean canInstantiate(Class<? extends BioPAXElement> aClass)
{
try {
String cname = mapClassName(aClass);
return !Modifier.isAbstract(Class.forName(cname).getModifiers());
} catch (ClassNotFoundException e)
{
return false;
} catch (Exception ex) {
log.error("Error in canInstantiate(" + aClass + ")", ex);
return false;
}
} | Checks whether objects of a BioPAX model interface
can be created (some types are not official BioPAX
types, abstract classes).
@param aClass BioPAX interface class
@return whether this factory can create an instance of the type |
public <T extends BioPAXElement> Class<T> getImplClass(Class<T> aModelInterfaceClass)
{
Class<T> implClass = null;
if (aModelInterfaceClass.isInterface()) {
String name = mapClassName(aModelInterfaceClass);
try {
implClass = (Class<T>) Class.forName(name);
} catch (ClassNotFoundException e) {
log.debug(String.format("getImplClass(%s), %s" , aModelInterfaceClass, e));
}
}
return implClass;
} | Get a concrete or abstract BioPAX type (not interface),
from org.biopax.paxtools.impl..*, i.e., one that has
persistence/search annotations, etc. This may be required for
some DAO and web service controllers; it also returns such
abstract BioPAX "adapters" as XReferrableImpl, ProcessImpl, etc.
@param <T> BioPAX type/interface
@param aModelInterfaceClass interface class for the BioPAX type
@return concrete class that implements the BioPAX interface and can be created with this factory |
@Override
public Collection<BioPAXElement> generate(Match match, int... ind)
{
assertIndLength(ind);
PhysicalEntity pe1 = (PhysicalEntity) match.get(ind[0]);
Conversion conv = (Conversion) match.get(ind[1]);
Set<PhysicalEntity> parts;
if (conv.getLeft().contains(pe1))
{
parts = sideType == Type.OTHER_SIDE ? conv.getRight() : conv.getLeft();
}
else if (conv.getRight().contains(pe1))
{
parts = sideType == Type.SAME_SIDE ? conv.getRight() : conv.getLeft();
}
else throw new IllegalArgumentException(
"The PhysicalEntity has to be a participant of the Conversion.");
if (blacklist == null) return new HashSet<BioPAXElement>(parts);
else
{
ConversionDirectionType dir = getDirection(conv);
if ((dir == ConversionDirectionType.LEFT_TO_RIGHT && ((relType == RelType.INPUT && parts != conv.getLeft()) || (relType == RelType.OUTPUT && parts != conv.getRight()))) ||
(dir == ConversionDirectionType.RIGHT_TO_LEFT && ((relType == RelType.INPUT && parts != conv.getRight()) || (relType == RelType.OUTPUT && parts != conv.getLeft()))))
return Collections.emptySet();
return new HashSet<BioPAXElement>(blacklist.getNonUbiques(parts, relType));
}
} | Checks which side is the first PhysicalEntity, and gathers participants on either the other
side or the same side.
@param match current pattern match
@param ind mapped indices
@return participants at the desired side |
protected void registerEditorsWithSubClasses(PropertyEditor editor, Class<? extends BioPAXElement> domain) {
for (Class<? extends BioPAXElement> c : classToEditorMap.keySet())
{
if (domain.isAssignableFrom(c)) {
//workaround for participants - can be replaced w/ a general
// annotation based system. For the time being, I am just handling it
//as a special case
if ((editor.getProperty().equals("PARTICIPANTS") &&
(conversion.class.isAssignableFrom(c) || control.class.isAssignableFrom(c))) ||
(editor.getProperty().equals("participant") &&
(Conversion.class.isAssignableFrom(c) || Control.class.isAssignableFrom(c)))) {
if (log.isDebugEnabled()) {
log.debug("skipping restricted participant property");
}
} else {
classToEditorMap.get(c).put(editor.getProperty(), editor);
}
}
}
if (editor instanceof ObjectPropertyEditor) {
registerInverseEditors((ObjectPropertyEditor) editor);
}
} | This method registers an editor with sub classes - i.e. inserts the editor to the proper value in editor maps.
@param editor to be registered
@param domain a subclass of the editor's original domain. |
protected void registerModelClass(String localName) {
try {
Class<? extends BioPAXElement> domain = this.getLevel().getInterfaceForName(localName);
HashMap<String, PropertyEditor> peMap = new HashMap<String, PropertyEditor>();
classToEditorMap.put(domain, peMap);
classToInverseEditorMap.put(domain, new HashSet<ObjectPropertyEditor>());
classToEditorSet.put(domain, new ValueSet(peMap.values()));
} catch (IllegalBioPAXArgumentException e) {
if (log.isDebugEnabled()) {
log.debug("Skipping (" + e.getMessage() + ")");
}
}
} | This method inserts the class into internal hashmaps and initializes the value collections.
@param localName of the BioPAX class. |
public Set<GraphObject> run()
{
for (GraphObject go : new HashSet<GraphObject>(result))
{
if (go instanceof Node)
{
checkNodeRecursive((Node) go);
}
}
return result;
} | Executes the algorithm.
@return the pruned graph |
private void checkNodeRecursive(Node node)
{
if (isDangling(node))
{
removeNode(node);
for (Edge edge : node.getUpstream())
{
checkNodeRecursive(edge.getSourceNode());
}
for (Edge edge : node.getDownstream())
{
checkNodeRecursive(edge.getTargetNode());
}
for (Node parent : node.getUpperEquivalent())
{
checkNodeRecursive(parent);
}
for (Node child : node.getLowerEquivalent())
{
checkNodeRecursive(child);
}
}
} | Recursively checks if a node is dangling.
@param node Node to check |
private void removeNode(Node node)
{
result.remove(node);
for (Edge edge : node.getUpstream())
{
result.remove(edge);
}
for (Edge edge : node.getDownstream())
{
result.remove(edge);
}
} | Removes the dangling node and its edges.
@param node Node to remove |
private boolean isDangling(Node node)
{
if (!result.contains(node)) return false;
if (ST.contains(node)) return false;
boolean hasIncoming = false;
for (Edge edge : node.getUpstream())
{
if (result.contains(edge))
{
hasIncoming = true;
break;
}
}
boolean hasOutgoing = false;
for (Edge edge : node.getDownstream())
{
if (result.contains(edge))
{
hasOutgoing = true;
break;
}
}
if (hasIncoming && hasOutgoing) return false;
boolean hasParent = false;
for (Node parent : node.getUpperEquivalent())
{
if (result.contains(parent))
{
hasParent = true;
break;
}
}
if (hasParent && (hasIncoming || hasOutgoing)) return false;
boolean hasChild = false;
for (Node child : node.getLowerEquivalent())
{
if (result.contains(child))
{
hasChild = true;
break;
}
}
return !(hasChild && (hasIncoming || hasOutgoing || hasParent));
} | Checks if the node is dangling.
@param node Node to check
@return true if dangling |
public Model filter(Model model) {
if(model == null || model.getLevel() != BioPAXLevel.L2)
return model; // nothing to do
preparePep2PEIDMap(model);
final Model newModel = factory.createModel();
newModel.getNameSpacePrefixMap().putAll(model.getNameSpacePrefixMap());
newModel.setXmlBase(model.getXmlBase());
// facilitate the conversion
normalize(model);
// First, map classes (and only set ID) if possible (pre-processing)
for(BioPAXElement bpe : model.getObjects()) {
Level3Element l3element = mapClass(bpe);
if(l3element != null) {
newModel.add(l3element);
} else {
log.debug("Skipping " + bpe + " " + bpe.getModelInterface().getSimpleName());
}
}
/* process each L2 element (mapping properties),
* except for pEPs and oCVs that must be processed as values
* (anyway, we do not want dangling elements)
*/
for(BioPAXElement e : model.getObjects()) {
if(e instanceof physicalEntityParticipant
|| e instanceof openControlledVocabulary) {
continue;
}
// map properties
traverse((Level2Element) e, newModel);
}
log.info("Done: new L3 model contains " + newModel.getObjects().size() + " BioPAX individuals.");
// fix new model (e.g., add PathwayStep's processes to the pathway components ;))
normalize(newModel);
return newModel;
} | Converts a BioPAX Model, Level 1 or 2, to the Level 3.
@param model BioPAX model to upgrade
@return new Level3 model |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.