Search in sources :

Example 6 with PostAnalysisFilterType

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

the class PostAnalysisSignatureDiscoveryPanel method createFilterMetric.

private FilterMetric createFilterMetric() {
    Number number = (Number) filterTextField.getValue();
    double value = number.doubleValue();
    PostAnalysisFilterType type = getFilterType();
    switch(type) {
        case NUMBER:
            return new FilterMetric.Number(value);
        case PERCENT:
            return new FilterMetric.Percent(value);
        case SPECIFIC:
            return new FilterMetric.Specific(value);
        case HYPERGEOM:
            return new FilterMetric.Hypergeom(value, hypergomUniverseSize);
        //				return new FilterMetric.MannWhit(value, mannWhitRanks, type);
        default:
            return new FilterMetric.None();
    }
}
Also used : PostAnalysisFilterType(org.baderlab.csplugins.enrichmentmap.model.PostAnalysisFilterType)

Example 7 with PostAnalysisFilterType

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

the class PostAnalysisWeightPanel method createRankTestSelectPanel.

@SuppressWarnings("unchecked")
private JPanel createRankTestSelectPanel() {
    JLabel testLabel = new JLabel(LABEL_TEST);
    JLabel cuttofLabel = new JLabel(LABEL_CUTOFF);
    JLabel dataSetLabel = new JLabel("Data Set:");
    DecimalFormat decFormat = new DecimalFormat();
    decFormat.setParseIntegerOnly(false);
    rankTestTextField = new JFormattedTextField(decFormat);
    rankTestTextField.setColumns(6);
    rankTestTextField.setHorizontalAlignment(JTextField.RIGHT);
    rankTestTextField.addPropertyChangeListener("value", e -> {
        StringBuilder message = new StringBuilder("The value you have entered is invalid.\n");
        Number number = (Number) rankTestTextField.getValue();
        PostAnalysisFilterType filterType = getFilterType();
        Optional<Double> value = PostAnalysisInputPanel.validateAndGetFilterValue(number, filterType, message);
        double def = filterType == PostAnalysisFilterType.HYPERGEOM ? HYPERGOM_DEFAULT : filterType.defaultValue;
        savedFilterValues.put(filterType, value.orElse(def));
        if (!value.isPresent()) {
            rankTestTextField.setValue(def);
            CySwingApplication application = serviceRegistrar.getService(CySwingApplication.class);
            JOptionPane.showMessageDialog(application.getJFrame(), message.toString(), "Parameter out of bounds", JOptionPane.WARNING_MESSAGE);
        }
    });
    rankingEnablementRenderer = new EnablementComboBoxRenderer<>();
    rankTestCombo = new JComboBox<>();
    rankTestCombo.setRenderer(rankingEnablementRenderer);
    rankTestCombo.addItem(PostAnalysisFilterType.MANN_WHIT_TWO_SIDED);
    rankTestCombo.addItem(PostAnalysisFilterType.MANN_WHIT_GREATER);
    rankTestCombo.addItem(PostAnalysisFilterType.MANN_WHIT_LESS);
    rankTestCombo.addItem(PostAnalysisFilterType.HYPERGEOM);
    rankTestCombo.addItem(PostAnalysisFilterType.NUMBER);
    rankTestCombo.addItem(PostAnalysisFilterType.PERCENT);
    rankTestCombo.addItem(PostAnalysisFilterType.SPECIFIC);
    rankTestCombo.addActionListener(e -> {
        PostAnalysisFilterType filterType = (PostAnalysisFilterType) rankTestCombo.getSelectedItem();
        rankTestTextField.setValue(savedFilterValues.get(filterType));
        CardLayout cardLayout = (CardLayout) cardPanel.getLayout();
        if (filterType.isMannWhitney() && map.getAllRanks().isEmpty())
            cardLayout.show(cardPanel, "warn");
        else
            cardLayout.show(cardPanel, filterType.name());
    });
    datasetCombo = new JComboBox<>();
    // Dataset model is already initialized
    datasetModel = new DefaultComboBoxModel<>();
    datasetCombo.setModel(datasetModel);
    datasetCombo.addActionListener(e -> {
        updateUniverseSize(getDataSet());
    });
    makeSmall(testLabel, cuttofLabel, rankTestCombo, rankTestTextField);
    makeSmall(dataSetLabel, datasetCombo);
    JPanel panel = new JPanel();
    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().addGroup(layout.createParallelGroup(Alignment.TRAILING, true).addComponent(testLabel).addComponent(cuttofLabel).addComponent(dataSetLabel)).addGroup(layout.createParallelGroup(Alignment.LEADING, true).addComponent(rankTestCombo, DEFAULT_SIZE, DEFAULT_SIZE, Short.MAX_VALUE).addComponent(rankTestTextField, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE).addComponent(datasetCombo, DEFAULT_SIZE, DEFAULT_SIZE, Short.MAX_VALUE))));
    layout.setVerticalGroup(layout.createSequentialGroup().addGroup(layout.createParallelGroup(Alignment.CENTER, false).addComponent(testLabel).addComponent(rankTestCombo, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE)).addGroup(layout.createParallelGroup(Alignment.CENTER, false).addComponent(cuttofLabel).addComponent(rankTestTextField, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE)).addPreferredGap(ComponentPlacement.UNRELATED).addGroup(layout.createParallelGroup(Alignment.CENTER, false).addComponent(dataSetLabel).addComponent(datasetCombo, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE)));
    if (LookAndFeelUtil.isAquaLAF())
        panel.setOpaque(false);
    return panel;
}
Also used : CardLayout(java.awt.CardLayout) JPanel(javax.swing.JPanel) PostAnalysisFilterType(org.baderlab.csplugins.enrichmentmap.model.PostAnalysisFilterType) CySwingApplication(org.cytoscape.application.swing.CySwingApplication) DecimalFormat(java.text.DecimalFormat) JFormattedTextField(javax.swing.JFormattedTextField) JLabel(javax.swing.JLabel) GroupLayout(javax.swing.GroupLayout)

