Search in sources :

Example 1 with Code

use of org.monarchinitiative.loinc2hpo.codesystems.Code in project loinc2hpo by monarch-initiative.

the class AnnotateTabController method editCurrentAnnotation.

/**
 * This method is called from the pop up window
 * @param loincAnnotation passed from the pop up window
 */
protected void editCurrentAnnotation(UniversalLoinc2HPOAnnotation loincAnnotation) {
    setLoincIdSelected(loincAnnotation.getLoincId());
    model.setLoincUnderEditing(model.getLoincEntryMap().get(loincAnnotation.getLoincId()));
    // populate annotation textfields for basic mode
    Map<String, Code> internalCode = CodeSystemConvertor.getCodeContainer().getCodeSystemMap().get(Loinc2HPOCodedValue.CODESYSTEM);
    Code codeLow = internalCode.get("L");
    Code codeHigh = internalCode.get("H");
    Code codeNormal = internalCode.get("N");
    HpoTermId4LoincTest hpoLow = loincAnnotation.loincInterpretationToHPO(codeLow);
    HpoTermId4LoincTest hpoHigh = loincAnnotation.loincInterpretationToHPO(codeHigh);
    HpoTermId4LoincTest hpoNormal = loincAnnotation.loincInterpretationToHPO(codeNormal);
    if (hpoLow != null) {
        String hpoLowTermName = hpoLow.getHpoTerm().getName();
        annotationTextFieldLeft.setText(hpoLowTermName);
    }
    if (hpoHigh != null) {
        String hpoHighTermName = hpoHigh.getHpoTerm().getName();
        annotationTextFieldRight.setText(hpoHighTermName);
    }
    if (hpoNormal != null) {
        String hpoNormalTermName = hpoNormal.getHpoTerm().getName();
        boolean isnegated = hpoNormal.isNegated();
        annotationTextFieldMiddle.setText(hpoNormalTermName);
        inverseChecker.setSelected(isnegated);
    }
    // remember: advanced annotation == not using internal codes
    for (Map.Entry<Code, HpoTermId4LoincTest> entry : loincAnnotation.getCandidateHpoTerms().entrySet()) {
        if (!entry.getKey().getSystem().equals(Loinc2HPOCodedValue.CODESYSTEM)) {
            tempAdvancedAnnotations.add(new Annotation(entry.getKey(), entry.getValue()));
        }
    }
    boolean flag = loincAnnotation.getFlag();
    flagForAnnotation.setSelected(flag);
    String comment = loincAnnotation.getNote();
    annotationNoteField.setText(comment);
    createAnnotationButton.setText("Save");
    clearButton.setText("Cancel");
}
Also used : Code(org.monarchinitiative.loinc2hpo.codesystems.Code) ImmutableMap(com.google.common.collect.ImmutableMap) Annotation(org.monarchinitiative.loinc2hpo.model.Annotation)

Example 2 with Code

use of org.monarchinitiative.loinc2hpo.codesystems.Code in project loinc2hpo by monarch-initiative.

the class AnnotateTabController method handleAnnotateCodedValue.

@FXML
private void handleAnnotateCodedValue(ActionEvent e) {
    e.consume();
    // do nothing if it is the basic mode
    if (!advancedAnnotationModeSelected)
        return;
    Annotation annotation = null;
    String system = annotationTextFieldLeft.getText().trim().toLowerCase();
    // case sensitive
    String codeId = annotationTextFieldMiddle.getText().trim();
    Code code = null;
    if (system != null && !system.isEmpty() && codeId != null && !codeId.isEmpty()) {
        code = Code.getNewCode().setSystem(system).setCode(codeId);
    }
    String candidateHPO = annotationTextFieldRight.getText();
    HpoTerm hpoterm = model.getTermMap().get(stripEN(candidateHPO));
    if (hpoterm == null)
        logger.error("hpoterm is null");
    if (code != null && hpoterm != null) {
        annotation = new Annotation(code, new HpoTermId4LoincTest(hpoterm, inverseChecker.isSelected()));
    }
    tempAdvancedAnnotations.add(annotation);
    // add annotated value to the advanced table view
    // initadvancedAnnotationTable();
    accordion.setExpandedPane(advancedAnnotationTitledPane);
    inverseChecker.setSelected(false);
    model.setTempAdvancedAnnotation(new HashMap<>());
    model.setInversedAdvancedMode(false);
}
Also used : HpoTerm(com.github.phenomics.ontolib.formats.hpo.HpoTerm) Code(org.monarchinitiative.loinc2hpo.codesystems.Code) Annotation(org.monarchinitiative.loinc2hpo.model.Annotation) FXML(javafx.fxml.FXML)

