use of net.sourceforge.ondex.core.ONDEXConcept in project knetbuilder by Rothamsted.
the class GraphElementManipulation method changeAttributeValue.
public static void changeAttributeValue(ONDEXEntity e, AttributeName n, Object value) {
if (e instanceof ONDEXConcept) {
ONDEXConcept c = (ONDEXConcept) e;
boolean doIndex = c.getAttribute(n).isDoIndex();
c.deleteAttribute(n);
c.createAttribute(n, value, doIndex);
}
if (e instanceof ONDEXRelation) {
ONDEXRelation r = (ONDEXRelation) e;
boolean doIndex = r.getAttribute(n).isDoIndex();
r.deleteAttribute(n);
r.createAttribute(n, value, doIndex);
} else {
throw new IllegalArgumentException("This method only works with Ondex concepts and relations.");
}
}
use of net.sourceforge.ondex.core.ONDEXConcept in project knetbuilder by Rothamsted.
the class GraphElementManipulation method copyConcept.
/**
* Creates a copy of a concept and provides an opportunity to select a new
* concept class and new DataSource.
*
* @param graph
* - graph
* @param c
* - original concept that will be copied
* @param newCC
* - new concept class that the copy will have
* @param newDataSource
* - new DataSource that the copy will have
* @return concept that was created
*/
public static ONDEXConcept copyConcept(ONDEXGraph graph, ONDEXConcept c, ConceptClass newCC, DataSource newDataSource) {
EvidenceType der = ControledVocabularyHelper.createEvidence(graph, "Derived_copy");
ONDEXConcept nc = graph.getFactory().createConcept(c.getPID(), newDataSource, newCC, der);
copyConceptData(graph, c, nc);
nc.removeEvidenceType(der);
return nc;
}
use of net.sourceforge.ondex.core.ONDEXConcept in project knetbuilder by Rothamsted.
the class GraphElementManipulation method oneToManyCollapse.
/**
* Creates a one-to-many collapsed concept by creating collapsed concept of
* a source to all targets. Source concept is NOT deleted by this method.
*
* @param graph
* @param source
* @param targets
*/
public static final Set<ONDEXConcept> oneToManyCollapse(ONDEXGraph graph, ONDEXConcept source, Collection<ONDEXConcept> targets) {
boolean createNewTarget = false;
Set<ONDEXConcept> result = new HashSet<ONDEXConcept>();
System.err.println("Targets number:" + targets.size());
for (ONDEXConcept target : targets) {
System.err.println(target.getOfType());
ConceptClass newClass = target.getOfType();
Set<ConceptClass> set = new HashSet<ConceptClass>();
set.add(newClass);
set.add(source.getOfType());
if (set.size() > 1) {
createNewTarget = true;
newClass = getCompoundConceptClass(graph, set);
}
DataSource newDataSource = target.getElementOf();
Set<DataSource> allDataSources = new HashSet<DataSource>();
allDataSources.add(newDataSource);
allDataSources.add(source.getElementOf());
if (allDataSources.size() > 1) {
createNewTarget = true;
newDataSource = getCompoundDataSource(graph, allDataSources);
}
ONDEXConcept realTarget = target;
if (createNewTarget) {
realTarget = copyConcept(graph, target, newClass, newDataSource);
copyRelations(graph, target, realTarget);
graph.deleteConcept(target.getId());
}
copyConceptData(graph, source, realTarget);
copyRelations(graph, source, realTarget);
result.add(realTarget);
}
return result;
}
use of net.sourceforge.ondex.core.ONDEXConcept in project knetbuilder by Rothamsted.
the class GraphElementManipulation method conceptToCluster.
/**
* Swaps hub concept for a cluster where every concept is connected to every
* other concept by relation of specified type set. Use only with
* non-directional relation types
*
* @param c
* - hub concept
* @param clusterRel
* - relation type set to use in the cluster
* @param graph
* - graph
* @param rtss
* - relation type set() that define the cluster
* @throws AccessDeniedException
* @throws NullValueException
*/
public static void conceptToCluster(ONDEXConcept c, RelationType clusterRel, ONDEXGraph graph, RelationType... rtss) throws NullValueException, AccessDeniedException {
Set<RelationType> ts = new HashSet<RelationType>(Arrays.asList(rtss));
List<ONDEXConcept> cluster = new ArrayList<ONDEXConcept>();
for (ONDEXRelation r : graph.getRelationsOfConcept(c)) {
if (ts.contains(r.getOfType())) {
if (c.equals(r.getFromConcept()) && c.equals(r.getToConcept()))
continue;
if (c.equals(r.getFromConcept()))
cluster.add(r.getToConcept());
else if (c.equals(r.getToConcept()))
cluster.add(r.getFromConcept());
}
}
Collection<EvidenceType> evidence = new ArrayList<EvidenceType>();
for (EvidenceType et : c.getEvidence()) evidence.add(et);
for (int i = 0; i < cluster.size(); i++) {
for (int j = i + 1; j < cluster.size(); j++) {
graph.createRelation(cluster.get(i), cluster.get(j), clusterRel, evidence);
}
}
graph.deleteConcept(c.getId());
}
use of net.sourceforge.ondex.core.ONDEXConcept in project knetbuilder by Rothamsted.
the class GraphElementManipulation method conceptToAttribute.
/**
* Makes concept into an attribute with the value of concept name on all of
* the concepts connected to it via relations of specified type set. Use
* only with non-directional relation types.
*
* @param c
* - defining concept
* @param attName
* - name to use for the attribute
* @param graph
* - graph
* @param rtss
* - valid set of relation type sets
* @throws EmptyStringException
* @throws NullValueException
*/
public static void conceptToAttribute(ONDEXConcept c, String attName, ONDEXGraph graph, RelationType... rtss) throws NullValueException, EmptyStringException {
ONDEXGraphMetaData data = graph.getMetaData();
AttributeName an = data.getAttributeName(attName);
if (an == null)
an = data.getFactory().createAttributeName(attName, String.class);
Set<RelationType> ts = new HashSet<RelationType>(Arrays.asList(rtss));
List<ONDEXConcept> cluster = new ArrayList<ONDEXConcept>();
for (ONDEXRelation r : graph.getRelationsOfConcept(c)) {
if (ts.contains(r.getOfType())) {
if (c.equals(r.getFromConcept()) && c.equals(r.getToConcept()))
continue;
if (c.equals(r.getFromConcept()))
cluster.add(r.getToConcept());
else if (c.equals(r.getToConcept()))
cluster.add(r.getFromConcept());
}
}
String value = c.getConceptName().getName();
for (ONDEXConcept d : cluster) {
d.createAttribute(an, value, false);
}
graph.deleteConcept(c.getId());
}
Aggregations