Example 8 with PostAnalysisFilterType

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

the class PAKnownSignatureCommandTask method run.

@Override
public void run(TaskMonitor taskMonitor) throws Exception {
    if (gmtFile == null || !gmtFile.canRead())
        throw new IllegalArgumentException("Signature GMT file name not valid");
    CyNetwork selectedNetwork;
    CyNetworkView selectedView;
    if (network == null) {
        selectedNetwork = applicationManager.getCurrentNetwork();
        selectedView = applicationManager.getCurrentNetworkView();
        if (selectedNetwork == null || selectedView == null) {
            throw new IllegalArgumentException("Current network not available.");
        }
    } else {
        selectedNetwork = network;
        Collection<CyNetworkView> networkViews = networkViewManager.getNetworkViews(network);
        if (networkViews == null || networkViews.isEmpty()) {
            throw new IllegalArgumentException("No network view for: " + network);
        }
        selectedView = networkViews.iterator().next();
    }
    EnrichmentMap map = emManager.getEnrichmentMap(selectedNetwork.getSUID());
    if (map == null)
        throw new IllegalArgumentException("Network is not an Enrichment Map.");
    loadGeneSets(map);
    PostAnalysisFilterType filter = PostAnalysisFilterType.valueOf(filterType.getSelectedValue());
    UniverseType universe = UniverseType.valueOf(hypergeomUniverseType.getSelectedValue());
    PostAnalysisParameters.Builder builder = new PostAnalysisParameters.Builder();
    builder.setAttributePrefix(map.getParams().getAttributePrefix());
    builder.setSignatureGMTFileName(gmtFile.getAbsolutePath());
    builder.setLoadedGMTGeneSets(signatureGenesets);
    builder.addSelectedGeneSetNames(selectedGenesetNames);
    builder.setUniverseType(universe);
    builder.setUserDefinedUniverseSize(userDefinedUniverseSize);
    builder.setRankTestParameters(new PostAnalysisFilterParameters(filter, cutoff));
    builder.setName(name);
    if (isBatch()) {
        // run in batch mode
        builder.setDataSetName(null);
    } else {
        if (map.getDataSet(dataSetName) == null) {
            throw new IllegalArgumentException("Data set name not valid: '" + dataSetName + "'");
        }
        builder.setDataSetName(dataSetName);
    }
    // Mann-Whitney requires ranks
    if (filter.isMannWhitney()) {
        processMannWhitneyArgs(map, builder);
    }
    TaskFactory taskFactory = taskFactoryFactory.create(selectedView, builder.build());
    TaskIterator taskIterator = new TaskIterator();
    taskIterator.append(taskFactory.createTaskIterator());
    Task updatePanelTask = new AbstractTask() {

        @Override
        public void run(TaskMonitor taskMonitor) {
            controlPanelMediatorProvider.get().updateDataSetList(selectedView);
            selectedView.updateView();
        }
    };
    taskIterator.append(updatePanelTask);
    insertTasksAfterCurrentTask(taskIterator);
}
Also used : Task(org.cytoscape.work.Task) AbstractTask(org.cytoscape.work.AbstractTask) UniverseType(org.baderlab.csplugins.enrichmentmap.model.PostAnalysisParameters.UniverseType) AbstractTask(org.cytoscape.work.AbstractTask) PostAnalysisFilterType(org.baderlab.csplugins.enrichmentmap.model.PostAnalysisFilterType) PostAnalysisFilterParameters(org.baderlab.csplugins.enrichmentmap.model.PostAnalysisFilterParameters) CyNetwork(org.cytoscape.model.CyNetwork) EnrichmentMap(org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap) PostAnalysisParameters(org.baderlab.csplugins.enrichmentmap.model.PostAnalysisParameters) TaskIterator(org.cytoscape.work.TaskIterator) TaskMonitor(org.cytoscape.work.TaskMonitor) CreateDiseaseSignatureTaskFactory(org.baderlab.csplugins.enrichmentmap.task.postanalysis.CreateDiseaseSignatureTaskFactory) TaskFactory(org.cytoscape.work.TaskFactory) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Example 9 with PostAnalysisFilterType

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