Example 3 with Code

use of org.monarchinitiative.loinc2hpo.codesystems.Code in project loinc2hpo by monarch-initiative.

the class AnnotateTabController method initialize.

@FXML
private void initialize() {
    if (model != null) {
        // weird line. model is set by main controller; this line never runs
        setModel(model);
    // currentAnnotationController.setModel(model); //let current annotation stage have access to model
    }
    // currentAnnotationController.setModel(model); //let current annotation stage have access to model
    suggestHPOButton.setTooltip(new Tooltip("Suggest new HPO terms"));
    filterButton.setTooltip(new Tooltip("Filter Loinc by providing a Loinc list in txt file"));
    addCodedAnnotationButton.setTooltip(new Tooltip("Add current annotation"));
    flagForAnnotation.setTooltip(new Tooltip("Check if you are not confident"));
    clearButton.setTooltip(new Tooltip("Clear all textfields"));
    allAnnotationsButton.setTooltip(new Tooltip("Display annotations for currently selected Loinc code"));
    initLOINCtableButton.setTooltip(new Tooltip("Initialize Loinc Core Table. Download it first."));
    IntializeHPOmodelbutton.setTooltip(new Tooltip("Load hp.owl as a RDF model for query"));
    searchForLOINCIdButton.setTooltip(new Tooltip("Search Loinc with a Loinc code or name"));
    modeButton.setTooltip(new Tooltip("Switch between basic and advanced annotation mode"));
    autoQueryButton.setTooltip(new Tooltip("Find candidate HPO terms with automatically generated keys"));
    manualQueryButton.setTooltip(new Tooltip("Find candidate HPO terms with manually typed keys"));
    hpoListView.setCellFactory(new Callback<ListView<HPO_Class_Found>, ListCell<HPO_Class_Found>>() {

        @Override
        public ListCell<HPO_Class_Found> call(ListView<HPO_Class_Found> param) {
            return new ListCell<HPO_Class_Found>() {

                @Override
                public void updateItem(HPO_Class_Found hpo, boolean empty) {
                    super.updateItem(hpo, empty);
                    if (hpo != null) {
                        setText(hpo.toString());
                        Tooltip tooltip = new Tooltip(hpo.getDefinition());
                        tooltip.setPrefWidth(300);
                        tooltip.setWrapText(true);
                        setTooltip(tooltip);
                    } else {
                        setText(null);
                    }
                }
            };
        }
    });
    treeView.setCellFactory(new Callback<TreeView<HPO_TreeView>, TreeCell<HPO_TreeView>>() {

        @Override
        public TreeCell<HPO_TreeView> call(TreeView<HPO_TreeView> param) {
            return new TreeCell<HPO_TreeView>() {

                @Override
                public void updateItem(HPO_TreeView hpo, boolean empty) {
                    super.updateItem(hpo, empty);
                    if (empty) {
                        setText(null);
                        setGraphic(null);
                    } else {
                        if (hpo != null && hpo.hpo_class_found == null) {
                            setText("root");
                        }
                        if (hpo != null && hpo.hpo_class_found != null) {
                            setText(hpo.toString());
                            if (hpo.hpo_class_found.getDefinition() != null) {
                                Tooltip tooltip = new Tooltip(hpo.hpo_class_found.getDefinition());
                                tooltip.setPrefWidth(300);
                                tooltip.setWrapText(true);
                                setTooltip(tooltip);
                            }
                        }
                    }
                }
            };
        }
    });
    // if user creates a new Loinc group, add two menuitems for it, and specify the actions when those menuitems are
    // clicked
    userCreatedLoincLists.addListener(new ListChangeListener<String>() {

        @Override
        public void onChanged(Change<? extends String> c) {
            while (c.next()) {
                if (c.wasAdded()) {
                    logger.trace(c + " was added");
                    c.getAddedSubList().stream().filter(p -> !model.getUserCreatedLoincLists().containsKey(p)).forEach(p -> {
                        model.addUserCreatedLoincList(p, new LinkedHashSet<>());
                        MenuItem newListMenuItem = new MenuItem(p);
                        userCreatedLoincListsButton.getItems().add(newListMenuItem);
                        newListMenuItem.setOnAction((event -> {
                            logger.trace("action detected");
                            if (loincTableView.getSelectionModel().getSelectedItem() != null) {
                                LoincId loincId = loincTableView.getSelectionModel().getSelectedItem().getLOINC_Number();
                                if (model.getUserCreatedLoincLists().get(p).contains(loincId)) {
                                    model.getUserCreatedLoincLists().get(p).remove(loincId);
                                    logger.trace(String.format("LOINC: %s removed from %s", loincId, p));
                                } else {
                                    model.getUserCreatedLoincLists().get(p).add(loincId);
                                    logger.trace(String.format("LOINC: %s added to %s", loincId, p));
                                }
                                changeColorLoincTableView();
                                model.setSessionChanged(true);
                            }
                        }));
                        MenuItem newExportMenuItem = new MenuItem(p);
                        exportLoincListButton.getItems().add(newExportMenuItem);
                        newExportMenuItem.setOnAction((event -> {
                            logger.trace("action detected");
                            if (loincTableView.getSelectionModel().getSelectedItem() != null) {
                                Set<LoincId> loincIds = model.getUserCreatedLoincLists().get(p);
                                if (loincIds.isEmpty()) {
                                    return;
                                }
                                FileChooser chooser = new FileChooser();
                                chooser.setTitle("Save Loinc List: ");
                                chooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("TSV files (*.txt)", "*.txt"));
                                chooser.setInitialFileName(p);
                                File f = chooser.showSaveDialog(null);
                                String filepath;
                                if (f == null) {
                                    return;
                                } else {
                                    filepath = f.getAbsolutePath();
                                }
                                StringBuilder builder = new StringBuilder();
                                loincIds.forEach(l -> {
                                    builder.append(l);
                                    builder.append("\n");
                                });
                                WriteToFile.writeToFile(builder.toString().trim(), filepath);
                            }
                        }));
                        MenuItem newImportMenuItem = new MenuItem(p);
                        importLoincGroupButton.getItems().add(newImportMenuItem);
                        newImportMenuItem.setOnAction((event) -> {
                            logger.trace("user wants to import " + p);
                            FileChooser chooser = new FileChooser();
                            chooser.setTitle("Select file to import from");
                            File f = chooser.showOpenDialog(null);
                            if (f == null) {
                                return;
                            }
                            List<String> malformed = new ArrayList<>();
                            List<String> notFound = new ArrayList<>();
                            try {
                                LoincOfInterest loincSet = new LoincOfInterest(f.getAbsolutePath());
                                Set<String> loincIds = loincSet.getLoincOfInterest();
                                loincIds.forEach(l -> {
                                    LoincId loincId = null;
                                    try {
                                        loincId = new LoincId(l);
                                    } catch (MalformedLoincCodeException e) {
                                        malformed.add(l);
                                    }
                                    if (model.getLoincEntryMap().containsKey(loincId)) {
                                        model.getUserCreatedLoincLists().get(p).add(loincId);
                                    } else {
                                        notFound.add(l);
                                    }
                                    changeColorLoincTableView();
                                });
                            } catch (FileNotFoundException e) {
                                logger.error("File not found. Should never happen");
                            }
                            if (!malformed.isEmpty() || !notFound.isEmpty()) {
                                String malformedString = String.join("\n", malformed);
                                String notFoundString = String.join("\n", notFound);
                                PopUps.showInfoMessage(String.format("Malformed Loinc: %d\n%s\nNot Found: %d\n%s", malformed.size(), malformedString, notFound.size(), notFoundString), "Error during importing");
                            }
                        });
                    });
                } else {
                    logger.error("This should never happen");
                }
            }
        }
    });
    initadvancedAnnotationTable();
}
Also used : PopUps(org.monarchinitiative.loinc2hpo.gui.PopUps) WriteToFile(org.monarchinitiative.loinc2hpo.io.WriteToFile) javafx.scene.control(javafx.scene.control) Inject(com.google.inject.Inject) Parent(javafx.scene.Parent) Task(javafx.concurrent.Task) ListChangeListener(javafx.collections.ListChangeListener) MalformedLoincCodeException(org.monarchinitiative.loinc2hpo.exception.MalformedLoincCodeException) HpoTerm(com.github.phenomics.ontolib.formats.hpo.HpoTerm) GitHubPopup(org.monarchinitiative.loinc2hpo.gui.GitHubPopup) Circle(javafx.scene.shape.Circle) ImmutableMap(com.google.common.collect.ImmutableMap) LoincLongNameParser(org.monarchinitiative.loinc2hpo.util.LoincLongNameParser) Event(javafx.event.Event) javafx.stage(javafx.stage) Platform(javafx.application.Platform) FXML(javafx.fxml.FXML) Logger(org.apache.logging.log4j.Logger) Code(org.monarchinitiative.loinc2hpo.codesystems.Code) HPO_Class_Found(org.monarchinitiative.loinc2hpo.util.HPO_Class_Found) ObservableList(javafx.collections.ObservableList) org.monarchinitiative.loinc2hpo.loinc(org.monarchinitiative.loinc2hpo.loinc) LoincCodeNotFoundException(org.monarchinitiative.loinc2hpo.exception.LoincCodeNotFoundException) NetPostException(org.monarchinitiative.loinc2hpo.exception.NetPostException) Singleton(com.google.inject.Singleton) Scene(javafx.scene.Scene) Main(org.monarchinitiative.loinc2hpo.gui.Main) java.util(java.util) Loinc2HPOCodedValue(org.monarchinitiative.loinc2hpo.codesystems.Loinc2HPOCodedValue) LocalDateTime(java.time.LocalDateTime) FXCollections(javafx.collections.FXCollections) GitHubLabelRetriever(org.monarchinitiative.loinc2hpo.github.GitHubLabelRetriever) GitHubPoster(org.monarchinitiative.loinc2hpo.github.GitHubPoster) CodeSystemConvertor(org.monarchinitiative.loinc2hpo.codesystems.CodeSystemConvertor) FXMLLoader(javafx.fxml.FXMLLoader) Annotation(org.monarchinitiative.loinc2hpo.model.Annotation) SparqlQuery(org.monarchinitiative.loinc2hpo.util.SparqlQuery) Callback(javafx.util.Callback) Color(javafx.scene.paint.Color) OntologyModelBuilderForJena(org.monarchinitiative.loinc2hpo.io.OntologyModelBuilderForJena) javafx.scene.input(javafx.scene.input) Model(org.monarchinitiative.loinc2hpo.model.Model) ReadOnlyStringWrapper(javafx.beans.property.ReadOnlyStringWrapper) LoincOfInterest(org.monarchinitiative.loinc2hpo.io.LoincOfInterest) Injector(com.google.inject.Injector) ActionEvent(javafx.event.ActionEvent) java.io(java.io) LoincCodeClass(org.monarchinitiative.loinc2hpo.util.LoincCodeClass) LogManager(org.apache.logging.log4j.LogManager) LoincOfInterest(org.monarchinitiative.loinc2hpo.io.LoincOfInterest) ObservableList(javafx.collections.ObservableList) HPO_Class_Found(org.monarchinitiative.loinc2hpo.util.HPO_Class_Found) MalformedLoincCodeException(org.monarchinitiative.loinc2hpo.exception.MalformedLoincCodeException) WriteToFile(org.monarchinitiative.loinc2hpo.io.WriteToFile) FXML(javafx.fxml.FXML)

