Search in sources :

Example 1 with Branch

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

the class Txt method out.

static void out(QueryType type, PrintStream ps, Map<EdamUri, Concept> concepts, List<Query> queries, List<MappingTest> mappings) throws IOException {
    ps.print("query_id");
    ps.print(SEP);
    ps.print("query_name");
    ps.print(SEP);
    ps.print("edam_branch");
    ps.print(SEP);
    ps.print("edam_uri");
    ps.print(SEP);
    ps.print("edam_label");
    ps.print(SEP);
    ps.print("edam_obsolete");
    ps.print(SEP);
    ps.print("best_one_query");
    ps.print(SEP);
    ps.print("best_one_edam");
    ps.print(SEP);
    ps.print("best_one_score");
    ps.print(SEP);
    ps.print("without_path_score");
    ps.print(SEP);
    ps.print("score");
    ps.print(SEP);
    ps.print("test");
    ps.println();
    for (int i = 0; i < queries.size(); ++i) {
        Query query = queries.get(i);
        MappingTest mapping = mappings.get(i);
        for (Branch branch : Branch.values()) {
            for (MatchTest matchTest : mapping.getMatches(branch)) {
                Match match = matchTest.getMatch();
                Concept concept = concepts.get(match.getEdamUri());
                ps.print(query.getId() != null ? query.getId() : "");
                ps.print(SEP);
                ps.print(query.getName() != null ? query.getName() : "");
                ps.print(SEP);
                ps.print(branch);
                ps.print(SEP);
                ps.print(match.getEdamUri());
                ps.print(SEP);
                ps.print(concept.getLabel());
                ps.print(SEP);
                ps.print(concept.isObsolete());
                ps.print(SEP);
                ps.print(match.getQueryMatch().getType().name());
                ps.print(SEP);
                ps.print(match.getConceptMatch().getType().name());
                ps.print(SEP);
                ps.print(match.getBestOneScore() > -1 ? match.getBestOneScore() : "");
                ps.print(SEP);
                ps.print(match.getWithoutPathScore() > -1 ? match.getWithoutPathScore() : "");
                ps.print(SEP);
                ps.print(match.getScore());
                ps.print(SEP);
                ps.print(matchTest.getTest().name());
                ps.println();
            }
        }
    }
}
Also used : Concept(org.edamontology.edammap.core.edam.Concept) Query(org.edamontology.edammap.core.query.Query) Branch(org.edamontology.edammap.core.edam.Branch) MappingTest(org.edamontology.edammap.core.benchmarking.MappingTest) MatchTest(org.edamontology.edammap.core.benchmarking.MatchTest) Match(org.edamontology.edammap.core.mapping.Match)

Example 2 with Branch

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

the class Benchmark method calculate.