the class CreateDiseaseSignatureNetworkTask method createEdge.

/**
	 * Returns true iff the user should be warned about an existing edge that
	 * does not pass the new cutoff. If the edge already exists it will be
	 * returned, if the edge had to be created it will not be returned.
	 */
private void createEdge(SimilarityKey similarityKey, CyNetwork network, CyNetworkView netView, String prefix, CyTable edgeTable, CyTable nodeTable, boolean passedCutoff, EMSignatureDataSet sigDataSet) {
    // PA always generates distinct edges
    final String edgeName = similarityKey.toString();
    GenesetSimilarity genesetSimilarity = geneSetSimilarities.get(similarityKey);
    CyEdge edge = existingEdgeCache.get(new EdgeCacheKey(edgeName, sigDataSet.getName()));
    if (edge == null) {
        if (passedCutoff) {
            CyNode hubNode = nodeCache.get(genesetSimilarity.getGeneset1Name());
            CyNode geneSet = NetworkUtil.getNodeWithValue(network, nodeTable, CyNetwork.NAME, genesetSimilarity.getGeneset2Name());
            if (hubNode == null || geneSet == null)
                return;
            edge = network.addEdge(hubNode, geneSet, false);
            // We actually add the edges to the EM data sets, not the signature data set
            sigDataSet.addEdgeSuid(edge.getSUID());
            //				map.getDataSet(similarityKey.getName()).addEdgeSuid(edge.getSUID());
            taskResult.addNewEdge(edge);
        } else {
            // edge does not exist and does not pass cutoff, do nothing
            return;
        }
    } else {
        if (!passedCutoff && existingEdgeCache.containsKey(edgeName))
            taskResult.addExistingEdgeFailsCutoff(edge);
    }
    if (passedCutoff)
        taskResult.incrementPassedCutoffCount();
    CyRow row = edgeTable.getRow(edge.getSUID());
    row.set(CyNetwork.NAME, edgeName);
    row.set(CyEdge.INTERACTION, similarityKey.getInteraction());
    List<String> geneList = new ArrayList<>();
    Set<Integer> genesHash = genesetSimilarity.getOverlappingGenes();
    for (Integer current : genesHash) {
        String gene = map.getGeneFromHashKey(current);
        if (gene != null)
            geneList.add(gene);
    }
    Collections.sort(geneList);
    Columns.EDGE_OVERLAP_GENES.set(row, prefix, null, geneList);
    Columns.EDGE_OVERLAP_SIZE.set(row, prefix, null, genesetSimilarity.getSizeOfOverlap());
    Columns.EDGE_SIMILARITY_COEFF.set(row, prefix, null, genesetSimilarity.getSimilarityCoeffecient());
    Columns.EDGE_DATASET.set(row, prefix, null, similarityKey.getName());
    Columns.EDGE_SIG_DATASET.set(row, prefix, null, sigDataSet.getName());
    if (passedCutoff)
        Columns.EDGE_CUTOFF_TYPE.set(row, prefix, null, params.getRankTestParameters().getType().display);
    PostAnalysisFilterType filterType = params.getRankTestParameters().getType();
    if (filterType.isMannWhitney()) {
        Columns.EDGE_MANN_WHIT_TWOSIDED_PVALUE.set(row, prefix, null, genesetSimilarity.getMannWhitPValueTwoSided());
        Columns.EDGE_MANN_WHIT_GREATER_PVALUE.set(row, prefix, null, genesetSimilarity.getMannWhitPValueGreater());
        Columns.EDGE_MANN_WHIT_LESS_PVALUE.set(row, prefix, null, genesetSimilarity.getMannWhitPValueLess());
        Columns.EDGE_MANN_WHIT_CUTOFF.set(row, prefix, null, params.getRankTestParameters().getValue());
    }
    // always calculate hypergeometric
    Columns.EDGE_HYPERGEOM_PVALUE.set(row, prefix, null, genesetSimilarity.getHypergeomPValue());
    Columns.EDGE_HYPERGEOM_U.set(row, prefix, null, genesetSimilarity.getHypergeomU());
    Columns.EDGE_HYPERGEOM_N.set(row, prefix, null, genesetSimilarity.getHypergeomN());
    Columns.EDGE_HYPERGEOM_M.set(row, prefix, null, genesetSimilarity.getHypergeomM());
    Columns.EDGE_HYPERGEOM_K.set(row, prefix, null, genesetSimilarity.getHypergeomK());
    Columns.EDGE_HYPERGEOM_CUTOFF.set(row, prefix, null, params.getRankTestParameters().getValue());
}
Also used : PostAnalysisFilterType(org.baderlab.csplugins.enrichmentmap.model.PostAnalysisFilterType) ArrayList(java.util.ArrayList) CyNode(org.cytoscape.model.CyNode) GenesetSimilarity(org.baderlab.csplugins.enrichmentmap.model.GenesetSimilarity) CyRow(org.cytoscape.model.CyRow) CyEdge(org.cytoscape.model.CyEdge)

