Search in sources :

Example 6 with PostAnalysisFilterParameters

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

the class PostAnalysisTaskTest method test_3_PostAnalysisHypergeometric_overlap.

/**
	 * Run post-analysis again, but with hypergeometric test this time.
	 * The result should keep the 2 edges that were created by the previous run
	 * plus add two new edges.
	 */
@Test
public void test_3_PostAnalysisHypergeometric_overlap(@Continuous VisualMappingFunctionFactory cmFactory) throws Exception {
    mockContinuousMappingFactory(cmFactory);
    PostAnalysisParameters.Builder builder = new PostAnalysisParameters.Builder();
    builder.setAnalysisType(AnalysisType.KNOWN_SIGNATURE);
    builder.setUniverseType(UniverseType.USER_DEFINED);
    builder.setUserDefinedUniverseSize(11445);
    builder.setSignatureGMTFileName(PATH + "PA_top8_middle8_bottom8.gmt");
    builder.setAttributePrefix("EM1_");
    PostAnalysisFilterParameters rankTest = new PostAnalysisFilterParameters(PostAnalysisFilterType.HYPERGEOM, 0.25);
    builder.setRankTestParameters(rankTest);
    runPostAnalysis(emNetwork, builder, LegacySupport.DATASET1);
    // Assert that post-analysis created the new nodes correctly
    Map<String, CyNode> nodes = TestUtils.getNodes(emNetwork);
    assertEquals(5, nodes.size());
    assertTrue(nodes.containsKey("PA_TOP8_MIDDLE8_BOTTOM8"));
    Map<String, CyEdge> edges = TestUtils.getSignatureEdges(emNetwork, "EM1_", "PA_top8_middle8_bottom8(1)");
    assertEquals(4, edges.size());
    CyEdge edge1 = edges.get("PA_TOP8_MIDDLE8_BOTTOM8 (sig_Dataset 1) TOP8_PLUS100");
    assertNotNull(edge1);
    //	   	assertEquals(1.40E-6,  emNetwork.getRow(edge1).get("EM1_Overlap_Mann_Whit_pVal", Double.class), 0.001);
    assertEquals(4.21E-11, emNetwork.getRow(edge1).get("EM1_Overlap_Hypergeom_pVal", Double.class), 0.001);
    assertEquals(PostAnalysisFilterType.HYPERGEOM.toString(), emNetwork.getRow(edge1).get("EM1_Overlap_cutoff", String.class));
    CyEdge edge2 = edges.get("PA_TOP8_MIDDLE8_BOTTOM8 (sig_Dataset 1) BOTTOM8_PLUS100");
    assertNotNull(edge2);
    //	   	assertEquals(1.40E-6,  emNetwork.getRow(edge2).get("EM1_Overlap_Mann_Whit_pVal", Double.class), 0.001);
    assertEquals(4.21E-11, emNetwork.getRow(edge2).get("EM1_Overlap_Hypergeom_pVal", Double.class), 0.001);
    assertEquals(PostAnalysisFilterType.HYPERGEOM.toString(), emNetwork.getRow(edge2).get("EM1_Overlap_cutoff", String.class));
    CyEdge edge3 = edges.get("PA_TOP8_MIDDLE8_BOTTOM8 (sig_Dataset 1) MIDDLE8_PLUS100");
    assertNotNull(edge3);
    assertNull(emNetwork.getRow(edge3).get("EM1_Overlap_Mann_Whit_pVal", Double.class));
    assertEquals(4.21E-11, emNetwork.getRow(edge3).get("EM1_Overlap_Hypergeom_pVal", Double.class), 0.001);
    assertEquals(PostAnalysisFilterType.HYPERGEOM.toString(), emNetwork.getRow(edge3).get("EM1_Overlap_cutoff", String.class));
    CyEdge edge4 = edges.get("PA_TOP8_MIDDLE8_BOTTOM8 (sig_Dataset 1) TOP1_PLUS100");
    assertNotNull(edge4);
    assertNull(emNetwork.getRow(edge4).get("EM1_Overlap_Mann_Whit_pVal", Double.class));
    assertEquals(0.19, emNetwork.getRow(edge4).get("EM1_Overlap_Hypergeom_pVal", Double.class), 0.01);
    assertEquals(PostAnalysisFilterType.HYPERGEOM.toString(), emNetwork.getRow(edge4).get("EM1_Overlap_cutoff", String.class));
}
Also used : PostAnalysisParameters(org.baderlab.csplugins.enrichmentmap.model.PostAnalysisParameters) PostAnalysisFilterParameters(org.baderlab.csplugins.enrichmentmap.model.PostAnalysisFilterParameters) CyNode(org.cytoscape.model.CyNode) CyEdge(org.cytoscape.model.CyEdge) Test(org.junit.Test)

