Search in sources :

Example 6 with HpoOboParser

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

the class ObservationAnalysisFromCodedValuesTest method setup.

@BeforeClass
public static void setup() throws MalformedLoincCodeException {
    String path = FhirObservationAnalyzerTest.class.getClassLoader().getResource("json/staphylococcus.fhir").getPath();
    Observation observation1 = FhirResourceRetriever.parseJsonFile2Observation(path);
    path = FhirObservationAnalyzerTest.class.getClassLoader().getResource("json/staphylococcusNoInterpretation.fhir").getPath();
    Observation observation2 = FhirResourceRetriever.parseJsonFile2Observation(path);
    path = FhirObservationAnalyzerTest.class.getClassLoader().getResource("json/ecoliNoInterpretation.fhir").getPath();
    Observation observation3 = FhirResourceRetriever.parseJsonFile2Observation(path);
    path = FhirObservationAnalyzerTest.class.getClassLoader().getResource("json/neisseriaNoInterpretation.fhir").getPath();
    Observation observation4 = FhirResourceRetriever.parseJsonFile2Observation(path);
    observations[0] = observation1;
    observations[1] = observation2;
    observations[2] = observation3;
    observations[3] = observation4;
    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<>();
    ImmutableMap.Builder<TermId, HpoTerm> termmap2 = 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);
            termmap2.put(term.getId(), term);
        });
    }
    hpoTermMap = termmap.build();
    hpoTermMap2 = termmap2.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();
    testmap.put(loincId, annotation15074);
    loinc2HpoAnnotationBuilder = new UniversalLoinc2HPOAnnotation.Builder();
    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");
    loinc2HpoAnnotationBuilder.setLoincId(loincId).setLoincScale(loincScale).setHighValueHpoTerm(positive).addAdvancedAnnotation(code1, new HpoTermId4LoincTest(forCode1, false)).addAdvancedAnnotation(code2, new HpoTermId4LoincTest(forCode2, false));
    UniversalLoinc2HPOAnnotation annotation600 = loinc2HpoAnnotationBuilder.build();
    testmap.put(loincId, annotation600);
}
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) Observation(org.hl7.fhir.dstu3.model.Observation) TermId(com.github.phenomics.ontolib.ontology.data.TermId) File(java.io.File) HpoOntology(com.github.phenomics.ontolib.formats.hpo.HpoOntology) BeforeClass(org.junit.BeforeClass)

Example 7 with HpoOboParser

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

the class ObservationAnalysisFromInterpretationTest method setup.

@BeforeClass
public static void setup() throws MalformedLoincCodeException {
    String path = FhirObservationAnalyzerTest.class.getClassLoader().getResource("json/glucoseHigh.fhir").getPath();
    Observation observation1 = FhirResourceRetriever.parseJsonFile2Observation(path);
    path = FhirObservationAnalyzerTest.class.getClassLoader().getResource("json/glucoseConflictingInterpretation.fhir").getPath();
    Observation observation2 = FhirResourceRetriever.parseJsonFile2Observation(path);
    observations[0] = observation1;
    observations[1] = observation2;
    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<>();
    ImmutableMap.Builder<TermId, HpoTerm> termmap2 = 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);
            termmap2.put(term.getId(), term);
        });
    }
    hpoTermMap = termmap.build();
    hpoTermMap2 = termmap2.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();
    testmap.put(loincId, annotation15074);
    loinc2HpoAnnotationBuilder = new UniversalLoinc2HPOAnnotation.Builder();
    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");
    loinc2HpoAnnotationBuilder.setLoincId(loincId).setLoincScale(loincScale).setHighValueHpoTerm(positive).addAdvancedAnnotation(code1, new HpoTermId4LoincTest(forCode1, false)).addAdvancedAnnotation(code2, new HpoTermId4LoincTest(forCode2, false));
    UniversalLoinc2HPOAnnotation annotation600 = loinc2HpoAnnotationBuilder.build();
    testmap.put(loincId, annotation600);
}
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) Observation(org.hl7.fhir.dstu3.model.Observation) TermId(com.github.phenomics.ontolib.ontology.data.TermId) File(java.io.File) HpoOntology(com.github.phenomics.ontolib.formats.hpo.HpoOntology) BeforeClass(org.junit.BeforeClass)

Example 8 with HpoOboParser

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

the class ObservationAnalysisFromQnValueTest method setup.

@BeforeClass
public static void setup() throws MalformedLoincCodeException {
    String path = FhirObservationAnalyzerTest.class.getClassLoader().getResource("json/glucoseHighNoInterpretation.fhir").getPath();
    Observation observation1 = FhirResourceRetriever.parseJsonFile2Observation(path);
    path = FhirObservationAnalyzerTest.class.getClassLoader().getResource("json/glucoseNoInterpretationNoReference.fhir").getPath();
    Observation observation2 = FhirResourceRetriever.parseJsonFile2Observation(path);
    observations[0] = observation1;
    observations[1] = observation2;
    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<>();
    ImmutableMap.Builder<TermId, HpoTerm> termmap2 = 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);
            termmap2.put(term.getId(), term);
        });
    }
    hpoTermMap = termmap.build();
    hpoTermMap2 = termmap2.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();
    testmap.put(loincId, annotation15074);
    loinc2HpoAnnotationBuilder = new UniversalLoinc2HPOAnnotation.Builder();
    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");
    loinc2HpoAnnotationBuilder.setLoincId(loincId).setLoincScale(loincScale).setHighValueHpoTerm(positive).addAdvancedAnnotation(code1, new HpoTermId4LoincTest(forCode1, false)).addAdvancedAnnotation(code2, new HpoTermId4LoincTest(forCode2, false));
    UniversalLoinc2HPOAnnotation annotation600 = loinc2HpoAnnotationBuilder.build();
    testmap.put(loincId, annotation600);
}
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) Observation(org.hl7.fhir.dstu3.model.Observation) TermId(com.github.phenomics.ontolib.ontology.data.TermId) File(java.io.File) HpoOntology(com.github.phenomics.ontolib.formats.hpo.HpoOntology) BeforeClass(org.junit.BeforeClass)