Example 4 with Code

use of org.monarchinitiative.loinc2hpo.codesystems.Code in project loinc2hpo by monarch-initiative.

the class ObservationAnalysisFromCodedValues method getHPOforObservation.

@Override
public HpoTermId4LoincTest getHPOforObservation() throws AmbiguousResultsFoundException, UnrecognizedCodeException, AnnotationNotFoundException {
    if (annotationMap.get(loincId) == null)
        throw new AnnotationNotFoundException();
    Set<HpoTermId4LoincTest> results = new HashSet<>();
    codedValue.getCoding().stream().filter(p -> annotationMap.get(loincId).getCodes().contains(new Code(p))).forEach(p -> results.add(annotationMap.get(loincId).loincInterpretationToHPO(new Code(p))));
    if (results.size() > 1) {
        throw new AmbiguousResultsFoundException();
    }
    if (results.size() == 1) {
        return results.iterator().next();
    } else {
        throw new UnrecognizedCodeException();
    }
}
Also used : AmbiguousResultsFoundException(org.monarchinitiative.loinc2hpo.exception.AmbiguousResultsFoundException) Set(java.util.Set) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept) UnrecognizedCodeException(org.monarchinitiative.loinc2hpo.exception.UnrecognizedCodeException) Observation(org.hl7.fhir.dstu3.model.Observation) HashSet(java.util.HashSet) Logger(org.apache.logging.log4j.Logger) HpoTermId4LoincTest(org.monarchinitiative.loinc2hpo.loinc.HpoTermId4LoincTest) LoincId(org.monarchinitiative.loinc2hpo.loinc.LoincId) UniversalLoinc2HPOAnnotation(org.monarchinitiative.loinc2hpo.loinc.UniversalLoinc2HPOAnnotation) Loinc2HPOAnnotation(org.monarchinitiative.loinc2hpo.loinc.Loinc2HPOAnnotation) Map(java.util.Map) FHIRException(org.hl7.fhir.exceptions.FHIRException) Code(org.monarchinitiative.loinc2hpo.codesystems.Code) AnnotationNotFoundException(org.monarchinitiative.loinc2hpo.exception.AnnotationNotFoundException) LogManager(org.apache.logging.log4j.LogManager) UnrecognizedCodeException(org.monarchinitiative.loinc2hpo.exception.UnrecognizedCodeException) AnnotationNotFoundException(org.monarchinitiative.loinc2hpo.exception.AnnotationNotFoundException) AmbiguousResultsFoundException(org.monarchinitiative.loinc2hpo.exception.AmbiguousResultsFoundException) HpoTermId4LoincTest(org.monarchinitiative.loinc2hpo.loinc.HpoTermId4LoincTest) Code(org.monarchinitiative.loinc2hpo.codesystems.Code) HashSet(java.util.HashSet)

