Search in sources :

Example 11 with HpoOntology

use of com.github.phenomics.ontolib.formats.hpo.HpoOntology in project loinc2hpo by monarch-initiative.

the class UniversalLoinc2HPOAnnotationTest method testSerializeAdvancedAnnotation.

@Test
@Ignore
public void testSerializeAdvancedAnnotation() 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();
    System.out.println(annotation600.getAdvancedAnnotationsString());
}
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) Ignore(org.junit.Ignore) FhirObservationAnalyzerTest(org.monarchinitiative.loinc2hpo.fhir.FhirObservationAnalyzerTest) Test(org.junit.Test)

Example 12 with HpoOntology

use of com.github.phenomics.ontolib.formats.hpo.HpoOntology in project loinc2hpo by monarch-initiative.

the class UniversalLoinc2HPOAnnotationTest method testSerializeBasicAnnotation.

@Test
@Ignore
public void testSerializeBasicAnnotation() 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();
    System.out.println(UniversalLoinc2HPOAnnotation.getHeaderBasic());
    System.out.println(annotation15074.getBasicAnnotationsString().trim());
}
Also used : HpoOboParser(com.github.phenomics.ontolib.io.obo.hpo.HpoOboParser) IOException(java.io.IOException) 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) Ignore(org.junit.Ignore) FhirObservationAnalyzerTest(org.monarchinitiative.loinc2hpo.fhir.FhirObservationAnalyzerTest) Test(org.junit.Test)

Aggregations

HpoOntology (com.github.phenomics.ontolib.formats.hpo.HpoOntology)12 HpoTerm (com.github.phenomics.ontolib.formats.hpo.HpoTerm)10 HpoOboParser (com.github.phenomics.ontolib.io.obo.hpo.HpoOboParser)10 ImmutableMap (com.google.common.collect.ImmutableMap)10 File (java.io.File)10 IOException (java.io.IOException)10 Code (org.monarchinitiative.loinc2hpo.codesystems.Code)8 BeforeClass (org.junit.BeforeClass)6 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 Observation (org.hl7.fhir.dstu3.model.Observation)3 Ignore (org.junit.Ignore)3 HashMap (java.util.HashMap)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 BufferedReader (java.io.BufferedReader)1 FileReader (java.io.FileReader)1 FromFile (org.monarchinitiative.loinc2hpo.io.FromFile)1 HPOParser (org.monarchinitiative.loinc2hpo.io.HPOParser)1