Example 9 with HpoOboParser

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

the class UniversalLoinc2HPOAnnotationTest method testBuilderForAdvanced.

@Test
public void testBuilderForAdvanced() 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("600-7");
    LoincScale 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");
    loinc2HpoAnnotationBuilder.setLoincId(loincId).setLoincScale(loincScale).setHighValueHpoTerm(positive).addAdvancedAnnotation(code1, new HpoTermId4LoincTest(forCode1, false)).addAdvancedAnnotation(code2, new HpoTermId4LoincTest(forCode2, false));
    UniversalLoinc2HPOAnnotation annotation600 = loinc2HpoAnnotationBuilder.build();
    assertEquals("600-7", annotation600.getLoincId().toString());
    Map<String, Code> internalCodes = CodeSystemConvertor.getCodeContainer().getCodeSystemMap().get(Loinc2HPOCodedValue.CODESYSTEM);
    Code code4Pos = internalCodes.get("P");
    assertEquals(positive.getId().getIdWithPrefix(), annotation600.getCandidateHpoTerms().get(code4Pos).getHpoTerm().getId().getIdWithPrefix());
    assertEquals(false, annotation600.getCandidateHpoTerms().get(code4Pos).isNegated());
    Code code4high = internalCodes.get("H");
    assertEquals(positive.getId().getIdWithPrefix(), annotation600.getCandidateHpoTerms().get(code4high).getHpoTerm().getId().getIdWithPrefix());
    assertEquals(false, annotation600.getCandidateHpoTerms().get(code4Pos).isNegated());
    assertEquals(forCode1.getId().getIdWithPrefix(), annotation600.getCandidateHpoTerms().get(code1).getHpoTerm().getId().getIdWithPrefix());
    assertEquals(false, annotation600.getCandidateHpoTerms().get(code1).isNegated());
    assertEquals(forCode2.getId().getIdWithPrefix(), annotation600.getCandidateHpoTerms().get(code2).getHpoTerm().getId().getIdWithPrefix());
    assertEquals(false, annotation600.getCandidateHpoTerms().get(code2).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 10 with HpoOboParser

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

the class UniversalLoinc2HPOAnnotationTest method testWriteInOut.

@Test
@Ignore
public void testWriteInOut() throws Exception {
    Map<String, HpoTerm> hpoTermMap;
    Map<TermId, HpoTerm> hpoTermMap2;
    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<>();
    ImmutableMap.Builder<TermId, HpoTerm> termmap2 = 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);
            termmap2.put(term.getId(), term);
        });
    }
    hpoTermMap = termmap.build();
    hpoTermMap2 = termmap2.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();
    Map<LoincId, UniversalLoinc2HPOAnnotation> testmap = new HashMap<>();
    testmap.put(loincId, annotation15074);
    loinc2HpoAnnotationBuilder = new UniversalLoinc2HPOAnnotation.Builder();
    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");
    loinc2HpoAnnotationBuilder.setLoincId(loincId).setLoincScale(loincScale).setHighValueHpoTerm(positive).addAdvancedAnnotation(code1, new HpoTermId4LoincTest(forCode1, false)).addAdvancedAnnotation(code2, new HpoTermId4LoincTest(forCode2, false));
    UniversalLoinc2HPOAnnotation annotation600 = loinc2HpoAnnotationBuilder.build();
    testmap.put(loincId, annotation600);
    assertEquals(2, testmap.size());
    String filepath = temporaryFolder.newFile().getAbsolutePath();
    WriteToFile.toTSVbasicAnnotations(filepath, testmap);
    String filepath2 = temporaryFolder.newFile().getAbsolutePath();
    WriteToFile.toTSVadvancedAnnotations(filepath2, testmap);
    Map<LoincId, UniversalLoinc2HPOAnnotation> deserializedMap = WriteToFile.fromTSVBasic(filepath, hpoTermMap2);
    WriteToFile.fromTSVAdvanced(filepath2, deserializedMap, hpoTermMap2);
    assertEquals(2, deserializedMap.size());
    deserializedMap.values().forEach(System.out::println);
}
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) TermId(com.github.phenomics.ontolib.ontology.data.TermId) WriteToFile(org.monarchinitiative.loinc2hpo.io.WriteToFile) File(java.io.File) HpoOntology(com.github.phenomics.ontolib.formats.hpo.HpoOntology) Ignore(org.junit.Ignore) FhirObservationAnalyzerTest(org.monarchinitiative.loinc2hpo.fhir.FhirObservationAnalyzerTest) Test(org.junit.Test)

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