public static Results calculate(List<Query> queries, List<Mapping> mappings) {
    Results results = new Results();
    Map<Branch, Long> size = new EnumMap<>(Branch.class);
    for (Branch branch : Branch.values()) {
        size.put(branch, 0l);
    }
    for (int i = 0; i < queries.size(); ++i) {
        MappingTest mappingTest = new MappingTest();
        Query query = queries.get(i);
        Mapping mapping = mappings.get(i);
        for (Branch branch : mapping.getBranches()) {
            long annotationsSize;
            if (query.getAnnotations() != null) {
                annotationsSize = query.getAnnotations().stream().filter(e -> e.getBranch() == branch).count();
            } else {
                annotationsSize = 0;
            }
            if (annotationsSize > 0) {
                size.put(branch, size.get(branch) + 1);
            }
            int tp = 0, fp = 0, fn = 0;
            double DCG = 0, IDCG = 0, DCGa = 0, IDCGa = 0;
            for (int j = 0; j < mapping.getMatches(branch).size(); ++j) {
                Match match = mapping.getMatches(branch).get(j);
                if (match.isExistingAnnotation()) {
                    mappingTest.matches.get(branch).add(new MatchTest(match, Test.tp));
                    ++tp;
                    double precisionAve = tp / (double) (tp + fp);
                    results.measures.get(branch).addMeasure(Measure.AveP, precisionAve / (double) annotationsSize);
                    if (j < annotationsSize) {
                        results.measures.get(branch).addMeasure(Measure.RP, 1 / (double) annotationsSize);
                    }
                    int rel = 1;
                    if (j == 0) {
                        DCG += rel;
                    } else {
                        DCG += rel / (Math.log(j + 1) / Math.log(2));
                    }
                    DCGa += (Math.pow(2, rel) - 1) / (Math.log(j + 1 + 1) / Math.log(2));
                } else {
                    mappingTest.matches.get(branch).add(new MatchTest(match, Test.fp));
                    ++fp;
                }
                if (annotationsSize > 0) {
                    int Mrel = ((annotationsSize - j <= 0) ? 0 : 1);
                    if (j == 0) {
                        IDCG += Mrel;
                    } else {
                        IDCG += Mrel / (Math.log(j + 1) / Math.log(2));
                    }
                    IDCGa += (Math.pow(2, Mrel) - 1) / (Math.log(j + 1 + 1) / Math.log(2));
                }
            }
            for (Match excludedAnnotation : mapping.getRemainingAnnotations(branch)) {
                mappingTest.matches.get(branch).add(new MatchTest(excludedAnnotation, Test.fn));
                ++fn;
            }
            results.measuresTotal.addTest(Test.tp, tp);
            results.measuresTotal.addTest(Test.fp, fp);
            results.measuresTotal.addTest(Test.fn, fn);
            results.measures.get(branch).addTest(Test.tp, tp);
            results.measures.get(branch).addTest(Test.fp, fp);
            results.measures.get(branch).addTest(Test.fn, fn);
            if (annotationsSize > 0) {
                double precision = 0;
                if (tp > 0 || fp > 0)
                    precision = tp / (double) (tp + fp);
                double recall = tp / (double) (tp + fn);
                results.measures.get(branch).addMeasure(Measure.precision, precision);
                results.measures.get(branch).addMeasure(Measure.recall, recall);
                if (tp > 0) {
                    results.measures.get(branch).addMeasure(Measure.f1, 2 * (precision * recall) / (precision + recall));
                    results.measures.get(branch).addMeasure(Measure.f2, (1 + Math.pow(2, 2)) * (precision * recall) / ((Math.pow(2, 2) * precision) + recall));
                }
                results.measures.get(branch).addMeasure(Measure.Jaccard, tp / (double) (tp + fp + fn));
                if (tp > 0 || fp > 0) {
                    results.measures.get(branch).addMeasure(Measure.DCG, DCG / IDCG);
                    results.measures.get(branch).addMeasure(Measure.DCGa, DCGa / IDCGa);
                }
            }
        }
        results.mappings.add(mappingTest);
    }
    for (Branch branch : Branch.values()) {
        long s = size.get(branch);
        if (s == 0)
            continue;
        for (Measure measure : Measure.values()) {
            results.measures.get(branch).divideMeasure(measure, s);
        }
    }
    int branchesSize = 0;
    for (Branch branch : Branch.values()) {
        if (size.get(branch) == 0)
            continue;
        ++branchesSize;
        for (Measure measure : Measure.values()) {
            results.measuresTotal.addMeasure(measure, results.measures.get(branch).getMeasure(measure));
        }
    }
    if (branchesSize > 0) {
        for (Measure measure : Measure.values()) {
            results.measuresTotal.divideMeasure(measure, branchesSize);
        }
    }
    return results;
}
Also used : Query(org.edamontology.edammap.core.query.Query) Mapping(org.edamontology.edammap.core.mapping.Mapping) Match(org.edamontology.edammap.core.mapping.Match) Branch(org.edamontology.edammap.core.edam.Branch) EnumMap(java.util.EnumMap)

Example 3 with Branch

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

the class Results method toStringTest.

public String toStringTest(Test test) {
    StringBuilder sb = new StringBuilder();
    sb.append("[");
    List<String> tests = new ArrayList<>();
    for (Branch branch : Branch.values()) {
        tests.add(Integer.toString(this.measures.get(branch).getTest(test)));
    }
    sb.append(String.join(", ", tests));
    sb.append("] (");
    sb.append(Integer.toString(measuresTotal.getTest(test)));
    sb.append(")");
    return sb.toString();
}
Also used : Branch(org.edamontology.edammap.core.edam.Branch) ArrayList(java.util.ArrayList)

Example 4 with Branch

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

the class Results method toStringMeasure.

public String toStringMeasure(Measure measure) {
    StringBuilder sb = new StringBuilder();
    sb.append("[");
    List<String> measures = new ArrayList<>();
    for (Branch branch : Branch.values()) {
        measures.add(percent(this.measures.get(branch).getMeasure(measure)));
    }
    sb.append(String.join(", ", measures));
    sb.append("] (");
    sb.append(percent(measuresTotal.getMeasure(measure)));
    sb.append(")");
    return sb.toString();
}
Also used : Branch(org.edamontology.edammap.core.edam.Branch) ArrayList(java.util.ArrayList)

