Search in sources :

Example 1 with Model

use of org.monarchinitiative.loinc2hpo.model.Model 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 2 with Model

use of org.monarchinitiative.loinc2hpo.model.Model in project loinc2hpo by monarch-initiative.

the class MainController method initialize.

@FXML
private void initialize() {
    Platform.runLater(() -> {
        annotateTabButton.setDisable(true);
        Loinc2HPOAnnotationsTabButton.setDisable(true);
        Loinc2HpoConversionTabButton.setDisable(true);
    });
    configurationComplete.addListener(new ChangeListener<Boolean>() {

        @Override
        public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
            if (newValue.booleanValue()) {
                Platform.runLater(() -> {
                    annotateTabButton.setDisable(false);
                    Loinc2HPOAnnotationsTabButton.setDisable(false);
                    Loinc2HpoConversionTabButton.setDisable(false);
                });
            }
        }
    });
    this.model = new Model();
    // read in settings from file
    File settings = getPathToSettingsFileAndEnsurePathExists();
    model.setPathToSettingsFile(settings.getAbsolutePath());
    if (settings.exists()) {
        model.inputSettings(settings.getAbsolutePath());
        configurationComplete.setValue(isConfigurationCompleted());
    }
    // set it to the default path. user can still change it
    if (model.getPathToAutoSavedFolder() == null) {
        model.setPathToAutoSavedFolder(Loinc2HpoPlatform.getLOINC2HPODir() + File.separator + "Data");
        File folder = new File(model.getPathToAutoSavedFolder());
        boolean created = false;
        if (!folder.exists()) {
            created = folder.mkdir();
        }
        if (created) {
            model.writeSettings();
        }
        configurationComplete.set(isConfigurationCompleted());
    }
    if (setupTabController == null) {
        logger.error("setupTabController is null");
        return;
    }
    setupTabController.setModel(model);
    if (annotateTabController == null) {
        logger.error("annotate Controller is null");
        return;
    }
    annotateTabController.setModel(model);
    if (loinc2HpoAnnotationsTabController == null) {
        logger.error("loinc2HpoAnnotationsTabController is null");
        return;
    }
    if (loinc2HPOConversionTabController == null) {
        logger.error("loinc2HPOConversionTabController is null");
        return;
    }
    currentAnnotationController.setModel(model);
    if (model == null) {
        logger.error("main controller model is null");
        return;
    }
    loinc2HpoAnnotationsTabController.setModel(model);
    loinc2HPOConversionTabController.setModel(model);
    if (Loinc2HpoPlatform.isMacintosh()) {
        loincmenubar.useSystemMenuBarProperty().set(true);
    }
    // control how menu items should be shown
    importAnnotationButton.setDisable(true);
    exportMenu.setDisable(true);
    tabPane.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Tab>() {

        @Override
        public void changed(ObservableValue<? extends Tab> observable, Tab oldValue, Tab newValue) {
            if (newValue.equals(Loinc2HPOAnnotationsTabButton)) {
                importAnnotationButton.setDisable(false);
                exportMenu.setDisable(false);
                clearMenu.setDisable(false);
            } else {
                importAnnotationButton.setDisable(true);
                exportMenu.setDisable(true);
                clearMenu.setDisable(true);
            }
        }
    });
    if (configurationComplete.get()) {
        annotateTabController.defaultStartUp();
        defaultStartup();
        if (model.getPathToLastSession() != null) {
            openSession(model.getPathToLastSession());
        }
    }
    // @TODO: to decide whether to remove the following menuitems
    importLoincCategory.setVisible(false);
    exportLoincCategory.setVisible(false);
    saveAnnotationsMenuItem.setVisible(false);
    saveAnnotationsAsMenuItem.setVisible(false);
    appendAnnotationsToMenuItem.setVisible(false);
    clearMenu.setVisible(false);
}
Also used : Model(org.monarchinitiative.loinc2hpo.model.Model) WriteToFile(org.monarchinitiative.loinc2hpo.io.WriteToFile) FXML(javafx.fxml.FXML)

Example 3 with Model

use of org.monarchinitiative.loinc2hpo.model.Model in project loinc2hpo by monarch-initiative.

the class CurrentAnnotationController method populateTables.

