Search in sources :

Example 6 with HpoTerm

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

the class AnnotateTabController method createLoinc2HpoAnnotation.

@FXML
private void createLoinc2HpoAnnotation(ActionEvent e) {
    if (loincTableView.getSelectionModel().getSelectedItem() == null) {
        PopUps.showInfoMessage("No loinc entry is selected. Try clicking \"Initialize Loinc Table\"", "No Loinc selection Error");
        return;
    }
    // specify loinc for the annotation
    LoincEntry loincEntry = loincTableView.getSelectionModel().getSelectedItem();
    LoincId loincCode = loincEntry.getLOINC_Number();
    LoincScale loincScale = LoincScale.string2enum(loincEntry.getScale());
    // if the loinc is already annotated, warn user
    if (createAnnotationButton.getText().equals("Create annotation") && model.getLoincAnnotationMap().containsKey(loincCode)) {
        boolean toOverwrite = PopUps.getBooleanFromUser("Do you want to overwrite?", loincCode + " is already annotated", "Overwrite warning");
        if (!toOverwrite)
            return;
    }
    // update annotations right before finalizing the record
    if (!advancedAnnotationModeSelected) {
        // we are last in basic mode, user might have changed data for basic annotation
        logger.trace("creating the annotation while at the basic mode");
        logger.trace("record changes for basic annotation");
        // update terms for basic annotation
        model.setTempTerms(recordTempTerms());
        model.setInversedBasicMode(recordInversed());
    } else {
        // if we are last in the advanced mode, user might have added a new annotation, we add this annotation
        logger.trace("creating the annotation while at the advanced mode");
        handleAnnotateCodedValue(e);
    }
    // map hpo terms to internal codes
    Map<String, String> tempTerms = model.getTempTerms();
    String hpoLo = tempTerms.get("hpoLo");
    String hpoNormal = tempTerms.get("hpoNormal");
    String hpoHi = tempTerms.get("hpoHi");
    logger.debug(String.format("hpoLo: %s; hpoNormal: %s; hpoHi: %s", hpoLo, hpoNormal, hpoHi));
    // if no annotations for basic AND advanced, do not create it
    if ((hpoLo == null || hpoLo.isEmpty()) && (hpoNormal == null || hpoNormal.isEmpty()) && (hpoHi == null || hpoHi.isEmpty()) && tempAdvancedAnnotations.isEmpty()) {
        PopUps.showInfoMessage("You have not mapped any HPO terms to this LOINC.", "Abort");
        logger.debug("tempAdvancedAnnotations size: " + tempAdvancedAnnotations.size());
        return;
    }
    // We don't have to force every loinc code to have three phenotypes
    HpoTerm low = termmap.get(hpoLo);
    HpoTerm normal = termmap.get(hpoNormal);
    HpoTerm high = termmap.get(hpoHi);
    // it happens when something is wrong with hpo termmap (a name could not be mapped)
    if (hpoLo != null && low == null) {
        logger.error(hpoLo + " cannot be mapped to a term");
        createAnnotationSuccess.setFill(Color.RED);
        showErrorOfMapping(hpoLo);
        return;
    }
    if (hpoHi != null && high == null) {
        logger.error(hpoHi + " cannot be mapped to a term");
        createAnnotationSuccess.setFill(Color.RED);
        showErrorOfMapping(hpoHi);
        return;
    }
    if (hpoNormal != null && normal == null) {
        logger.error(hpoNormal + " cannot be mapped to a term");
        createAnnotationSuccess.setFill(Color.RED);
        showErrorOfMapping(hpoNormal);
        return;
    }
    // start building the annotation
    UniversalLoinc2HPOAnnotation.Builder builder = new UniversalLoinc2HPOAnnotation.Builder();
    builder.setLoincId(loincCode).setLoincScale(loincScale).setLowValueHpoTerm(low).setIntermediateValueHpoTerm(normal).setHighValueHpoTerm(high).setIntermediateNegated(model.isInversedBasicMode()).setNote(annotationNoteField.getText()).setFlag(flagForAnnotation.isSelected());
    // add the advanced annotations
    if (!tempAdvancedAnnotations.isEmpty()) {
        tempAdvancedAnnotations.forEach(p -> builder.addAdvancedAnnotation(p.getCode(), p.getHpoTermId4LoincTest()));
    }
    // add some meta data, such as date, created by, and version
    if (createAnnotationButton.getText().equals("Create annotation")) {
        // create for the first time
        builder.setCreatedBy(model.getBiocuratorID() == null ? MISSINGVALUE : model.getBiocuratorID()).setCreatedOn(LocalDateTime.now().withNano(0)).setVersion(0.1);
    } else {
        // editing mode
        builder.setLastEditedBy(model.getBiocuratorID() == null ? MISSINGVALUE : model.getBiocuratorID()).setLastEditedOn(LocalDateTime.now().withNano(0)).setCreatedBy(model.getLoincAnnotationMap().get(loincCode).getCreatedBy()).setCreatedOn(model.getLoincAnnotationMap().get(loincCode).getCreatedOn()).setVersion(model.getLoincAnnotationMap().get(loincCode).getVersion() + 0.1);
    }
    // complete the building process, build the object
    UniversalLoinc2HPOAnnotation loinc2HPOAnnotation = builder.build();
    model.addLoincTest(loinc2HPOAnnotation);
    // reset many settings
    advancedAnnotationModeSelected = false;
    // clear the temp term in model
    model.setTempTerms(new HashMap<>());
    model.setInversedBasicMode(false);
    model.setTempAdvancedAnnotation(new HashMap<>());
    model.setInversedAdvancedMode(false);
    tempAdvancedAnnotations.clear();
    switchToBasicAnnotationMode();
    flagForAnnotation.setSelected(false);
    annotationNoteField.clear();
    model.setSessionChanged(true);
    loinc2HpoAnnotationsTabController.refreshTable();
    createAnnotationSuccess.setFill(Color.GREEN);
    if (createAnnotationButton.getText().equals("Save")) {
        createAnnotationButton.setText("Create annotation");
        model.setLoincUnderEditing(null);
    }
    changeColorLoincTableView();
    e.consume();
}
Also used : HpoTerm(com.github.phenomics.ontolib.formats.hpo.HpoTerm) FXML(javafx.fxml.FXML)

Example 7 with HpoTerm

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

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

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

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

Aggregations

HpoTerm (com.github.phenomics.ontolib.formats.hpo.HpoTerm)14 HpoOntology (com.github.phenomics.ontolib.formats.hpo.HpoOntology)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)10 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 HashMap (java.util.HashMap)3 FXML (javafx.fxml.FXML)3 Observation (org.hl7.fhir.dstu3.model.Observation)3 Ignore (org.junit.Ignore)3 ImmutableTermId (com.github.phenomics.ontolib.ontology.data.ImmutableTermId)1 ImmutableTermPrefix (com.github.phenomics.ontolib.ontology.data.ImmutableTermPrefix)1 TermPrefix (com.github.phenomics.ontolib.ontology.data.TermPrefix)1 BufferedReader (java.io.BufferedReader)1