Search in sources :

Example 1 with EvidenceType

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

the class ControledVocabularyHelper method createEvidence.

/**
 * Get evidence type
 *
 * @param graph
 * @param type
 * @return
 */
public static EvidenceType createEvidence(final ONDEXGraph graph, final String type) {
    final ONDEXGraphMetaData meta = graph.getMetaData();
    EvidenceType evidence = meta.getEvidenceType(type);
    if (evidence == null)
        evidence = meta.getFactory().createEvidenceType(type);
    return evidence;
}
Also used : EvidenceType(net.sourceforge.ondex.core.EvidenceType) ONDEXGraphMetaData(net.sourceforge.ondex.core.ONDEXGraphMetaData)

Example 2 with EvidenceType

use of net.sourceforge.ondex.core.EvidenceType 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 EvidenceType

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

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

the class ONDEXGraphCloner method cloneConcept.

/**
 * Clones a concept from the original graph to the new graph
 *
 * @param conceptToClone
 *            the concept to clone in the original graph
 * @return the new Concept
 */
public ONDEXConcept cloneConcept(ONDEXConcept conceptToClone) {
    if (!metaDataHasBeenCloned) {
        cloneMetaData();
    }
    if (old2newConceptIds.containsKey(conceptToClone.getId())) {
        // " already cloned returning previously cloned concept");
        return newGraph.getConcept(old2newConceptIds.get(conceptToClone.getId()));
    }
    ONDEXGraphMetaData nomd = newGraph.getMetaData();
    String pid = conceptToClone.getPID();
    String desc = conceptToClone.getDescription();
    String anno = conceptToClone.getAnnotation();
    ArrayList<EvidenceType> ets = new ArrayList<EvidenceType>();
    for (EvidenceType evidence : conceptToClone.getEvidence()) {
        ets.add(nomd.getEvidenceType(evidence.getId()));
    }
    DataSource dataSource = conceptToClone.getElementOf();
    DataSource newDataSource = nomd.getDataSource(dataSource.getId());
    ConceptClass cc = conceptToClone.getOfType();
    ConceptClass newCC = nomd.getConceptClass(cc.getId());
    ONDEXConcept newConcept = newGraph.createConcept(pid, anno, desc, newDataSource, newCC, ets);
    // required to prevent StackOverflow when adding itself as tag
    old2newConceptIds.put(conceptToClone.getId(), newConcept.getId());
    for (ONDEXConcept tag : conceptToClone.getTags()) {
        ONDEXConcept newTag;
        if (old2newConceptIds.containsKey(tag.getId())) {
            // check if
            // tag
            // concept
            // exists
            int cid = old2newConceptIds.get(tag.getId());
            newTag = newGraph.getConcept(cid);
        } else {
            // recursive
            newTag = cloneConcept(tag);
        }
        newConcept.addTag(newTag);
    }
    for (Attribute attribute : conceptToClone.getAttributes()) {
        AttributeName att = attribute.getOfType();
        AttributeName newAtt = nomd.getAttributeName(att.getId());
        newConcept.createAttribute(newAtt, attribute.getValue(), attribute.isDoIndex());
    }
    for (ConceptName name : conceptToClone.getConceptNames()) {
        newConcept.createConceptName(name.getName(), name.isPreferred());
    }
    for (ConceptAccession acc : conceptToClone.getConceptAccessions()) {
        dataSource = acc.getElementOf();
        newDataSource = nomd.getDataSource(dataSource.getId());
        newConcept.createConceptAccession(acc.getAccession(), newDataSource, acc.isAmbiguous());
    }
    return newConcept;
}
Also used : EvidenceType(net.sourceforge.ondex.core.EvidenceType) ConceptClass(net.sourceforge.ondex.core.ConceptClass) Attribute(net.sourceforge.ondex.core.Attribute) ArrayList(java.util.ArrayList) ConceptAccession(net.sourceforge.ondex.core.ConceptAccession) ONDEXGraphMetaData(net.sourceforge.ondex.core.ONDEXGraphMetaData) DataSource(net.sourceforge.ondex.core.DataSource) ONDEXConcept(net.sourceforge.ondex.core.ONDEXConcept) ConceptName(net.sourceforge.ondex.core.ConceptName) AttributeName(net.sourceforge.ondex.core.AttributeName)

Example 5 with EvidenceType

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

the class DefaultHandler method addPublicationXref.

/**
 * For publications create a separate concept and relationship.
 *
 * @param c
 *            ONDEXConcept with publication
 * @param pub
 *            publicationXref used
 * @throws Exception
 */
