Search in sources :

Example 6 with EdamUri

use of org.edamontology.edammap.core.edam.EdamUri in project edammap by edamontology.

the class Mapper method map.

public Mapping map(Query query, QueryProcessed processedQuery, MapperArgs args) {
    Mapping mapping = new Mapping(args.getMatches(), args.getBranches());
    Map<EdamUri, Match> matches = new HashMap<>();
    for (Map.Entry<EdamUri, ConceptProcessed> conceptEntry : processedConcepts.entrySet()) {
        EdamUri edamUri = conceptEntry.getKey();
        ConceptProcessed processedConcept = conceptEntry.getValue();
        if (!args.getBranches().contains(edamUri.getBranch()))
            continue;
        if ((processedConcept.isObsolete() && !args.isObsolete()) || (processedConcept.getDirectParents().isEmpty() && !args.isTopLevel())) {
            Match zeroMatch = new Match(0, new ConceptMatch(0, ConceptMatchType.none, -1), new QueryMatch(0, QueryMatchType.none, -1, -1));
            zeroMatch.setEdamUri(edamUri);
            matches.put(edamUri, zeroMatch);
            continue;
        }
        Match match = getBestMatch(processedConcept, processedQuery, args);
        match.setEdamUri(edamUri);
        matches.put(edamUri, match);
    }
    Set<EdamUri> annotations = new LinkedHashSet<>();
    for (EdamUri annotation : query.getAnnotations()) {
        if (args.getBranches().contains(annotation.getBranch())) {
            annotations.add(annotation);
            matches.get(annotation).setExistingAnnotation(true);
        }
    }
    if (!args.isInferiorParentsChildren() && !args.isDoneAnnotations()) {
        for (EdamUri annotation : annotations) {
            removeParents(annotation, matches);
            removeChildren(annotation, matches);
            matches.get(annotation).setRemoved(true);
        }
    }
    if (args.getAlgorithmArgs().getPathWeight() > 0 && args.getAlgorithmArgs().getParentWeight() > 0) {
        for (Match match : matches.values()) {
            match.setWithoutPathScore(match.getScore());
        }
        for (Map.Entry<EdamUri, Match> matchEntry : matches.entrySet()) {
            EdamUri edamUri = matchEntry.getKey();
            Match match = matchEntry.getValue();
            if (processedConcepts.get(edamUri).getDirectParents().isEmpty() && !args.isTopLevel()) {
                match.setRemoved(true);
                continue;
            }
            if (processedConcepts.get(edamUri).isObsolete() && !args.isObsolete()) {
                continue;
            }
            double bestPathScore = 0;
            for (EdamUri parent : processedConcepts.get(edamUri).getDirectParents()) {
                double best = bestPathScore(parent, matches, 1, 0, args.getAlgorithmArgs().getParentWeight());
                if (best > bestPathScore)
                    bestPathScore = best;
            }
            match.setScore((match.getScore() + args.getAlgorithmArgs().getPathWeight() * bestPathScore) / (1 + args.getAlgorithmArgs().getPathWeight()));
        }
    }
    List<Match> sortedMatches = new ArrayList<>(matches.values());
    Collections.sort(sortedMatches, Collections.reverseOrder());
    for (Match match : sortedMatches) {
        if (mapping.isFull())
            break;
        if (mapping.isFull(match.getEdamUri().getBranch()))
            continue;
        if (match.isRemoved())
            continue;
        if (processedConcepts.get(match.getEdamUri()).isObsolete() && !args.isObsolete())
            continue;
        if (!args.isDoneAnnotations() && match.isExistingAnnotation())
            continue;
        double goodScore = 0;
        double badScore = 0;
        switch(match.getEdamUri().getBranch()) {
            case topic:
                goodScore = args.getScoreArgs().getGoodScoreTopic();
                badScore = args.getScoreArgs().getBadScoreTopic();
                break;
            case operation:
                goodScore = args.getScoreArgs().getGoodScoreOperation();
                badScore = args.getScoreArgs().getBadScoreOperation();
                break;
            case data:
                goodScore = args.getScoreArgs().getGoodScoreData();
                badScore = args.getScoreArgs().getBadScoreData();
                break;
            case format:
                goodScore = args.getScoreArgs().getGoodScoreFormat();
                badScore = args.getScoreArgs().getBadScoreFormat();
                break;
        }
        double score = 0;
        if (args.getAlgorithmArgs().getMappingStrategy() == MapperStrategy.average) {
            score = match.getBestOneScore();
        } else if (args.getAlgorithmArgs().getPathWeight() > 0 && args.getAlgorithmArgs().getParentWeight() > 0) {
            score = match.getWithoutPathScore();
        } else {
            score = match.getScore();
        }
        if (score > goodScore) {
            if (!args.getScoreArgs().isOutputGoodScores())
                continue;
        } else if (score >= badScore && score <= goodScore) {
            if (!args.getScoreArgs().isOutputMediumScores())
                continue;
        } else if (score < badScore) {
            if (!args.getScoreArgs().isOutputBadScores())
                continue;
        }
        if (!args.isInferiorParentsChildren()) {
            removeParents(match.getEdamUri(), matches);
            removeChildren(match.getEdamUri(), matches);
        }
        addParentsChildren(match, mapping, false);
        mapping.addMatch(match);
    }
    if (args.isDoneAnnotations() && annotations.size() > 0) {
        int annotationsSeen = 0;
        for (Match match : sortedMatches) {
            if (annotations.contains(match.getEdamUri())) {
                ++annotationsSeen;
                if (!mapping.getMatches(match.getEdamUri().getBranch()).contains(match)) {
                    addParentsChildren(match, mapping, true);
                    mapping.addRemainingAnnotation(match);
                }
                if (annotationsSeen >= annotations.size())
                    break;
            }
        }
    }
    return mapping;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ConceptProcessed(org.edamontology.edammap.core.processing.ConceptProcessed) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) EdamUri(org.edamontology.edammap.core.edam.EdamUri) HashMap(java.util.HashMap) Map(java.util.Map)