Example 7 with PostAnalysisFilterParameters

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

the class PostAnalysisWeightPanel method build.

public boolean build(PostAnalysisParameters.Builder builder) {
    double value = ((Number) rankTestTextField.getValue()).doubleValue();
    PostAnalysisFilterParameters rankTest = new PostAnalysisFilterParameters(getFilterType(), value);
    builder.setDataSetName(getDataSet());
    builder.setUniverseType(getUniverseType());
    builder.setUserDefinedUniverseSize(getUserDefinedUniverseSize());
    builder.setRankTestParameters(rankTest);
    if (getFilterType().isMannWhitney()) {
        if (map.isSingleRanksPerDataset()) {
            for (EMDataSet dataset : map.getDataSetList()) {
                String ranksName = dataset.getExpressionSets().getAllRanksNames().iterator().next();
                builder.addDataSetToRankFile(dataset.getName(), ranksName);
            }
        } else {
            JFrame jframe = serviceRegistrar.getService(CySwingApplication.class).getJFrame();
            MannWhitneyRanksDialog dialog = new MannWhitneyRanksDialog(jframe, map);
            Optional<Map<String, String>> result = dialog.open();
            if (result.isPresent()) {
                Map<String, String> dataSetToRank = result.get();
                dataSetToRank.forEach(builder::addDataSetToRankFile);
            } else {
                return false;
            }
        }
    }
    return true;
}
Also used : JFrame(javax.swing.JFrame) CySwingApplication(org.cytoscape.application.swing.CySwingApplication) PostAnalysisFilterParameters(org.baderlab.csplugins.enrichmentmap.model.PostAnalysisFilterParameters) EMDataSet(org.baderlab.csplugins.enrichmentmap.model.EMDataSet) EnrichmentMap(org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap) Map(java.util.Map)

Example 8 with PostAnalysisFilterParameters

use of org.baderlab.csplugins.enrichmentmap.model.PostAnalysisFilterParameters 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)

Aggregations

PostAnalysisFilterParameters (org.baderlab.csplugins.enrichmentmap.model.PostAnalysisFilterParameters)8 PostAnalysisParameters (org.baderlab.csplugins.enrichmentmap.model.PostAnalysisParameters)6 CyEdge (org.cytoscape.model.CyEdge)5 Test (org.junit.Test)5 EMDataSet (org.baderlab.csplugins.enrichmentmap.model.EMDataSet)2 EnrichmentMap (org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap)2 CyNode (org.cytoscape.model.CyNode)2 Map (java.util.Map)1 JFrame (javax.swing.JFrame)1 EdgeSimilarities (org.baderlab.csplugins.enrichmentmap.EdgeSimilarities)1 GeneSet (org.baderlab.csplugins.enrichmentmap.model.GeneSet)1 GenesetSimilarity (org.baderlab.csplugins.enrichmentmap.model.GenesetSimilarity)1 PostAnalysisFilterType (org.baderlab.csplugins.enrichmentmap.model.PostAnalysisFilterType)1 UniverseType (org.baderlab.csplugins.enrichmentmap.model.PostAnalysisParameters.UniverseType)1 CreateDiseaseSignatureTaskFactory (org.baderlab.csplugins.enrichmentmap.task.postanalysis.CreateDiseaseSignatureTaskFactory)1 CySwingApplication (org.cytoscape.application.swing.CySwingApplication)1 CyNetwork (org.cytoscape.model.CyNetwork)1 CyNetworkView (org.cytoscape.view.model.CyNetworkView)1 AbstractTask (org.cytoscape.work.AbstractTask)1 Task (org.cytoscape.work.Task)1