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);
}
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());
}
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());
}
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());
}
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);
}
Aggregations