Search in sources :

Example 1 with ONDEXConcept

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.");
    }
}
Also used : ONDEXConcept(net.sourceforge.ondex.core.ONDEXConcept) ONDEXRelation(net.sourceforge.ondex.core.ONDEXRelation)

Example 2 with ONDEXConcept

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;
}
Also used : EvidenceType(net.sourceforge.ondex.core.EvidenceType) ONDEXConcept(net.sourceforge.ondex.core.ONDEXConcept)

Example 3 with ONDEXConcept

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;
}
Also used : ConceptClass(net.sourceforge.ondex.core.ConceptClass) ONDEXConcept(net.sourceforge.ondex.core.ONDEXConcept) HashSet(java.util.HashSet) DataSource(net.sourceforge.ondex.core.DataSource)

Example 4 with ONDEXConcept

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());
}
Also used : EvidenceType(net.sourceforge.ondex.core.EvidenceType) ONDEXConcept(net.sourceforge.ondex.core.ONDEXConcept) RelationType(net.sourceforge.ondex.core.RelationType) ArrayList(java.util.ArrayList) ONDEXRelation(net.sourceforge.ondex.core.ONDEXRelation) HashSet(java.util.HashSet)

Example 5 with ONDEXConcept

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());
}
Also used : ONDEXConcept(net.sourceforge.ondex.core.ONDEXConcept) RelationType(net.sourceforge.ondex.core.RelationType) ArrayList(java.util.ArrayList) AttributeName(net.sourceforge.ondex.core.AttributeName) ONDEXRelation(net.sourceforge.ondex.core.ONDEXRelation) ONDEXGraphMetaData(net.sourceforge.ondex.core.ONDEXGraphMetaData) HashSet(java.util.HashSet)

Aggregations

ONDEXConcept (net.sourceforge.ondex.core.ONDEXConcept)937 ONDEXRelation (net.sourceforge.ondex.core.ONDEXRelation)371 ConceptClass (net.sourceforge.ondex.core.ConceptClass)243 HashSet (java.util.HashSet)242 DataSource (net.sourceforge.ondex.core.DataSource)180 AttributeName (net.sourceforge.ondex.core.AttributeName)169 RelationType (net.sourceforge.ondex.core.RelationType)147 HashMap (java.util.HashMap)142 EvidenceType (net.sourceforge.ondex.core.EvidenceType)142 Attribute (net.sourceforge.ondex.core.Attribute)122 ArrayList (java.util.ArrayList)112 Test (org.junit.Test)103 ConceptAccession (net.sourceforge.ondex.core.ConceptAccession)87 ONDEXGraph (net.sourceforge.ondex.core.ONDEXGraph)82 Set (java.util.Set)81 File (java.io.File)80 GeneralOutputEvent (net.sourceforge.ondex.event.type.GeneralOutputEvent)72 IOException (java.io.IOException)70 List (java.util.List)69 BufferedReader (java.io.BufferedReader)61