/** * Pre-check for all relations that <i>may</i> be accepted by <code>isValid(ONDEXRelation, StateMachineDerivedPath)</code>. * * @param relation the relation to check * @return true if the relation is valid, ignoring the path tag */ public boolean isValid(ONDEXRelation relation) { return relation.getOfType().equals(rt); }
/** * Return all of the relation types of the relations * contained in the collection * * @param cs * @return set of relation types */ public static Set<RelationType> getRelationTypes(Collection<ONDEXRelation> cs) { Set<RelationType> result = new HashSet<RelationType>(); for (ONDEXRelation c : cs) { result.add(c.getOfType()); } return result; }
/** * Return all of the relation types of the relations * contained in the collection * * @param cs * @return set of relation types */ public static Set<RelationType> getRelationTypes(Collection<ONDEXRelation> cs) { Set<RelationType> result = new HashSet<RelationType>(); for (ONDEXRelation c : cs) { result.add(c.getOfType()); } return result; }
/** * Returns result of transformation. * * @param edge * ONDEXRelation * @return String */ public Stroke transform(ONDEXRelation edge) { if (esf != null) { // transform edge thickness return new BasicStroke(esf.transform(edge)); } else { // without a size transformer if (!strokes.containsKey(edge.getOfType())) { Stroke stroke = new BasicStroke(Config.getSizeForRelationType(edge.getOfType())); strokes.put(edge.getOfType(), stroke); } return strokes.get(edge.getOfType()); } }
private boolean instanceOf(RelationType rt, ONDEXRelation r) { RelationType rt_query = r.getOfType(); while (!rt_query.equals(rt)) { if (rt_query.getSpecialisationOf() == null) { return false; } rt_query = rt_query.getSpecialisationOf(); } return true; }
/** * Returns all outgoing relations of concept * * @param graph * - graph * @param c * - concept * @param exclude * - ignore retalions of these types * @return - set of relations */ public static final Set<ONDEXRelation> getOutgoingRelations(ONDEXGraph graph, ONDEXConcept c, RelationType... exclude) { Set<RelationType> toExclude = new HashSet<RelationType>(Arrays.asList(exclude)); Set<ONDEXRelation> result = new HashSet<ONDEXRelation>(); for (ONDEXRelation r : graph.getRelationsOfConcept(c)) { if (r.getFromConcept().equals(c) && !toExclude.contains(r.getOfType())) result.add(r); } return result; }
public String getValue(ONDEXEntity cOrr) throws InvalidOndexEntityException { if(AbstractConcept.class.isAssignableFrom(cOrr.getClass())){ return ((ONDEXConcept)cOrr).getOfType().getId(); } if(AbstractRelation.class.isAssignableFrom(cOrr.getClass())){ return ((ONDEXRelation)cOrr).getOfType().getId(); } throw new InvalidOndexEntityException(cOrr.getClass()+": is not an Ondex class for which type is known"); }
/** * Returns all incoming relations of concept * * @param graph * - graph * @param c * - concept * @param exclude * - ignore retalions of these types * @return - set of relations */ public static final Set<ONDEXRelation> getIncomingRelations(ONDEXGraph graph, ONDEXConcept c, RelationType... exclude) { Set<ONDEXRelation> it = graph.getRelationsOfConcept(c); Set<RelationType> toExclude = new HashSet<RelationType>(Arrays.asList(exclude)); Set<ONDEXRelation> result = new HashSet<ONDEXRelation>(); for (ONDEXRelation r : it) { if (r.getToConcept().equals(c) && !toExclude.contains(r.getOfType())) result.add(r); } return result; }
public static Set<ONDEXConcept> getOtherNodesIncoming(ONDEXGraph graph, ONDEXConcept c, RelationType... types) { Set<RelationType> restriction = new HashSet<RelationType>(); boolean performCheck = false; if (types != null && types.length > 0) { performCheck = true; restriction.addAll(Arrays.asList(types)); } Set<ONDEXConcept> result = new HashSet<ONDEXConcept>(); for (ONDEXRelation r : graph.getRelationsOfConcept(c)) { if (!r.getToConcept().equals(c)) { continue; } if (!performCheck || restriction.contains(r.getOfType())) { result.add(getOtherNode(c, r)); } } return result; }
/** * For a given relation returns the target concept, observes the reverse * logic flag. * * @param r * ONDEXRelation * @return target concept */ private ONDEXConcept getTarget(ONDEXRelation r) { String relationType = r.getOfType().getFullname(); if (relationType == null) relationType = r.getOfType().getId(); if (relationTypeReverseLogic.contains(relationType)) { return r.getFromConcept(); } return r.getToConcept(); }
public boolean isValidRelationAtDepth(ONDEXRelation relation, int currentPosition, ONDEXConcept conceptAtHead) { ONDEXConcept toConcept = relation.getToConcept(); if (toConcept.equals(conceptAtHead)) { toConcept = relation.getFromConcept(); } if (!isValidConceptAtDepth(toConcept, currentPosition)) return false; if (validRelationTypeAtDepth != null) { ArrayList<RelationType> list = validRelationTypeAtDepth.get(currentPosition); if (list != null) { if (list.contains(relation.getOfType())) return true; } else { return isInclusivePresumption; } } return false; }
/** * For a given concept returns all connecting source concepts, usually the * reactions. * * @param c * ONDEXConcept * @return connecting source concepts */ private Set<ONDEXConcept> getSources(ONDEXConcept c) { Set<ONDEXConcept> output = new HashSet<ONDEXConcept>(); for (ONDEXRelation r : graph.getRelationsOfConcept(c)) { if (!proc_subset || sourceRelations.contains(r)) { String relationType = r.getOfType().getFullname(); if (relationType == null) relationType = r.getOfType().getId(); if (!relationTypeToRegArc.contains(relationType) && !relationTypeToAnnotation.contains(relationType) && !getSource(r).equals(c)) { output.add(getSource(r)); } } } return output; }
/** * Which concepts are taking part in modifier relations for a given concept. * * @param c * ONDEXConcept with relations * @return modifier concepts */ private Set<ONDEXConcept> getModifiers(ONDEXConcept c) { Set<ONDEXConcept> output = new HashSet<ONDEXConcept>(); for (ONDEXRelation r : graph.getRelationsOfConcept(c)) { if (!proc_subset || sourceRelations.contains(r)) { String relationType = r.getOfType().getFullname(); if (relationType == null) relationType = r.getOfType().getId(); if (relationTypeToRegArc.contains(relationType) && !getSource(r).equals(c)) { output.add(getSource(r)); } } } return output; }
/** * For a given relation returns the source concept, observes the reverse * logic flag. * * @param r * ONDEXRelation * @return source concept */ private ONDEXConcept getSource(ONDEXRelation r) { String relationType = r.getOfType().getFullname(); if (relationType == null) relationType = r.getOfType().getId(); if (relationTypeReverseLogic.contains(relationType)) { return r.getToConcept(); } return r.getFromConcept(); }
/** * Extracts the label from a given edge. * * @param edge * ONDEXRelation * @return String */ private String getLabel(ONDEXRelation edge) { String label; // first try fullname of rt RelationType rt = edge.getOfType(); label = rt.getFullname(); // else take id of rt if (label.trim().length() == 0) { label = rt.getId(); } label = makeMaxLength(label); return label; }
/** * returns a hashset with the protein families that are connected with the * given concept. * * @param c the concept * @return a hashset of pfams that are connected */ private HashSet<ONDEXConcept> getConnectedPfams(ONDEXConcept c) { HashSet<ONDEXConcept> set = new HashSet<ONDEXConcept>(); for (ONDEXRelation inOrOutRelation : graph.getRelationsOfConcept(c)) { if (inOrOutRelation.getOfType().equals(rts_seq2pfam)) { ONDEXConcept otherEnd = (inOrOutRelation.getFromConcept().equals(c)) ? inOrOutRelation.getToConcept() : inOrOutRelation.getFromConcept(); if (otherEnd.getOfType().equals(cc_protFam)) { set.add(otherEnd); } } } return set; }
/** * Constructor wraps a given ONDEXRelation. * * @param sid * unique id * @param aog * LuceneONDEXGraph * @param r * ONDEXRelation */ LuceneRelation(long sid, LuceneONDEXGraph aog, ONDEXRelation r) { this(sid, aog, r.getId(), r.getFromConcept(), r.getToConcept(), r .getOfType()); this.parent = r; }
@Override protected void doAction() { for (ONDEXRelation edge : entities) { ONDEXRelation r = edge; for (ONDEXRelation or : viewer.getONDEXJUNGGraph().getRelationsOfRelationType(r.getOfType())) { viewer.getONDEXJUNGGraph().setVisibility(or, false); } } }
/** * Clone relation with having a new RelationType. * * @param oldR * old ONDEXRelation * @param newRT * new RelationType to use * @return new ONDEXRelation */ public ONDEXRelation clone(ONDEXRelation oldR, RelationType newRT) { // first clone concept with new ConceptClass ONDEXRelation newR = graph.getRelation(oldR.getFromConcept(), oldR.getToConcept(), oldR.getOfType()); if (newR == null) graph.createRelation(oldR.getFromConcept(), oldR.getToConcept(), oldR.getOfType(), oldR.getEvidence()); // copies everything else copyEverythingElse(oldR, newR); return newR; }
public Model createModel(ONDEXGraph og) { Model instanceModel = ModelFactory.createDefaultModel(); for (ONDEXConcept concept : og.getConcepts()) { Resource classOfConcept = instanceModel.createResource(urlPrefixMetaData + concept.getOfType().getId()); instanceModel.createResource(urlPrefixInstances + concept.getId(), classOfConcept); } for (ONDEXRelation or : og.getRelations()) { Property propertyOfPredicate = instanceModel.createProperty(urlPrefixMetaData, or.getOfType().getId()); Resource fromConcept = instanceModel.getResource(urlPrefixInstances + or.getFromConcept().getId()); Resource toConcept = instanceModel.getResource(urlPrefixInstances + or.getToConcept().getId()); instanceModel.createStatement(toConcept, propertyOfPredicate, fromConcept); } return instanceModel; }