Search in sources :

Example 1 with HpoOboParser

use of com.github.phenomics.ontolib.io.obo.hpo.HpoOboParser in project loinc2hpo by monarch-initiative.

the class HpoOntologyParser method parseOntology.

/**
 * Parse the HP ontology file and place the data in {@link #ontology} and
 * @throws IOException
 */
public void parseOntology() throws IOException {
    HpoOboParser hpoOboParser = new HpoOboParser(new File(hpoOntologyPath));
    this.ontology = hpoOboParser.parse();
}
Also used : HpoOboParser(com.github.phenomics.ontolib.io.obo.hpo.HpoOboParser) File(java.io.File)

Example 2 with HpoOboParser

use of com.github.phenomics.ontolib.io.obo.hpo.HpoOboParser in project loinc2hpo by monarch-initiative.

the class UniversalLoinc2HPOAnnotationTest method testToString.

@Test
public void testToString() throws Exception {
    Map<String, HpoTerm> hpoTermMap;
    String hpo_obo = FhirObservationAnalyzerTest.class.getClassLoader().getResource("obo/hp.obo").getPath();
    HpoOboParser hpoOboParser = new HpoOboParser(new File(hpo_obo));
    HpoOntology hpo = null;
    try {
        hpo = hpoOboParser.parse();
    } catch (IOException e) {
        e.printStackTrace();
    }
    ImmutableMap.Builder<String, HpoTerm> termmap = new ImmutableMap.Builder<>();
    if (hpo != null) {
        List<HpoTerm> res = hpo.getTermMap().values().stream().distinct().collect(Collectors.toList());
        res.forEach(term -> termmap.put(term.getName(), term));
    }
    hpoTermMap = termmap.build();
    Map<LoincId, UniversalLoinc2HPOAnnotation> testmap = new HashMap<>();
    LoincId loincId = new LoincId("15074-8");
    LoincScale loincScale = LoincScale.string2enum("Qn");
    HpoTerm low = hpoTermMap.get("Hypoglycemia");
    HpoTerm normal = hpoTermMap.get("Abnormality of blood glucose concentration");
    HpoTerm hi = hpoTermMap.get("Hyperglycemia");
    Map<String, Code> internalCodes = CodeSystemConvertor.getCodeContainer().getCodeSystemMap().get(Loinc2HPOCodedValue.CODESYSTEM);
    UniversalLoinc2HPOAnnotation glucoseAnnotation = new UniversalLoinc2HPOAnnotation.Builder().setLoincId(loincId).setLoincScale(loincScale).setLowValueHpoTerm(low).setIntermediateValueHpoTerm(normal).setHighValueHpoTerm(hi).setIntermediateNegated(true).build();
    testmap.put(loincId, glucoseAnnotation);
    loincId = new LoincId("600-7");
    loincScale = LoincScale.string2enum("Nom");
    HpoTerm forCode1 = hpoTermMap.get("Recurrent E. coli infections");
    HpoTerm forCode2 = hpoTermMap.get("Recurrent Staphylococcus aureus infections");
    HpoTerm positive = hpoTermMap.get("Recurrent bacterial infections");
    Code code1 = Code.getNewCode().setSystem("http://snomed.info/sct").setCode("112283007");
    Code code2 = Code.getNewCode().setSystem("http://snomed.info/sct").setCode("3092008");
    UniversalLoinc2HPOAnnotation bacterialAnnotation = new UniversalLoinc2HPOAnnotation.Builder().setLoincId(loincId).setLoincScale(loincScale).addAdvancedAnnotation(code1, new HpoTermId4LoincTest(forCode1, false)).addAdvancedAnnotation(code2, new HpoTermId4LoincTest(forCode2, false)).addAdvancedAnnotation(internalCodes.get("P"), new HpoTermId4LoincTest(positive, false)).build();
    testmap.put(loincId, bacterialAnnotation);
    // testmap.entrySet().forEach(System.out::println);
    String path = temporaryFolder.newFile("testoutput.tsv").getPath();
    WriteToFile.writeToFile("", path);
    testmap.forEach((k, v) -> {
        WriteToFile.appendToFile(v.toString(), path);
        WriteToFile.appendToFile("\n", path);
    });
    // WriteToFile.appendToFile(glucoseAnnotation.toString(), path);
    BufferedReader reader = new BufferedReader(new FileReader(path));
    // System.out.println(UniversalLoinc2HPOAnnotation.getHeaderAdvanced());
    // reader.lines().forEach(System.out::println);
    String content = "15074-8\tQn\thttp://jax.org/loinc2hpo\tL\tHP:0001943\tfalse\tnull\tfalse\t0.0\tnull\tnull\tnull\tnull\n" + "15074-8\tQn\thttp://jax.org/loinc2hpo\tN\tHP:0011015\ttrue\tnull\tfalse\t0.0\tnull\tnull\tnull\tnull\n" + "15074-8\tQn\thttp://jax.org/loinc2hpo\tH\tHP:0003074\tfalse\tnull\tfalse\t0.0\tnull\tnull\tnull\tnull\n" + "15074-8\tQn\thttp://jax.org/loinc2hpo\tA\tHP:0011015\tfalse\tnull\tfalse\t0.0\tnull\tnull\tnull\tnull\n" + "600-7\tNom\thttp://snomed.info/sct\t112283007\tHP:0002740\tfalse\tnull\tfalse\t0.0\tnull\tnull\tnull\tnull\n" + "600-7\tNom\thttp://jax.org/loinc2hpo\tP\tHP:0002718\tfalse\tnull\tfalse\t0.0\tnull\tnull\tnull\tnull\n" + "600-7\tNom\thttp://snomed.info/sct\t3092008\tHP:0002726\tfalse\tnull\tfalse\t0.0\tnull\tnull\tnull\tnull";
    assertEquals(9, reader.lines().collect(Collectors.toList()).size());
}
Also used : HashMap(java.util.HashMap) HpoOboParser(com.github.phenomics.ontolib.io.obo.hpo.HpoOboParser) IOException(java.io.IOException) Code(org.monarchinitiative.loinc2hpo.codesystems.Code) ImmutableMap(com.google.common.collect.ImmutableMap) HpoTerm(com.github.phenomics.ontolib.formats.hpo.HpoTerm) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) WriteToFile(org.monarchinitiative.loinc2hpo.io.WriteToFile) File(java.io.File) HpoOntology(com.github.phenomics.ontolib.formats.hpo.HpoOntology) FhirObservationAnalyzerTest(org.monarchinitiative.loinc2hpo.fhir.FhirObservationAnalyzerTest) Test(org.junit.Test)

