Search in sources :

Example 1 with PostAnalysisFilterType

use of org.baderlab.csplugins.enrichmentmap.model.PostAnalysisFilterType in project EnrichmentMapApp by BaderLab.

the class CreateDiseaseSignatureTaskParallel method startBuildDiseaseSignatureParallel.

/**
	 * Returns immediately, need to wait on the executor to join all threads.
	 */
private Map<SimilarityKey, GenesetSimilarity> startBuildDiseaseSignatureParallel(TaskMonitor tm, ExecutorService executor, Set<String> enrichmentGeneSetNames, Map<String, GeneSet> signatureGeneSets) {
    DiscreteTaskMonitor taskMonitor = discreteTaskMonitor(tm, signatureGeneSets.size());
    // Gene universe is all enrichment genes in the map
    Set<Integer> geneUniverse = map.getAllEnrichmentGenes();
    Map<SimilarityKey, GenesetSimilarity> geneSetSimilarities = new ConcurrentHashMap<>();
    for (String hubName : signatureGeneSets.keySet()) {
        GeneSet sigGeneSet = signatureGeneSets.get(hubName);
        Set<Integer> sigGenesInUniverse = Sets.intersection(sigGeneSet.getGenes(), geneUniverse);
        // Compute similarities in batches
        executor.execute(() -> {
            loop: for (String geneSetName : enrichmentGeneSetNames) {
                for (EMDataSet dataSet : dataSets) {
                    if (Thread.interrupted())
                        break loop;
                    GeneSet enrGeneSet = dataSet.getSetOfGeneSets().getGeneSetByName(geneSetName);
                    if (enrGeneSet != null) {
                        // restrict to a common gene universe
                        Set<Integer> enrGenes = Sets.intersection(enrGeneSet.getGenes(), geneUniverse);
                        Set<Integer> union = Sets.union(sigGeneSet.getGenes(), enrGenes);
                        Set<Integer> intersection = Sets.intersection(sigGenesInUniverse, enrGenes);
                        if (!intersection.isEmpty()) {
                            double coeffecient = ComputeSimilarityTaskParallel.computeSimilarityCoeffecient(map.getParams(), intersection, union, sigGeneSet.getGenes(), enrGenes);
                            GenesetSimilarity comparison = new GenesetSimilarity(hubName, geneSetName, coeffecient, INTERACTION, intersection);
                            PostAnalysisFilterType filterType = params.getRankTestParameters().getType();
                            switch(filterType) {
                                case HYPERGEOM:
                                    int hyperUniverseSize1 = getHypergeometricUniverseSize(dataSet);
                                    hypergeometric(hyperUniverseSize1, sigGenesInUniverse, enrGenes, intersection, comparison);
                                    break;
                                case MANN_WHIT_TWO_SIDED:
                                case MANN_WHIT_GREATER:
                                case MANN_WHIT_LESS:
                                    mannWhitney(intersection, comparison, dataSet);
                                default:
                                    // want mann-whit to fall through
                                    // #70 calculate hypergeometric also
                                    int hyperUniverseSize2 = map.getNumberOfGenes();
                                    hypergeometric(hyperUniverseSize2, sigGenesInUniverse, enrGenes, intersection, comparison);
                                    break;
                            }
                            SimilarityKey key = new SimilarityKey(hubName, geneSetName, INTERACTION, dataSet.getName());
                            geneSetSimilarities.put(key, comparison);
                        }
                    }
                }
            }
            taskMonitor.inc();
        });
    }
    return geneSetSimilarities;
}
Also used : DiscreteTaskMonitor(org.baderlab.csplugins.enrichmentmap.util.DiscreteTaskMonitor) GeneSet(org.baderlab.csplugins.enrichmentmap.model.GeneSet) Set(java.util.Set) EMDataSet(org.baderlab.csplugins.enrichmentmap.model.EMDataSet) PostAnalysisFilterType(org.baderlab.csplugins.enrichmentmap.model.PostAnalysisFilterType) SimilarityKey(org.baderlab.csplugins.enrichmentmap.model.SimilarityKey) EMDataSet(org.baderlab.csplugins.enrichmentmap.model.EMDataSet) GenesetSimilarity(org.baderlab.csplugins.enrichmentmap.model.GenesetSimilarity) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) GeneSet(org.baderlab.csplugins.enrichmentmap.model.GeneSet)

