Search in sources :

Example 1 with HPO_Class_Found

use of org.monarchinitiative.loinc2hpo.util.HPO_Class_Found in project loinc2hpo by monarch-initiative.

the class AnnotateTabController method updateHpoTermListView.

private void updateHpoTermListView(LoincEntry entry) {
    if (SparqlQuery.model == null) {
        Alert alert = new Alert(Alert.AlertType.INFORMATION);
        alert.setTitle("HPO Model Undefined");
        alert.setHeaderText("Create HPO model first before querying");
        alert.setContentText("Click \"Initialize HPO model\" to create an" + " HPO model for Sparql query. Click and query again.");
        alert.showAndWait();
        return;
    }
    String name = entry.getLongName();
    hpoListView.getItems().clear();
    sparqlQueryResult.clear();
    sparqlQueryResult.addAll(SparqlQuery.query_auto(name));
    sparqlQueryResult.sort((o1, o2) -> o2.getScore() - o1.getScore());
    // SparqlQuery.query_auto(name).stream().forEach(sparqlQueryResult::add);
    logger.trace("sparqlQueryResult size: " + sparqlQueryResult.size());
    if (sparqlQueryResult.size() == 0) {
        String noHPOfoundMessage = "0 HPO class is found. Try manual search with " + "alternative keys (synonyms)";
        sparqlQueryResult.add(new HPO_Class_Found(noHPOfoundMessage, null, null, null));
    }
    hpoListView.setItems(sparqlQueryResult);
}
Also used : HPO_Class_Found(org.monarchinitiative.loinc2hpo.util.HPO_Class_Found)

Example 2 with HPO_Class_Found

use of org.monarchinitiative.loinc2hpo.util.HPO_Class_Found in project loinc2hpo by monarch-initiative.

the class AnnotateTabController method suggestNewChildTerm.

@FXML
private void suggestNewChildTerm(ActionEvent e) {
    e.consume();
    initializeGitHubLabelsIfNecessary();
    LoincEntry loincEntrySelected = loincTableView.getSelectionModel().getSelectedItem();
    if (loincEntrySelected == null) {
        logger.error("Select a loinc code before making a suggestion");
        PopUps.showInfoMessage("Please select a loinc code before creating GitHub issue", "Error: No HPO Term selected");
        return;
    }
    loincIdSelected = loincEntrySelected.getLOINC_Number();
    logger.info("Selected loinc to create github issue for: " + loincIdSelected);
    HPO_Class_Found hpoSelected = (HPO_Class_Found) hpoListView.getSelectionModel().getSelectedItem();
    if (hpoSelected == null) {
        HPO_TreeView hpoSelectedInTree = treeView.getSelectionModel().getSelectedItem().getValue();
        hpoSelected = hpoSelectedInTree.hpo_class_found;
    }
    if (hpoSelected == null) {
        logger.error("Select a hpo term before making a suggestion");
        PopUps.showInfoMessage("Please select a hpo term before creating GitHub issue", "Error: No HPO Term selected");
        return;
    }
    HpoTerm hpoTerm = model.getTermMap().get(hpoSelected.getLabel());
    GitHubPopup popup = new GitHubPopup(loincEntrySelected, hpoTerm, true);
    initializeGitHubLabelsIfNecessary();
    popup.setLabels(model.getGithublabels());
    popup.setupGithubUsernamePassword(githubUsername, githubPassword);
    popup.setBiocuratorId(model.getBiocuratorID());
    logger.debug("get biocurator id from model: " + model.getBiocuratorID());
    popup.displayWindow(Main.getPrimarystage());
    String githubissue = popup.retrieveGitHubIssue();
    if (githubissue == null) {
        logger.trace("got back null github issue");
        return;
    }
    List<String> labels = popup.getGitHubLabels();
    // String title = String.format("NTR for Loinc %s:  \"%s\"", loincIdSelected, popup.retrieveSuggestedTerm());
    String title = String.format("Loinc %s:  \"%s\"", loincIdSelected, loincEntrySelected.getLongName());
    postGitHubIssue(githubissue, title, popup.getGitHubUserName(), popup.getGitHubPassWord(), labels);
}
Also used : HPO_Class_Found(org.monarchinitiative.loinc2hpo.util.HPO_Class_Found) HpoTerm(com.github.phenomics.ontolib.formats.hpo.HpoTerm) GitHubPopup(org.monarchinitiative.loinc2hpo.gui.GitHubPopup) FXML(javafx.fxml.FXML)

Example 3 with HPO_Class_Found

use of org.monarchinitiative.loinc2hpo.util.HPO_Class_Found in project loinc2hpo by monarch-initiative.

the class AnnotateTabController method handleManualQueryButton.