Example 7 with EdamUri

use of org.edamontology.edammap.core.edam.EdamUri in project edammap by edamontology.

the class Mapper method bestPathScore.

private double bestPathScore(EdamUri edamUri, Map<EdamUri, Match> matches, int level, double current, double parentWeight) {
    // matches.get(edamUri) is null if edamUri is from some other branch than its child who called us
    // should not happen if EDAM is consistent
    double score = (matches.get(edamUri) == null ? 0 : matches.get(edamUri).getWithoutPathScore());
    current += Math.pow(parentWeight, level) * score;
    List<EdamUri> parents = processedConcepts.get(edamUri).getDirectParents();
    if (parents.size() == 0) {
        double denominator = 0;
        for (int l = 1; l <= level; ++l) {
            denominator += Math.pow(parentWeight, l);
        }
        return current /= denominator;
    } else {
        double bestPathScore = 0;
        for (EdamUri parent : parents) {
            double best = bestPathScore(parent, matches, level + 1, current, parentWeight);
            if (best > bestPathScore)
                bestPathScore = best;
        }
        return bestPathScore;
    }
}
Also used : EdamUri(org.edamontology.edammap.core.edam.EdamUri)

Example 8 with EdamUri

use of org.edamontology.edammap.core.edam.EdamUri in project edammap by edamontology.

the class Mapper method removeChildren.

private void removeChildren(EdamUri edamUri, Map<EdamUri, Match> matches) {
    for (EdamUri child : processedConcepts.get(edamUri).getDirectChildren()) {
        if (matches.get(child) != null && !matches.get(child).isRemoved()) {
            matches.get(child).setRemoved(true);
            removeChildren(child, matches);
        }
    }
}
Also used : EdamUri(org.edamontology.edammap.core.edam.EdamUri)

Example 9 with EdamUri

use of org.edamontology.edammap.core.edam.EdamUri in project edammap by edamontology.

the class Mapper method removeParents.

private void removeParents(EdamUri edamUri, Map<EdamUri, Match> matches) {
    for (EdamUri parent : processedConcepts.get(edamUri).getDirectParents()) {
        if (matches.get(parent) != null && !matches.get(parent).isRemoved()) {
            matches.get(parent).setRemoved(true);
            removeParents(parent, matches);
        }
    }
}
Also used : EdamUri(org.edamontology.edammap.core.edam.EdamUri)

Example 10 with EdamUri

use of org.edamontology.edammap.core.edam.EdamUri in project edammap by edamontology.

the class QueryLoader method getSEQwiki.

private static Query getSEQwiki(SEQwiki SEQwiki, Map<EdamUri, Concept> concepts) {
    List<Keyword> keywords = new ArrayList<>();
    keywords.addAll(keywords(split(SEQwiki.getDomains(), INTERNAL_SEPARATOR_COMMA), "Domain", SEQWIKI, 0));
    keywords.addAll(keywords(split(SEQwiki.getMethods(), INTERNAL_SEPARATOR_COMMA), "Method", SEQWIKI, 0));
    List<Link> webpageUrls = new ArrayList<>();
    addLink(SEQWIKI + SEQwiki.getName().trim().replace(" ", "_"), null, false, webpageUrls);
    webpageUrls.addAll(links(split(SEQwiki.getWebpages(), INTERNAL_SEPARATOR_COMMA), null, false, 0));
    Set<EdamUri> annotations = new LinkedHashSet<>();
    for (Keyword keyword : keywords) {
        EdamUri annotation = getSEQwikiAnnotation(keyword, concepts);
        if (annotation != null)
            annotations.add(annotation);
    }
    return new Query(null, SEQwiki.getName().trim(), keywords, SEQwiki.getSummary().trim(), webpageUrls, links(split(SEQwiki.getDocs(), INTERNAL_SEPARATOR_COMMA), null, false, 0), publicationIds(split(SEQwiki.getPublications(), INTERNAL_SEPARATOR_COMMA), SEQWIKI, null, false, 0), annotations);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ArrayList(java.util.ArrayList) EdamUri(org.edamontology.edammap.core.edam.EdamUri)

Aggregations

EdamUri (org.edamontology.edammap.core.edam.EdamUri)11 ArrayList (java.util.ArrayList)4 Concept (org.edamontology.edammap.core.edam.Concept)4 LinkedHashSet (java.util.LinkedHashSet)3 Idf (org.edamontology.edammap.core.idf.Idf)3 Map (java.util.Map)2 Results (org.edamontology.edammap.core.benchmarking.Results)2 Output (org.edamontology.edammap.core.output.Output)2 PreProcessor (org.edamontology.edammap.core.preprocessing.PreProcessor)2 ConceptProcessed (org.edamontology.edammap.core.processing.ConceptProcessed)2 File (java.io.File)1 URI (java.net.URI)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 CoreArgs (org.edamontology.edammap.core.args.CoreArgs)1 IdfMake (org.edamontology.edammap.core.idf.IdfMake)1 ServerInput (org.edamontology.edammap.core.input.ServerInput)1 Function (org.edamontology.edammap.core.input.json.Function)1 InputOutput (org.edamontology.edammap.core.input.json.InputOutput)1