private void populateTables() {
    if (model == null) {
        logger.error("model is null.");
        return;
    }
    this.currentAnnotation = model.getCurrentAnnotation();
    LoincEntry currentLoincEntry = model.getLoincEntryMap().get(currentAnnotation.getLoincId());
    annotationTitle.setText(String.format("Annotations for Loinc: %s[%s]", currentLoincEntry.getLOINC_Number(), currentLoincEntry.getLongName()));
    internalCodeAnnotations.clear();
    currentAnnotation.getCandidateHpoTerms().entrySet().stream().filter(p -> p.getKey().getSystem().equals(Loinc2HPOCodedValue.CODESYSTEM)).map(p -> new Annotation(p.getKey(), p.getValue())).forEach(internalCodeAnnotations::add);
    externalCodeAnnotations.clear();
    currentAnnotation.getCandidateHpoTerms().entrySet().stream().filter(p -> !p.getKey().getSystem().equals(Loinc2HPOCodedValue.CODESYSTEM)).map(p -> new Annotation(p.getKey(), p.getValue())).forEach(externalCodeAnnotations::add);
    interpretationCodeAnnotations.clear();
    for (Map.Entry<Code, Code> entry : CodeSystemConvertor.getCodeConversionMap().entrySet()) {
        logger.debug("key: " + entry.getKey() + "\nvalue: " + entry.getValue());
        HpoTermId4LoincTest result = currentAnnotation.loincInterpretationToHPO(entry.getValue());
        logger.debug("result is null? " + (result == null));
        if (result != null) {
            Annotation annotation = new Annotation(entry.getKey(), result);
            interpretationCodeAnnotations.add(annotation);
            logger.debug("interpretationCodeAnnotations size: " + interpretationCodeAnnotations.size());
        }
    }
    logger.debug("internalTableview is null: " + (internalTableview == null));
    logger.debug("internalCodeAnnotations is null: " + (internalTableview == null));
    logger.debug("internal annotation size: " + internalCodeAnnotations.size());
    internalCodeAnnotations.forEach(logger::info);
    logger.trace("exit initInternalTableview()");
}
Also used : javafx.scene.control(javafx.scene.control) Inject(com.google.inject.Inject) Node(javafx.scene.Node) Loinc2HPOCodedValue(org.monarchinitiative.loinc2hpo.codesystems.Loinc2HPOCodedValue) Model(org.monarchinitiative.loinc2hpo.model.Model) FXCollections(javafx.collections.FXCollections) LoincEntry(org.monarchinitiative.loinc2hpo.loinc.LoincEntry) ReadOnlyStringWrapper(javafx.beans.property.ReadOnlyStringWrapper) FXML(javafx.fxml.FXML) ActionEvent(javafx.event.ActionEvent) Logger(org.apache.logging.log4j.Logger) HpoTermId4LoincTest(org.monarchinitiative.loinc2hpo.loinc.HpoTermId4LoincTest) UniversalLoinc2HPOAnnotation(org.monarchinitiative.loinc2hpo.loinc.UniversalLoinc2HPOAnnotation) ReadOnlyBooleanWrapper(javafx.beans.property.ReadOnlyBooleanWrapper) Stage(javafx.stage.Stage) CodeSystemConvertor(org.monarchinitiative.loinc2hpo.codesystems.CodeSystemConvertor) Annotation(org.monarchinitiative.loinc2hpo.model.Annotation) Map(java.util.Map) Code(org.monarchinitiative.loinc2hpo.codesystems.Code) ObservableList(javafx.collections.ObservableList) BorderPane(javafx.scene.layout.BorderPane) LogManager(org.apache.logging.log4j.LogManager) Singleton(com.google.inject.Singleton) LoincEntry(org.monarchinitiative.loinc2hpo.loinc.LoincEntry) HpoTermId4LoincTest(org.monarchinitiative.loinc2hpo.loinc.HpoTermId4LoincTest) Map(java.util.Map) Code(org.monarchinitiative.loinc2hpo.codesystems.Code) UniversalLoinc2HPOAnnotation(org.monarchinitiative.loinc2hpo.loinc.UniversalLoinc2HPOAnnotation) Annotation(org.monarchinitiative.loinc2hpo.model.Annotation)

Aggregations

FXML (javafx.fxml.FXML)3 Model (org.monarchinitiative.loinc2hpo.model.Model)3 Inject (com.google.inject.Inject)2 Singleton (com.google.inject.Singleton)2 ReadOnlyStringWrapper (javafx.beans.property.ReadOnlyStringWrapper)2 FXCollections (javafx.collections.FXCollections)2 ObservableList (javafx.collections.ObservableList)2 ActionEvent (javafx.event.ActionEvent)2 javafx.scene.control (javafx.scene.control)2 LogManager (org.apache.logging.log4j.LogManager)2 Logger (org.apache.logging.log4j.Logger)2 Code (org.monarchinitiative.loinc2hpo.codesystems.Code)2 CodeSystemConvertor (org.monarchinitiative.loinc2hpo.codesystems.CodeSystemConvertor)2 Loinc2HPOCodedValue (org.monarchinitiative.loinc2hpo.codesystems.Loinc2HPOCodedValue)2 WriteToFile (org.monarchinitiative.loinc2hpo.io.WriteToFile)2 HpoTerm (com.github.phenomics.ontolib.formats.hpo.HpoTerm)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Injector (com.google.inject.Injector)1 java.io (java.io)1 LocalDateTime (java.time.LocalDateTime)1