Search in sources :

Example 1 with ConceptClass

use of net.sourceforge.ondex.core.ConceptClass 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 2 with ConceptClass

use of net.sourceforge.ondex.core.ConceptClass in project knetbuilder by Rothamsted.

the class GraphElementManipulation method getCompoundConceptClass.

/**
 * @param graph
 *            - graph
 * @param ids
 *            - concept classes to compound
 * @return - new concept class
 * @author hindlem
 *         <p/>
 *         The method for creation of compound concept classes used during
 *         the collapsing of entities
 */
public static ConceptClass getCompoundConceptClass(ONDEXGraph graph, Collection<ConceptClass> ids) {
    final TreeSet<String> sortedConceptClassConcat = new TreeSet<String>();
    ConceptClass newCc = null;
    for (ConceptClass id : ids) {
        String[] compoundIds = id.getId().split(":");
        if (compoundIds.length > 1) {
            Collections.addAll(sortedConceptClassConcat, compoundIds);
        } else {
            sortedConceptClassConcat.add(id.getId());
        }
    }
    if (sortedConceptClassConcat.size() == 0)
        throw new RuntimeException("The set supplied must not be empty");
    if (sortedConceptClassConcat.size() > 1) {
        StringBuilder newCCName = new StringBuilder();
        Iterator<String> ccit = sortedConceptClassConcat.iterator();
        boolean first = true;
        while (ccit.hasNext()) {
            String ccName = ccit.next();
            if (!first)
                newCCName.append(':');
            newCCName.append(ccName);
            first = false;
        }
        String ccName = newCCName.toString();
        newCc = graph.getMetaData().getConceptClass(ccName);
        if (newCc == null) {
            newCc = graph.getMetaData().getFactory().createConceptClass(ccName, ccName, "Collapsed Concept Class Set");
        }
    } else {
        String ccName = sortedConceptClassConcat.iterator().next();
        newCc = graph.getMetaData().getConceptClass(ccName);
        if (newCc == null) {
            newCc = graph.getMetaData().getFactory().createConceptClass(ccName, ccName, "Collapsed Concept Class Set");
        }
    }
    return newCc;
}
Also used : ConceptClass(net.sourceforge.ondex.core.ConceptClass) TreeSet(java.util.TreeSet)

Example 3 with ConceptClass

use of net.sourceforge.ondex.core.ConceptClass in project knetbuilder by Rothamsted.

the class ViewConstruction method getRelationsOfConceptClasses.

/**
 * Constructs the view containing all relations associated with particular
 * concept class, using the string ids to define the class
 * @param graph - graph to operate on
 * determine which relation  to include in the view.
 *
 * @return - resulting view
 */
public static Set<ONDEXRelation> getRelationsOfConceptClasses(ONDEXGraph graph, List<String> ccs) {
    Set<ONDEXRelation> result = BitSetFunctions.create(graph, ONDEXRelation.class, new BitSet());
    ONDEXGraphMetaData meta = graph.getMetaData();
    for (String cc : ccs) {
        ConceptClass ct = meta.getConceptClass(cc);
        if (ct != null) {
            result.addAll(graph.getRelationsOfConceptClass(ct));
        }
    }
    return result;
}
Also used : ConceptClass(net.sourceforge.ondex.core.ConceptClass) BitSet(java.util.BitSet) ONDEXRelation(net.sourceforge.ondex.core.ONDEXRelation) ONDEXGraphMetaData(net.sourceforge.ondex.core.ONDEXGraphMetaData)

Example 4 with ConceptClass

use of net.sourceforge.ondex.core.ConceptClass in project knetbuilder by Rothamsted.

the class ViewConstruction method getConceptsOfTypes.

/**
 * Return all of the concept of concept classes with provided ids in the graph
 * @param graph - Ondex graph
 * @param strIds - id of concept classes
 *
 * @return view
 */
public static final Set<ONDEXConcept> getConceptsOfTypes(ONDEXGraph graph, Collection<String> strIds) {
    Set<ONDEXConcept> result = BitSetFunctions.create(graph, ONDEXConcept.class, new BitSet());
    ConceptClass[] ccs = ControledVocabularyHelper.convertConceptClasses(graph, strIds);
    for (ConceptClass cc : ccs) {
        result.addAll(graph.getConceptsOfConceptClass(cc));
    }
    return result;
}
Also used : ConceptClass(net.sourceforge.ondex.core.ConceptClass) ONDEXConcept(net.sourceforge.ondex.core.ONDEXConcept) BitSet(java.util.BitSet)

Example 5 with ConceptClass

use of net.sourceforge.ondex.core.ConceptClass in project knetbuilder by Rothamsted.

the class MdHelper method createCC.

/**
 * Get concpet class
 *
 * @param graph
 * @param type
 * @return
 */
public static ConceptClass createCC(final ONDEXGraph graph, final String type) {
    final ONDEXGraphMetaData meta = graph.getMetaData();
    ConceptClass cc = meta.getConceptClass(type);
    if (cc == null)
        cc = meta.getFactory().createConceptClass(type);
    return cc;
}
Also used : ConceptClass(net.sourceforge.ondex.core.ConceptClass) ONDEXGraphMetaData(net.sourceforge.ondex.core.ONDEXGraphMetaData)

Aggregations

ConceptClass (net.sourceforge.ondex.core.ConceptClass)304 ONDEXConcept (net.sourceforge.ondex.core.ONDEXConcept)236 DataSource (net.sourceforge.ondex.core.DataSource)147 HashSet (java.util.HashSet)114 RelationType (net.sourceforge.ondex.core.RelationType)114 ONDEXRelation (net.sourceforge.ondex.core.ONDEXRelation)107 EvidenceType (net.sourceforge.ondex.core.EvidenceType)102 AttributeName (net.sourceforge.ondex.core.AttributeName)90 HashMap (java.util.HashMap)74 File (java.io.File)48 GeneralOutputEvent (net.sourceforge.ondex.event.type.GeneralOutputEvent)47 ArrayList (java.util.ArrayList)46 ONDEXGraph (net.sourceforge.ondex.core.ONDEXGraph)43 Attribute (net.sourceforge.ondex.core.Attribute)41 ONDEXGraphMetaData (net.sourceforge.ondex.core.ONDEXGraphMetaData)41 Set (java.util.Set)39 ConceptAccession (net.sourceforge.ondex.core.ConceptAccession)36 BufferedReader (java.io.BufferedReader)35 List (java.util.List)34 Test (org.junit.Test)31