Example 3 with HpoOboParser

use of com.github.phenomics.ontolib.io.obo.hpo.HpoOboParser in project loinc2hpo by monarch-initiative.

the class UniversalLoinc2HPOAnnotationTest method testBuilderForBasicAnnotation.

@Test
public void testBuilderForBasicAnnotation() throws Exception {
    Map<String, HpoTerm> hpoTermMap;
    String hpo_obo = FhirObservationAnalyzerTest.class.getClassLoader().getResource("obo/hp.obo").getPath();
    HpoOboParser hpoOboParser = new HpoOboParser(new File(hpo_obo));
    HpoOntology hpo = null;
    try {
        hpo = hpoOboParser.parse();
    } catch (IOException e) {
        e.printStackTrace();
    }
    ImmutableMap.Builder<String, HpoTerm> termmap = new ImmutableMap.Builder<>();
    if (hpo != null) {
        List<HpoTerm> res = hpo.getTermMap().values().stream().distinct().collect(Collectors.toList());
        res.forEach(term -> termmap.put(term.getName(), term));
    }
    hpoTermMap = termmap.build();
    UniversalLoinc2HPOAnnotation.Builder loinc2HpoAnnotationBuilder = new UniversalLoinc2HPOAnnotation.Builder();
    LoincId loincId = new LoincId("15074-8");
    LoincScale loincScale = LoincScale.string2enum("Qn");
    HpoTerm low = hpoTermMap.get("Hypoglycemia");
    HpoTerm normal = hpoTermMap.get("Abnormality of blood glucose concentration");
    HpoTerm hi = hpoTermMap.get("Hyperglycemia");
    loinc2HpoAnnotationBuilder.setLoincId(loincId).setLoincScale(loincScale).setLowValueHpoTerm(low).setIntermediateValueHpoTerm(normal).setIntermediateNegated(true).setHighValueHpoTerm(hi);
    UniversalLoinc2HPOAnnotation annotation15074 = loinc2HpoAnnotationBuilder.build();
    assertEquals("15074-8", annotation15074.getLoincId().toString());
    assertEquals("Qn", annotation15074.getLoincScale().toString());
    Map<String, Code> internalCodes = CodeSystemConvertor.getCodeContainer().getCodeSystemMap().get(Loinc2HPOCodedValue.CODESYSTEM);
    Code code4low = internalCodes.get("L");
    assertEquals(low.getId().getIdWithPrefix(), annotation15074.getCandidateHpoTerms().get(code4low).getHpoTerm().getId().getIdWithPrefix());
    assertEquals(false, annotation15074.getCandidateHpoTerms().get(code4low).isNegated());
    Code code4high = internalCodes.get("H");
    assertEquals(hi.getId().getIdWithPrefix(), annotation15074.getCandidateHpoTerms().get(code4high).getHpoTerm().getId().getIdWithPrefix());
    assertEquals(false, annotation15074.getCandidateHpoTerms().get(code4high).isNegated());
    Code code4normal = internalCodes.get("N");
    assertEquals(normal.getId().getIdWithPrefix(), annotation15074.getCandidateHpoTerms().get(code4normal).getHpoTerm().getId().getIdWithPrefix());
    assertEquals(true, annotation15074.getCandidateHpoTerms().get(code4normal).isNegated());
    Code code4Pos = internalCodes.get("P");
    assertEquals(hi.getId().getIdWithPrefix(), annotation15074.getCandidateHpoTerms().get(code4Pos).getHpoTerm().getId().getIdWithPrefix());
    assertEquals(false, annotation15074.getCandidateHpoTerms().get(code4Pos).isNegated());
    Code code4NP = internalCodes.get("NP");
    assertEquals(normal.getId().getIdWithPrefix(), annotation15074.getCandidateHpoTerms().get(code4NP).getHpoTerm().getId().getIdWithPrefix());
    assertEquals(true, annotation15074.getCandidateHpoTerms().get(code4NP).isNegated());
}
Also used : HpoOboParser(com.github.phenomics.ontolib.io.obo.hpo.HpoOboParser) IOException(java.io.IOException) Code(org.monarchinitiative.loinc2hpo.codesystems.Code) ImmutableMap(com.google.common.collect.ImmutableMap) HpoTerm(com.github.phenomics.ontolib.formats.hpo.HpoTerm) WriteToFile(org.monarchinitiative.loinc2hpo.io.WriteToFile) File(java.io.File) HpoOntology(com.github.phenomics.ontolib.formats.hpo.HpoOntology) FhirObservationAnalyzerTest(org.monarchinitiative.loinc2hpo.fhir.FhirObservationAnalyzerTest) Test(org.junit.Test)