Example 5 with Code

use of org.monarchinitiative.loinc2hpo.codesystems.Code in project loinc2hpo by monarch-initiative.

the class ObservationAnalysisFromInterpretation method getHPOforObservation.

@Override
public HpoTermId4LoincTest getHPOforObservation() throws UnsupportedCodingSystemException, AmbiguousResultsFoundException, AnnotationNotFoundException, UnrecognizedCodeException {
    // here we use a map to store the results: since there could be more than one interpretation coding system,
    // we try them all and store the results in a map <external code, result in internal code>
    Map<Code, Code> results = new HashMap<>();
    // get the annotation class for this loinc code
    UniversalLoinc2HPOAnnotation annotationForLoinc = annotationMap.get(this.loincId);
    if (annotationForLoinc == null)
        throw new AnnotationNotFoundException();
    // all interpretation codes in different coding systems. Expect one in most cases.
    Set<Code> interpretationCodes = getInterpretationCodes();
    interpretationCodes.stream().filter(p -> CodeSystemConvertor.getCodeContainer().getCodeSystemMap().containsKey(p.getSystem())).forEach(p -> {
        Code internalCode = null;
        try {
            internalCode = CodeSystemConvertor.convertToInternalCode(p);
            results.put(p, internalCode);
        } catch (InternalCodeNotFoundException e) {
            e.printStackTrace();
        }
    });
    List<Code> distinct = results.values().stream().distinct().collect(Collectors.toList());
    if (distinct.size() == 1) {
        HpoTermId4LoincTest hpoTermId4LoincTest = annotationForLoinc.loincInterpretationToHPO(distinct.get(0));
        if (hpoTermId4LoincTest == null)
            throw new UnrecognizedCodeException();
        return hpoTermId4LoincTest;
    } else {
        throw new AmbiguousResultsFoundException();
    }
}
Also used : java.util(java.util) HpoTermId4LoincTest(org.monarchinitiative.loinc2hpo.loinc.HpoTermId4LoincTest) LoincId(org.monarchinitiative.loinc2hpo.loinc.LoincId) UniversalLoinc2HPOAnnotation(org.monarchinitiative.loinc2hpo.loinc.UniversalLoinc2HPOAnnotation) CodeSystemConvertor(org.monarchinitiative.loinc2hpo.codesystems.CodeSystemConvertor) Loinc2HPOAnnotation(org.monarchinitiative.loinc2hpo.loinc.Loinc2HPOAnnotation) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept) Code(org.monarchinitiative.loinc2hpo.codesystems.Code) org.monarchinitiative.loinc2hpo.exception(org.monarchinitiative.loinc2hpo.exception) Collectors(java.util.stream.Collectors) UniversalLoinc2HPOAnnotation(org.monarchinitiative.loinc2hpo.loinc.UniversalLoinc2HPOAnnotation) HpoTermId4LoincTest(org.monarchinitiative.loinc2hpo.loinc.HpoTermId4LoincTest) Code(org.monarchinitiative.loinc2hpo.codesystems.Code)