private void addPublicationXref(ONDEXConcept c, publicationXref pub) throws Exception {
    // publication gets default data source
    DataSource elementOf = graph.getMetaData().getDataSource(Parser.cvToUse);
    if (elementOf == null)
        throw new DataSourceMissingException(Parser.cvToUse + " is missing.");
    // reused for relation
    EvidenceType evidence = graph.getMetaData().getEvidenceType(etIMPD);
    if (evidence == null)
        throw new EvidenceTypeMissingException(etIMPD + " is missing.");
    // get corresponding concept
    String rdfid = pub.getUri();
    if (!rdf2Concept.containsKey(rdfid)) {
        // create publication concept
        ConceptClass ofType = graph.getMetaData().getConceptClass(ccPublication);
        if (ofType == null)
            throw new ConceptClassMissingException(ccPublication + " is missing.");
        // add concept to global map
        ONDEXConcept pubC = graph.getFactory().createConcept(rdfid, elementOf, ofType, evidence);
        rdf2Concept.put(rdfid, pubC);
        // PubMed id is non-ambiguous for a publication
        if (pub.getID() != null)
            pubC.createConceptAccession(pub.getID(), elementOf, false);
        // add year of publication
        if (pub.getYEAR() > 0) {
            AttributeName yearAN = graph.getMetaData().getAttributeName(anYEAR);
            if (yearAN == null)
                throw new AttributeNameMissingException(anYEAR + " is missing.");
            pubC.createAttribute(yearAN, pub.getYEAR(), false);
        }
        // add journal reference
        AttributeName journalAN = graph.getMetaData().getAttributeName(anJOURNAL);
        if (journalAN == null)
            throw new AttributeNameMissingException(anJOURNAL + " is missing.");
        StringBuffer source = new StringBuffer();
        for (String s : pub.getSOURCE()) {
            source.append(s);
            source.append("\n");
        }
        if (source.length() > 0) {
            pubC.createAttribute(journalAN, source.toString(), true);
            pubC.createConceptName(source.toString(), true);
        }
        // add title of publication
        if (pub.getTITLE() != null) {
            AttributeName titleAN = graph.getMetaData().getAttributeName(anTITLE);
            if (titleAN == null)
                throw new AttributeNameMissingException(anTITLE + " is missing.");
            pubC.createAttribute(titleAN, pub.getTITLE(), true);
            pubC.createConceptName(pub.getTITLE(), false);
        }
        // add authors as list
        AttributeName authorsAN = graph.getMetaData().getAttributeName(anAUTHORS);
        if (authorsAN == null)
            throw new AttributeNameMissingException(anAUTHORS + " is missing.");
        StringBuffer authors = new StringBuffer();
        for (String s : pub.getAUTHORS()) {
            authors.append(s);
            authors.append("; ");
        }
        if (authors.length() > 0)
            pubC.createAttribute(authorsAN, authors.toString(), true);
        // add possible URL of publication, only first one
        if (pub.getURL() != null) {
            AttributeName urlAN = graph.getMetaData().getAttributeName(anURL);
            if (urlAN == null)
                throw new AttributeNameMissingException(anURL + " is missing.");
            Iterator<String> it = pub.getURL().iterator();
            if (it.hasNext())
                pubC.createAttribute(urlAN, it.next(), false);
        }
    }
    // create relation between concept and publication
    RelationType ofType = graph.getMetaData().getRelationType(rtPublishedIn);
    ONDEXConcept pubC = rdf2Concept.get(rdfid);
    graph.getFactory().createRelation(c, pubC, ofType, evidence);
}
Also used : EvidenceType(net.sourceforge.ondex.core.EvidenceType) ConceptClass(net.sourceforge.ondex.core.ConceptClass) EvidenceTypeMissingException(net.sourceforge.ondex.exception.type.EvidenceTypeMissingException) AttributeNameMissingException(net.sourceforge.ondex.exception.type.AttributeNameMissingException) DataSourceMissingException(net.sourceforge.ondex.exception.type.DataSourceMissingException) ConceptClassMissingException(net.sourceforge.ondex.exception.type.ConceptClassMissingException) DataSource(net.sourceforge.ondex.core.DataSource) ONDEXConcept(net.sourceforge.ondex.core.ONDEXConcept) RelationType(net.sourceforge.ondex.core.RelationType) AttributeName(net.sourceforge.ondex.core.AttributeName)

Aggregations

EvidenceType (net.sourceforge.ondex.core.EvidenceType)175 ONDEXConcept (net.sourceforge.ondex.core.ONDEXConcept)142 ConceptClass (net.sourceforge.ondex.core.ConceptClass)103 DataSource (net.sourceforge.ondex.core.DataSource)97 RelationType (net.sourceforge.ondex.core.RelationType)87 AttributeName (net.sourceforge.ondex.core.AttributeName)68 ONDEXRelation (net.sourceforge.ondex.core.ONDEXRelation)68 HashSet (java.util.HashSet)51 Attribute (net.sourceforge.ondex.core.Attribute)43 HashMap (java.util.HashMap)41 File (java.io.File)40 BufferedReader (java.io.BufferedReader)34 ArrayList (java.util.ArrayList)32 IOException (java.io.IOException)22 FileReader (java.io.FileReader)21 ONDEXGraph (net.sourceforge.ondex.core.ONDEXGraph)20 GeneralOutputEvent (net.sourceforge.ondex.event.type.GeneralOutputEvent)19 Test (org.junit.Test)19 FileNotFoundException (java.io.FileNotFoundException)17 MemoryONDEXGraph (net.sourceforge.ondex.core.memory.MemoryONDEXGraph)17