Example 4 with HpoOboParser

use of com.github.phenomics.ontolib.io.obo.hpo.HpoOboParser in project loinc2hpo by monarch-initiative.

the class HPOParser method parse.

private void parse(String path) {
    File f = new File(path);
    if (!f.exists()) {
        LOGGER.error(String.format("Unable to find HPO file at %s", path));
        return;
    }
    final HpoOboParser parser = new HpoOboParser(f);
    try {
        this.hpo = parser.parse();
    } catch (IOException e) {
        LOGGER.error(String.format("I/O error with HPO file at %s", path));
        LOGGER.error(e, e);
    }
}
Also used : HpoOboParser(com.github.phenomics.ontolib.io.obo.hpo.HpoOboParser) IOException(java.io.IOException) File(java.io.File)

Example 5 with HpoOboParser

use of com.github.phenomics.ontolib.io.obo.hpo.HpoOboParser in project loinc2hpo by monarch-initiative.

the class FhirObservationAnalyzerTest method setup.

@BeforeClass
public static void setup() {
    String path = FhirObservationAnalyzerTest.class.getClassLoader().getResource("json/glucoseHigh.fhir").getPath();
    observation = FhirResourceRetriever.parseJsonFile2Observation(path);
    String hpo_obo = FhirObservationAnalyzerTest.class.getClassLoader().getResource("obo/hp.obo").getPath();
    HpoOboParser hpoOboParser = new HpoOboParser(new File(hpo_obo));
    HpoOntology hpo = null;
    try {
        hpo = hpoOboParser.parse();
    } catch (IOException e) {
        e.printStackTrace();
    }
    ImmutableMap.Builder<String, HpoTerm> termmap = new ImmutableMap.Builder<>();
    if (hpo != null) {
        List<HpoTerm> res = hpo.getTermMap().values().stream().distinct().collect(Collectors.toList());
        res.forEach(term -> termmap.put(term.getName(), term));
    }
    hpoTermMap = termmap.build();
    assertNull(FhirObservationAnalyzer.getObservation());
}
Also used : HpoTerm(com.github.phenomics.ontolib.formats.hpo.HpoTerm) HpoOboParser(com.github.phenomics.ontolib.io.obo.hpo.HpoOboParser) IOException(java.io.IOException) File(java.io.File) HpoOntology(com.github.phenomics.ontolib.formats.hpo.HpoOntology) ImmutableMap(com.google.common.collect.ImmutableMap) BeforeClass(org.junit.BeforeClass)

Aggregations

HpoOboParser (com.github.phenomics.ontolib.io.obo.hpo.HpoOboParser)12 File (java.io.File)12 IOException (java.io.IOException)11 HpoOntology (com.github.phenomics.ontolib.formats.hpo.HpoOntology)10 HpoTerm (com.github.phenomics.ontolib.formats.hpo.HpoTerm)10 ImmutableMap (com.google.common.collect.ImmutableMap)10 Code (org.monarchinitiative.loinc2hpo.codesystems.Code)8 Test (org.junit.Test)6 FhirObservationAnalyzerTest (org.monarchinitiative.loinc2hpo.fhir.FhirObservationAnalyzerTest)6 WriteToFile (org.monarchinitiative.loinc2hpo.io.WriteToFile)6 TermId (com.github.phenomics.ontolib.ontology.data.TermId)4 BeforeClass (org.junit.BeforeClass)4 Observation (org.hl7.fhir.dstu3.model.Observation)3 Ignore (org.junit.Ignore)3 HashMap (java.util.HashMap)2 BufferedReader (java.io.BufferedReader)1 FileReader (java.io.FileReader)1