Example 10 with PostAnalysisFilterType

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

the class WidthFunction method calculateAndSetEdgeWidths.

private void calculateAndSetEdgeWidths(CyNetwork network, String prefix, TaskMonitor taskMonitor) {
    EdgeWidthParams edgeWidthParams = EdgeWidthParams.restore(network);
    EnrichmentMap map = emManager.getEnrichmentMap(network.getSUID());
    //		String widthAttribute = prefix + EDGE_WIDTH_FORMULA_COLUMN;
    int n = network.getDefaultEdgeTable().getRowCount();
    int i = 0;
    for (CyRow row : network.getDefaultEdgeTable().getAllRows()) {
        if (taskMonitor != null)
            taskMonitor.setProgress((double) i / (double) n);
        i++;
        String interaction = row.get(CyEdge.INTERACTION, String.class);
        if (isSignature(interaction)) {
            String cutoffType = EDGE_CUTOFF_TYPE.get(row, prefix, null);
            PostAnalysisFilterType filterType = PostAnalysisFilterType.fromDisplayString(cutoffType);
            if (filterType == null) {
                EDGE_WIDTH_FORMULA_COLUMN.set(row, prefix, null, null);
                continue;
            }
            Double pvalue, cutoff;
            switch(filterType) {
                case MANN_WHIT_TWO_SIDED:
                    pvalue = EDGE_MANN_WHIT_TWOSIDED_PVALUE.get(row, prefix);
                    cutoff = EDGE_MANN_WHIT_CUTOFF.get(row, prefix);
                    break;
                case MANN_WHIT_GREATER:
                    pvalue = EDGE_MANN_WHIT_GREATER_PVALUE.get(row, prefix);
                    cutoff = EDGE_MANN_WHIT_CUTOFF.get(row, prefix);
                    break;
                case MANN_WHIT_LESS:
                    pvalue = EDGE_MANN_WHIT_LESS_PVALUE.get(row, prefix);
                    cutoff = EDGE_MANN_WHIT_CUTOFF.get(row, prefix);
                    break;
                default:
                    pvalue = EDGE_HYPERGEOM_PVALUE.get(row, prefix);
                    cutoff = EDGE_HYPERGEOM_CUTOFF.get(row, prefix);
                    break;
            }
            if (pvalue == null || cutoff == null) {
                EDGE_WIDTH_FORMULA_COLUMN.set(row, prefix, null);
            } else if (pvalue <= cutoff / 100) {
                EDGE_WIDTH_FORMULA_COLUMN.set(row, prefix, edgeWidthParams.pa_lessThan100);
            } else if (pvalue <= cutoff / 10) {
                EDGE_WIDTH_FORMULA_COLUMN.set(row, prefix, edgeWidthParams.pa_lessThan10);
            } else {
                EDGE_WIDTH_FORMULA_COLUMN.set(row, prefix, edgeWidthParams.pa_greater);
            }
        } else {
            // Can use a continuous mapping object to perform calculation
            // even though it won't be added to the visual style.
            ContinuousMapping<Double, Double> conmapping_edgewidth = (ContinuousMapping<Double, Double>) vmfFactoryContinuous.createVisualMappingFunction(prefix + EDGE_SIMILARITY_COEFF, Double.class, BasicVisualLexicon.EDGE_WIDTH);
            Double under_width = 0.5;
            Double min_width = edgeWidthParams.em_lower;
            Double max_width = edgeWidthParams.em_upper;
            Double over_width = 6.0;
            // Create boundary conditions                  less than,   equals,  greater than
            BoundaryRangeValues<Double> bv4 = new BoundaryRangeValues<>(under_width, min_width, min_width);
            BoundaryRangeValues<Double> bv5 = new BoundaryRangeValues<>(max_width, max_width, over_width);
            conmapping_edgewidth.addPoint(map.getParams().getSimilarityCutoff(), bv4);
            conmapping_edgewidth.addPoint(1.0, bv5);
            Double value = conmapping_edgewidth.getMappedValue(row);
            EDGE_WIDTH_FORMULA_COLUMN.set(row, prefix, value);
        }
    }
}
Also used : ContinuousMapping(org.cytoscape.view.vizmap.mappings.ContinuousMapping) PostAnalysisFilterType(org.baderlab.csplugins.enrichmentmap.model.PostAnalysisFilterType) BoundaryRangeValues(org.cytoscape.view.vizmap.mappings.BoundaryRangeValues) EnrichmentMap(org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap) CyRow(org.cytoscape.model.CyRow)

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