Search in sources :

Example 1 with HpoOntology

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

the class FromFileTest method setup.

@BeforeClass
public static void setup() throws IOException {
    ClassLoader classLoader = FromFileTest.class.getClassLoader();
    String obopath = classLoader.getResource("obo/hp.obo").getFile();
    String loincpath = classLoader.getResource("loinc2hpoAnnotationTest.tsv").getFile();
    HPOParser parser = new HPOParser(obopath);
    HpoOntology ontology = parser.getHPO();
    loincparser = new FromFile(loincpath, ontology);
}
Also used : HpoOntology(com.github.phenomics.ontolib.formats.hpo.HpoOntology) BeforeClass(org.junit.BeforeClass)

Example 2 with HpoOntology

use of com.github.phenomics.ontolib.formats.hpo.HpoOntology 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 HpoOntology

use of com.github.phenomics.ontolib.formats.hpo.HpoOntology 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 HpoOntology

use of com.github.phenomics.ontolib.formats.hpo.HpoOntology 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)

Example 5 with HpoOntology

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

the class FhirObservationParserTest method setup.

@BeforeClass
public static void setup() throws IOException {
    ClassLoader classLoader = FhirObservationParserTest.class.getClassLoader();
    String obopath = classLoader.getResource("obo/hp.obo").getFile();
    String loincpath = classLoader.getResource("loinc2hpoAnnotationTest.tsv").getFile();
    HPOParser parser = new HPOParser(obopath);
    HpoOntology ontology = parser.getHPO();
    loincparser = new FromFile(loincpath, ontology);
    testmap = loincparser.getTestmap();
    String fhirPath = classLoader.getResource("json/glucoseHigh.fhir").getFile();
    ObjectMapper mapper = new ObjectMapper();
    File f = new File(fhirPath);
    FileInputStream fis = new FileInputStream(f);
    byte[] data = new byte[(int) f.length()];
    fis.read(data);
    fis.close();
    node = mapper.readTree(data);
}
Also used : FromFile(org.monarchinitiative.loinc2hpo.io.FromFile) HpoOntology(com.github.phenomics.ontolib.formats.hpo.HpoOntology) FromFile(org.monarchinitiative.loinc2hpo.io.FromFile) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HPOParser(org.monarchinitiative.loinc2hpo.io.HPOParser) BeforeClass(org.junit.BeforeClass)

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