Example 5 with Branch

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

the class Report method writeMatches.

private static void writeMatches(ScoreArgs scoreArgs, Writer writer, Map<EdamUri, Concept> concepts, Query query, List<Publication> publications, MappingTest mapping) throws IOException {
    for (Branch branch : Branch.values()) {
        List<MatchTest> matches = mapping.getMatches(branch);
        if (matches.isEmpty())
            continue;
        writer.write("\t\t<div class=\"branch " + branch + "\">\n");
        writer.write("\t\t\t<h3>" + branch + "</h3>\n");
        for (MatchTest matchTest : matches) {
            Match match = matchTest.getMatch();
            writer.write("\t\t\t<div class=\"match " + matchTest.getTest().name() + "\">\n");
            writer.write("\t\t\t\t<div class=\"match-div\">\n");
            writeConcept(writer, concepts, match);
            writeQueryMatch(writer, query, publications, match.getQueryMatch(), true);
            writer.write("\t\t\t\t\t<div class=\"type\">" + match.getConceptMatch().getType() + "</div>\n");
            writeScore(scoreArgs, writer, branch, match);
            writer.write("\t\t\t\t</div>\n");
            List<MatchAverageStats> matchAverageStats = match.getMatchAverageStats();
            if (matchAverageStats != null && !matchAverageStats.isEmpty()) {
                // TODO
                Concept concept = concepts.get(match.getEdamUri());
                writer.write("\t\t\t\t<div class=\"details-div\">\n");
                writer.write("\t\t\t\t\t<div class=\"details\" tabindex=\"0\"></div>\n");
                writer.write("\t\t\t\t\t<div class=\"details-box\" tabindex=\"0\">\n");
                for (MatchAverageStats mas : matchAverageStats) {
                    writer.write("\t\t\t\t\t\t<div><div>");
                    writeQueryMatch(writer, query, publications, mas.getQueryMatch(), false);
                    writer.write("<br>" + percent(mas.getQueryMatch().getScore()) + "</div><div>");
                    ConceptMatchType conceptType = mas.getConceptMatch().getType();
                    writer.write("<span>" + conceptType + "</span>");
                    if (conceptType != ConceptMatchType.definition && conceptType != ConceptMatchType.comment && conceptType != ConceptMatchType.none) {
                        writer.write("<br>" + conceptMatchString(concept, mas.getConceptMatch()));
                    }
                    writer.write("<br>" + percent(mas.getConceptMatch().getScore()) + "</div><div>");
                    writer.write("<span>" + percent(mas.getScore()) + "</span></div></div>\n");
                }
                writer.write("\t\t\t\t\t</div>\n");
                writer.write("\t\t\t\t</div>\n");
            }
            writer.write("\t\t\t</div>\n");
        }
        writer.write("\t\t</div>\n");
    }
}
Also used : Concept(org.edamontology.edammap.core.edam.Concept) MatchAverageStats(org.edamontology.edammap.core.mapping.MatchAverageStats) Branch(org.edamontology.edammap.core.edam.Branch) ConceptMatchType(org.edamontology.edammap.core.mapping.ConceptMatchType) MatchTest(org.edamontology.edammap.core.benchmarking.MatchTest) QueryMatch(org.edamontology.edammap.core.mapping.QueryMatch) Match(org.edamontology.edammap.core.mapping.Match) ConceptMatch(org.edamontology.edammap.core.mapping.ConceptMatch)

Aggregations

Branch (org.edamontology.edammap.core.edam.Branch)5 Match (org.edamontology.edammap.core.mapping.Match)3 ArrayList (java.util.ArrayList)2 MatchTest (org.edamontology.edammap.core.benchmarking.MatchTest)2 Concept (org.edamontology.edammap.core.edam.Concept)2 Query (org.edamontology.edammap.core.query.Query)2 EnumMap (java.util.EnumMap)1 MappingTest (org.edamontology.edammap.core.benchmarking.MappingTest)1 ConceptMatch (org.edamontology.edammap.core.mapping.ConceptMatch)1 ConceptMatchType (org.edamontology.edammap.core.mapping.ConceptMatchType)1 Mapping (org.edamontology.edammap.core.mapping.Mapping)1 MatchAverageStats (org.edamontology.edammap.core.mapping.MatchAverageStats)1 QueryMatch (org.edamontology.edammap.core.mapping.QueryMatch)1