Example 2 with PostAnalysisFilterType

use of org.baderlab.csplugins.enrichmentmap.model.PostAnalysisFilterType in project EnrichmentMapApp by BaderLab.

the class PostAnalysisSignatureDiscoveryPanel method createSignatureDiscoveryGMTPanel.

/**
     * @return Panel for choosing and loading GMT and SignatureGMT Geneset-Files 
     */
private JPanel createSignatureDiscoveryGMTPanel() {
    signatureDiscoveryGMTFileNameTextField = new JFormattedTextField();
    signatureDiscoveryGMTFileNameTextField.setColumns(15);
    signatureDiscoveryGMTFileNameTextField.setToolTipText(Messages.GMT_INSTRUCTION);
    final Color textFieldForeground = signatureDiscoveryGMTFileNameTextField.getForeground();
    signatureDiscoveryGMTFileNameTextField.addPropertyChangeListener("value", (PropertyChangeEvent e) -> {
        // if the text is red set it back to black as soon as the user starts typing
        signatureDiscoveryGMTFileNameTextField.setForeground(textFieldForeground);
    });
    JButton selectSigGMTFileButton = new JButton("Browse...");
    selectSigGMTFileButton.setToolTipText(Messages.GMT_INSTRUCTION);
    selectSigGMTFileButton.setActionCommand("Signature Discovery");
    selectSigGMTFileButton.addActionListener((ActionEvent evt) -> {
        parentPanel.chooseGMTFile(signatureDiscoveryGMTFileNameTextField);
    });
    JLabel filterLabel = new JLabel("Filter:");
    filterTextField = new JFormattedTextField();
    filterTextField.setColumns(4);
    filterTextField.setHorizontalAlignment(JTextField.RIGHT);
    filterTextField.addPropertyChangeListener("value", (PropertyChangeEvent e) -> {
        StringBuilder message = new StringBuilder("The value you have entered is invalid.\n");
        Number number = (Number) filterTextField.getValue();
        PostAnalysisFilterType filterType = getFilterType();
        Optional<Double> value = PostAnalysisInputPanel.validateAndGetFilterValue(number, filterType, message);
        savedFilterValues.put(filterType, value.orElse(filterType.defaultValue));
        if (!value.isPresent()) {
            filterTextField.setValue(filterType.defaultValue);
            JOptionPane.showMessageDialog(application.getJFrame(), message.toString(), "Parameter out of bounds", JOptionPane.WARNING_MESSAGE);
        }
    });
    // Types of filters:
    // 1. filter by percent, i.e. the overlap between the signature geneset and EM geneset
    //    has to be X percentage of the EM set it overlaps with for at least one geneset in the enrichment map.
    // 2. filter by number, i.e. the overlap between the signature geneset and EM geneset
    //    has to be X genes of the EM set it overlaps with for at least one geneset in the enrichment map.
    // 3. filter by specificity, i.e looking for the signature genesets that are more specific than other genesets
    //    for instance a drug A that targets only X and Y as opposed to drug B that targets X,y,L,M,N,O,P.
    filterTypeCombo = new JComboBox<>();
    // default
    filterTypeCombo.addItem(PostAnalysisFilterType.NO_FILTER);
    //		filterTypeCombo.addItem(PostAnalysisFilterType.MANN_WHIT_TWO_SIDED);
    //		filterTypeCombo.addItem(PostAnalysisFilterType.MANN_WHIT_GREATER);
    //		filterTypeCombo.addItem(PostAnalysisFilterType.MANN_WHIT_LESS);
    filterTypeCombo.addItem(PostAnalysisFilterType.HYPERGEOM);
    filterTypeCombo.addItem(PostAnalysisFilterType.NUMBER);
    filterTypeCombo.addItem(PostAnalysisFilterType.PERCENT);
    filterTypeCombo.addItem(PostAnalysisFilterType.SPECIFIC);
    filterTypeCombo.addActionListener(e -> {
        updateFilterTextField();
    });
    updateFilterTextField();
    //TODO: Maybe move loading SigGMT to File-selection Event add load button
    JButton loadButton = new JButton();
    loadButton.setText("Load Gene Sets");
    loadButton.addActionListener(e -> {
        String filePath = (String) signatureDiscoveryGMTFileNameTextField.getValue();
        if (filePath == null || PostAnalysisInputPanel.checkFile(filePath).equals(Color.RED)) {
            String message = "Signature GMT file name not valid.\n";
            signatureDiscoveryGMTFileNameTextField.setForeground(Color.RED);
            JOptionPane.showMessageDialog(application.getJFrame(), message, "Post Analysis Known Signature", JOptionPane.WARNING_MESSAGE);
            return;
        }
        if (!EnrichmentMapParameters.checkFile(filePath)) {
            String message = "Signature GMT does not exist.\n";
            signatureDiscoveryGMTFileNameTextField.setForeground(Color.RED);
            JOptionPane.showMessageDialog(application.getJFrame(), message, "Post Analysis Known Signature", JOptionPane.WARNING_MESSAGE);
            return;
        }
        FilterMetric filterMetric = createFilterMetric();
        LoadSignatureSetsActionListener action = loadSignatureSetsActionListenerFactory.create(new File(filePath), filterMetric, parentPanel.getEnrichmentMap());
        action.setGeneSetCallback(gs -> {
            this.signatureGenesets = gs;
        });
        action.setFilteredSignatureSetsCallback(selected -> {
            availSigSetsModel.clear();
            selectedSigSetsModel.clear();
            for (String name : selected) availSigSetsModel.addElement(name);
            update();
        });
        action.actionPerformed(null);
    });
    makeSmall(signatureDiscoveryGMTFileNameTextField, selectSigGMTFileButton);
    makeSmall(filterLabel, filterTypeCombo, filterTextField);
    makeSmall(loadButton);
    JPanel panel = new JPanel();
    panel.setBorder(LookAndFeelUtil.createTitledBorder("SigGMT File (contains signature-genesets)"));
    final GroupLayout layout = new GroupLayout(panel);
    panel.setLayout(layout);
    layout.setAutoCreateContainerGaps(true);
    layout.setAutoCreateGaps(!LookAndFeelUtil.isAquaLAF());
    layout.setHorizontalGroup(layout.createParallelGroup(Alignment.CENTER, true).addGroup(layout.createSequentialGroup().addComponent(signatureDiscoveryGMTFileNameTextField, DEFAULT_SIZE, DEFAULT_SIZE, Short.MAX_VALUE).addComponent(selectSigGMTFileButton, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE)).addGroup(layout.createSequentialGroup().addComponent(filterLabel, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE).addComponent(filterTypeCombo, DEFAULT_SIZE, DEFAULT_SIZE, Short.MAX_VALUE).addComponent(filterTextField, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE)).addComponent(loadButton, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE));
    layout.setVerticalGroup(layout.createSequentialGroup().addGroup(layout.createParallelGroup(Alignment.CENTER, false).addComponent(signatureDiscoveryGMTFileNameTextField, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE).addComponent(selectSigGMTFileButton)).addGroup(layout.createParallelGroup(Alignment.CENTER, false).addComponent(filterLabel, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE).addComponent(filterTypeCombo, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE).addComponent(filterTextField, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE)).addComponent(loadButton, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE));
    if (LookAndFeelUtil.isAquaLAF())
        panel.setOpaque(false);
    return panel;
}
Also used : JPanel(javax.swing.JPanel) PropertyChangeEvent(java.beans.PropertyChangeEvent) PostAnalysisFilterType(org.baderlab.csplugins.enrichmentmap.model.PostAnalysisFilterType) ActionEvent(java.awt.event.ActionEvent) Color(java.awt.Color) JFormattedTextField(javax.swing.JFormattedTextField) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) FilterMetric(org.baderlab.csplugins.enrichmentmap.task.postanalysis.FilterMetric) LoadSignatureSetsActionListener(org.baderlab.csplugins.enrichmentmap.actions.LoadSignatureSetsActionListener) GroupLayout(javax.swing.GroupLayout) File(java.io.File)