@FXML
private void handleManualQueryButton(ActionEvent e) {
    e.consume();
    if (SparqlQuery.model == null) {
        Alert alert = new Alert(Alert.AlertType.INFORMATION);
        alert.setTitle("HPO Model Undefined");
        alert.setHeaderText("Create HPO model first before querying");
        alert.setContentText("Click \"Initialize HPO model\" to create an" + " HPO model for Sparql query. Click and query again.");
        alert.showAndWait();
        return;
    }
    // for now, force user choose a loinc entry. TODO: user may or may not
    // choose a loinc term.
    LoincEntry entry = loincTableView.getSelectionModel().getSelectedItem();
    if (entry == null) {
        noLoincEntryAlert();
        return;
    }
    if (model.getLoincUnderEditing() != null && !model.getLoincUnderEditing().equals(entry)) {
        PopUps.showInfoMessage("You are currently editing " + model.getLoincUnderEditing().getLOINC_Number() + ". Save or cancel editing current loinc annotation before switching to others", "Under Editing mode");
        return;
    }
    String userInput = userInputForManualQuery.getText();
    if (userInput == null || userInput.trim().length() < 2) {
        Alert alert = new Alert(Alert.AlertType.INFORMATION);
        alert.setTitle("Input Error");
        alert.setHeaderText("Type in keys for manual query");
        alert.setContentText("Provide comma seperated keys for query. Do " + "not use quotes(\"\"). Avoid non-specific words " + "or numbers. Synonyms are strongly recommended if " + "auto-query is not working.");
        alert.showAndWait();
        return;
    }
    String[] keys = userInput.split(",");
    List<String> keysInList = new ArrayList<>();
    for (String key : keys) {
        if (key.length() > 0) {
            keysInList.add(key);
        }
    }
    String name = entry.getLongName();
    LoincCodeClass loincCodeClass = LoincLongNameParser.parse(name);
    List<HPO_Class_Found> queryResults = SparqlQuery.query_manual(keysInList, loincCodeClass);
    if (queryResults.size() != 0) {
        ObservableList<HPO_Class_Found> items = FXCollections.observableArrayList();
        for (HPO_Class_Found candidate : queryResults) {
            items.add(candidate);
        }
        this.hpoListView.setItems(items);
        userInputForManualQuery.clear();
    // items.add("0 result is found. Try manual search with synonyms.");
    } else {
        ObservableList<String> items = FXCollections.observableArrayList();
        items.add("0 HPO class is found. Try manual search with " + "alternative keys (synonyms)");
        this.hpoListView.setItems(items);
    }
    // clear text in abnormality text fields if not currently editing a term
    if (!createAnnotationButton.getText().equals("Save")) {
        // Got user feedback that they do not want to clear the field when doing manual query
        // clearAbnormalityTextField();
        // inialize the flag field
        flagForAnnotation.setIndeterminate(false);
        flagForAnnotation.setSelected(false);
        createAnnotationSuccess.setFill(Color.WHITE);
        annotationNoteField.setText("");
    }
}
Also used : HPO_Class_Found(org.monarchinitiative.loinc2hpo.util.HPO_Class_Found) LoincCodeClass(org.monarchinitiative.loinc2hpo.util.LoincCodeClass) FXML(javafx.fxml.FXML)

Example 4 with HPO_Class_Found

use of org.monarchinitiative.loinc2hpo.util.HPO_Class_Found 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 5 with HPO_Class_Found

use of org.monarchinitiative.loinc2hpo.util.HPO_Class_Found in project loinc2hpo by monarch-initiative.

the class SparqlQueryTest method testQuery_auto.

@Test
public void testQuery_auto() {
    // String loinc_name = "Testosterone Free [Mass/volume] in Serum or Plasma";
    // SparqlQuery.query_auto(loinc_name);
    // String loinc_name = "Erythrocyte distribution width [Ratio] in blood or serum by Automated count";
    // String loinc_name = "Carbon dioxide, total [Moles/volume] in Serum or Plasma";
    // List<HPO_Class_Found> hpo_clsses_found = new ArrayList<>();
    /**
     *        System.out.println("Find Carbon dioxide, total [Moles/volume] in Serum or Plasma: ");
     *        SparqlQuery.query_auto("Carbon dioxide, total [Moles/volume] in Serum or Plasma");
     *        System.out.println("Find Anion gap 3 in Serum or Plasma: ");
     *        SparqlQuery.query_auto("Anion gap 3 in Serum or Plasma");
     */
    // System.out.println("Find \"Potassium [Moles/volume] in Serum or Plasma\": ");
    List<HPO_Class_Found> hpo_clsses_found = SparqlQuery.query_auto("Potassium [Moles/volume] in Serum or Plasma");
    for (HPO_Class_Found HPO_class : hpo_clsses_found) {
        StringBuilder outContent = new StringBuilder();
        // outContent.append(newline);
        // outContent.append("\t");
        outContent.append(HPO_class.getScore() + "\t");
        outContent.append(HPO_class.getId() + "\t");
        outContent.append(HPO_class.getLabel() + "\t");
        if (HPO_class.getDefinition() != null) {
            outContent.append(HPO_class.getDefinition());
        }
        outContent.append("\n");
    // System.out.println(outContent.toString());
    }
}
Also used : HPO_Class_Found(org.monarchinitiative.loinc2hpo.util.HPO_Class_Found) Test(org.junit.Test)

Aggregations

HPO_Class_Found (org.monarchinitiative.loinc2hpo.util.HPO_Class_Found)8 FXML (javafx.fxml.FXML)4 SparqlQuery (org.monarchinitiative.loinc2hpo.util.SparqlQuery)4 HpoTerm (com.github.phenomics.ontolib.formats.hpo.HpoTerm)3 Test (org.junit.Test)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 Inject (com.google.inject.Inject)2 Injector (com.google.inject.Injector)2 Singleton (com.google.inject.Singleton)2 java.io (java.io)2 LocalDateTime (java.time.LocalDateTime)2 java.util (java.util)2 Platform (javafx.application.Platform)2 ReadOnlyStringWrapper (javafx.beans.property.ReadOnlyStringWrapper)2 FXCollections (javafx.collections.FXCollections)2 ListChangeListener (javafx.collections.ListChangeListener)2 ObservableList (javafx.collections.ObservableList)2 Task (javafx.concurrent.Task)2 ActionEvent (javafx.event.ActionEvent)2 Event (javafx.event.Event)2