Aggregations

Code (org.monarchinitiative.loinc2hpo.codesystems.Code)20 HpoTerm (com.github.phenomics.ontolib.formats.hpo.HpoTerm)11 ImmutableMap (com.google.common.collect.ImmutableMap)10 HpoOntology (com.github.phenomics.ontolib.formats.hpo.HpoOntology)8 HpoOboParser (com.github.phenomics.ontolib.io.obo.hpo.HpoOboParser)8 File (java.io.File)8 IOException (java.io.IOException)8 TermId (com.github.phenomics.ontolib.ontology.data.TermId)6 Test (org.junit.Test)6 WriteToFile (org.monarchinitiative.loinc2hpo.io.WriteToFile)6 HpoTermId4LoincTest (org.monarchinitiative.loinc2hpo.loinc.HpoTermId4LoincTest)6 UniversalLoinc2HPOAnnotation (org.monarchinitiative.loinc2hpo.loinc.UniversalLoinc2HPOAnnotation)6 FhirObservationAnalyzerTest (org.monarchinitiative.loinc2hpo.fhir.FhirObservationAnalyzerTest)5 LoincId (org.monarchinitiative.loinc2hpo.loinc.LoincId)5 HashMap (java.util.HashMap)4 Annotation (org.monarchinitiative.loinc2hpo.model.Annotation)4 Map (java.util.Map)3 FXML (javafx.fxml.FXML)3 LogManager (org.apache.logging.log4j.LogManager)3 Logger (org.apache.logging.log4j.Logger)3