Example 3 with PostAnalysisFilterType

use of org.baderlab.csplugins.enrichmentmap.model.PostAnalysisFilterType in project EnrichmentMapApp by BaderLab.

the class PostAnalysisWeightPanel method initialize.

void initialize(EnrichmentMap currentMap) {
    this.map = currentMap;
    datasetModel.removeAllElements();
    datasetModel.addElement("-- All Data Sets --");
    for (String dataset : map.getDataSetNames()) {
        datasetModel.addElement(dataset);
    }
    datasetCombo.setEnabled(datasetModel.getSize() > 2);
    if (datasetModel.getSize() > 0) {
        datasetCombo.setSelectedIndex(0);
    }
    Map<String, Ranking> rankingMap = map.getAllRanks();
    String[] rankingArray = rankingMap.keySet().toArray(new String[rankingMap.size()]);
    Arrays.sort(rankingArray);
    PostAnalysisFilterType typeToUse = rankingArray.length == 0 ? PostAnalysisFilterType.HYPERGEOM : PostAnalysisFilterType.MANN_WHIT_TWO_SIDED;
    rankTestCombo.setSelectedItem(typeToUse);
    rankTestTextField.setValue(typeToUse.defaultValue);
    rankingEnablementRenderer.enableAll();
    if (rankingArray.length == 0) {
        rankingEnablementRenderer.disableItems(PostAnalysisFilterType.MANN_WHIT_TWO_SIDED, PostAnalysisFilterType.MANN_WHIT_LESS, PostAnalysisFilterType.MANN_WHIT_GREATER);
    }
}
Also used : Ranking(org.baderlab.csplugins.enrichmentmap.model.Ranking) PostAnalysisFilterType(org.baderlab.csplugins.enrichmentmap.model.PostAnalysisFilterType)

Example 4 with PostAnalysisFilterType

use of org.baderlab.csplugins.enrichmentmap.model.PostAnalysisFilterType in project EnrichmentMapApp by BaderLab.

the class PostAnalysisWeightPanel method reset.

void reset() {
    gmtRadioButton.setSelected(true);
    PostAnalysisFilterType filterType = PostAnalysisFilterType.MANN_WHIT_TWO_SIDED;
    rankTestCombo.setSelectedItem(filterType);
    rankTestTextField.setValue(filterType.defaultValue);
    savedFilterValues = PostAnalysisFilterType.createMapOfDefaults();
    savedFilterValues.put(PostAnalysisFilterType.HYPERGEOM, HYPERGOM_DEFAULT);
}
Also used : PostAnalysisFilterType(org.baderlab.csplugins.enrichmentmap.model.PostAnalysisFilterType)

Example 5 with PostAnalysisFilterType

use of org.baderlab.csplugins.enrichmentmap.model.PostAnalysisFilterType in project EnrichmentMapApp by BaderLab.

the class PostAnalysisSignatureDiscoveryPanel method updateFilterTextField.

private void updateFilterTextField() {
    PostAnalysisFilterType filterType = (PostAnalysisFilterType) filterTypeCombo.getSelectedItem();
    filterTextField.setValue(savedFilterValues.get(filterType));
    filterTextField.setEnabled(filterType != PostAnalysisFilterType.NO_FILTER);
}
Also used : PostAnalysisFilterType(org.baderlab.csplugins.enrichmentmap.model.PostAnalysisFilterType)

Aggregations

PostAnalysisFilterType (org.baderlab.csplugins.enrichmentmap.model.PostAnalysisFilterType)10 GroupLayout (javax.swing.GroupLayout)2 JFormattedTextField (javax.swing.JFormattedTextField)2 JLabel (javax.swing.JLabel)2 JPanel (javax.swing.JPanel)2 EnrichmentMap (org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap)2 GenesetSimilarity (org.baderlab.csplugins.enrichmentmap.model.GenesetSimilarity)2 CyRow (org.cytoscape.model.CyRow)2 CardLayout (java.awt.CardLayout)1 Color (java.awt.Color)1 ActionEvent (java.awt.event.ActionEvent)1 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 File (java.io.File)1 DecimalFormat (java.text.DecimalFormat)1 ArrayList (java.util.ArrayList)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 JButton (javax.swing.JButton)1 LoadSignatureSetsActionListener (org.baderlab.csplugins.enrichmentmap.actions.LoadSignatureSetsActionListener)1 EMDataSet (org.baderlab.csplugins.enrichmentmap.model.EMDataSet)1