Search in sources :

Example 26 with CyNetwork

use of org.cytoscape.model.CyNetwork in project EnrichmentMapApp by BaderLab.

the class CreateDiseaseSignatureNetworkTask method run.

/**
	 * This task is NOT cancellable.
	 */
@Override
public void run(TaskMonitor tm) {
    tm.setTitle("Post Analysis Geneset Similarities...");
    CyNetwork network = networkManager.getNetwork(map.getNetworkID());
    CyNetworkView networkView = getNetworKView(network);
    taskResult.setNetwork(network);
    taskResult.setNetworkView(networkView);
    // Gene universe is all enrichment genes in the map
    Set<Integer> geneUniverse = map.getAllEnrichmentGenes();
    String prefix = params.getAttributePrefix();
    //get the node attribute and edge attribute tables
    tm.setStatusMessage("Creating Columns");
    CyTable edgeTable = createEdgeColumns(network, "", prefix);
    CyTable nodeTable = createNodeColumns(network, "", prefix);
    tm.setProgress(0.1);
    tm.setStatusMessage("Caching Nodes");
    existingEdgeCache = createExistingEdgeCache(prefix, network, edgeTable);
    tm.setProgress(0.2);
    EMSignatureDataSet sigDataSet = createSignatureDataSet();
    // Create Signature Hub Nodes
    tm.setStatusMessage("Creating Nodes");
    signatureGeneSets.forEach(sigDataSet.getGeneSetsOfInterest()::addGeneSet);
    signatureGeneSets.forEach((hubName, sigGeneSet) -> createHubNode(hubName, network, networkView, prefix, edgeTable, nodeTable, geneUniverse, sigGeneSet, sigDataSet));
    tm.setProgress(0.3);
    // Layout nodes
    tm.setStatusMessage("Laying out Nodes");
    layoutHubNodes(networkView);
    tm.setProgress(0.4);
    // Create Signature Hub Edges
    tm.setStatusMessage("Creating Edges");
    DiscreteTaskMonitor dtm = new DiscreteTaskMonitor(tm, geneSetSimilarities.size(), 0.4, 0.9);
    dtm.setStatusMessageTemplate("Similarity {0} of {1}");
    for (SimilarityKey similarityKey : geneSetSimilarities.keySet()) {
        boolean passedCutoff = passesCutoff(similarityKey, sigDataSet);
        createEdge(similarityKey, network, networkView, prefix, edgeTable, nodeTable, passedCutoff, sigDataSet);
        dtm.inc();
    }
    // Set edge widths
    tm.setStatusMessage("Setting Edge Widths");
    widthFunctionProvider.get().setEdgeWidths(network, prefix, tm);
    tm.setProgress(1.0);
    // Add the new data set to the map
    map.addSignatureDataSet(sigDataSet);
}
Also used : CyTable(org.cytoscape.model.CyTable) DiscreteTaskMonitor(org.baderlab.csplugins.enrichmentmap.util.DiscreteTaskMonitor) EMSignatureDataSet(org.baderlab.csplugins.enrichmentmap.model.EMSignatureDataSet) CyNetwork(org.cytoscape.model.CyNetwork) SimilarityKey(org.baderlab.csplugins.enrichmentmap.model.SimilarityKey) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Example 27 with CyNetwork

use of org.cytoscape.model.CyNetwork in project EnrichmentMapApp by BaderLab.

the class RemoveSignatureDataSetsTask method run.

@Override
public void run(TaskMonitor taskMonitor) {
    CyNetwork network = networkManager.getNetwork(map.getNetworkID());
    if (network == null)
        throw new IllegalStateException("The Network with SUID " + map.getNetworkID() + " does not exist.");
    deleteSignatureNodesAndEdges(network);
    signatureDataSets.forEach(map::removeSignatureDataSet);
}
Also used : CyNetwork(org.cytoscape.model.CyNetwork)

Example 28 with CyNetwork

use of org.cytoscape.model.CyNetwork in project EnrichmentMapApp by BaderLab.

the class FilterNodesEdgesTask method filterNodes.

private void filterNodes(Set<CyNode> nodes, TaskMonitor taskMonitor) {
    CyNetwork net = networkView.getModel();
    for (CyNode n : net.getNodeList()) {
        if (cancelled)
            return;
        final View<CyNode> nv = networkView.getNodeView(n);
        if (nv == null)
            // Should never happen!
            continue;
        boolean filteredIn = nodes.contains(n);
        VisualLexicon lexicon = renderingEngineManager.getDefaultVisualLexicon();
        VisualProperty<?> customGraphics1 = lexicon.lookup(CyNode.class, "NODE_CUSTOMGRAPHICS_1");
        // Don't forget to remove all previous locked values first!
        nv.clearValueLock(NODE_VISIBLE);
        nv.clearValueLock(NODE_TRANSPARENCY);
        nv.clearValueLock(NODE_BORDER_TRANSPARENCY);
        nv.clearValueLock(NODE_LABEL_TRANSPARENCY);
        if (customGraphics1 != null)
            nv.clearValueLock(customGraphics1);
        if (filteredIn) {
            if (filterMode == FilterMode.SELECT)
                net.getRow(n).set(CyNetwork.SELECTED, true);
        } else {
            switch(filterMode) {
                case HIDE:
                    net.getRow(n).set(CyNetwork.SELECTED, false);
                    nv.setLockedValue(NODE_VISIBLE, false);
                    break;
                case HIGHLIGHT:
                    nv.setLockedValue(NODE_TRANSPARENCY, FILTERED_OUT_NODE_TRANSPARENCY);
                    nv.setLockedValue(NODE_BORDER_TRANSPARENCY, FILTERED_OUT_NODE_TRANSPARENCY);
                    nv.setLockedValue(NODE_LABEL_TRANSPARENCY, 0);
                    if (customGraphics1 != null)
                        nv.setLockedValue(customGraphics1, NullCustomGraphics.getNullObject());
                    break;
                case SELECT:
                    net.getRow(n).set(CyNetwork.SELECTED, false);
                    break;
            }
        }
    }
}
Also used : VisualLexicon(org.cytoscape.view.model.VisualLexicon) CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode)

Example 29 with CyNetwork

use of org.cytoscape.model.CyNetwork in project EnrichmentMapApp by BaderLab.

the class BaseIntegrationTest method importNetworkFromFile.

protected CyNetwork importNetworkFromFile(String path, String fileName) throws IOException {
    Set<CyNetwork> existingNetworks = networkManager.getNetworkSet();
    // import the network
    File file = TestUtils.createTempFile(path, fileName);
    TaskIterator taskIterator = loadNetworkFileTaskFactory.createTaskIterator(file);
    SerialTestTaskManager taskManager = new SerialTestTaskManager();
    taskManager.execute(taskIterator);
    // get a reference to the imported network
    Set<CyNetwork> networksAfterImport = networkManager.getNetworkSet();
    networksAfterImport.removeAll(existingNetworks);
    assertEquals(1, networksAfterImport.size());
    return networksAfterImport.iterator().next();
}
Also used : TaskIterator(org.cytoscape.work.TaskIterator) CyNetwork(org.cytoscape.model.CyNetwork) File(java.io.File)

Example 30 with CyNetwork

use of org.cytoscape.model.CyNetwork in project EnrichmentMapApp by BaderLab.

the class PostAnalysisTaskTest method test_1_EnrichmentMapBuildMapTask.

@Test
public void test_1_EnrichmentMapBuildMapTask(CyApplicationManager applicationManager, CyNetworkManager networkManager, EnrichmentMapManager emManager) {
    DataSetFiles dataset1files = new DataSetFiles();
    dataset1files.setGMTFileName(PATH + "gene_sets.gmt");
    dataset1files.setExpressionFileName(PATH + "FakeExpression.txt");
    dataset1files.setEnrichmentFileName1(PATH + "fakeEnrichments.txt");
    dataset1files.setRankedFile(PATH + "FakeRank.rnk");
    EMCreationParameters params = new EMCreationParameters("EM1_", 0.1, 0.1, NESFilter.ALL, Optional.empty(), SimilarityMetric.JACCARD, 0.1, 0.1);
    buildEnrichmentMap(params, dataset1files, Method.Generic, LegacySupport.DATASET1);
    // Assert the network is as expected
    Set<CyNetwork> networks = networkManager.getNetworkSet();
    assertEquals(1, networks.size());
    CyNetwork network = networks.iterator().next();
    Map<String, CyNode> nodes = TestUtils.getNodes(network);
    assertEquals(4, nodes.size());
    assertTrue(nodes.containsKey("BOTTOM8_PLUS100"));
    assertTrue(nodes.containsKey("MIDDLE8_PLUS100"));
    assertTrue(nodes.containsKey("TOP8_PLUS100"));
    assertTrue(nodes.containsKey("TOP1_PLUS100"));
    EdgeSimilarities edges = TestUtils.getEdgeSimilarities(network);
    assertEquals(6, edges.size());
    assertTrue(edges.containsEdge("MIDDLE8_PLUS100", "Geneset_Overlap", "BOTTOM8_PLUS100"));
    assertTrue(edges.containsEdge("TOP8_PLUS100", "Geneset_Overlap", "MIDDLE8_PLUS100"));
    assertTrue(edges.containsEdge("TOP8_PLUS100", "Geneset_Overlap", "BOTTOM8_PLUS100"));
    assertTrue(edges.containsEdge("TOP1_PLUS100", "Geneset_Overlap", "TOP8_PLUS100"));
    assertTrue(edges.containsEdge("TOP1_PLUS100", "Geneset_Overlap", "MIDDLE8_PLUS100"));
    assertTrue(edges.containsEdge("TOP1_PLUS100", "Geneset_Overlap", "BOTTOM8_PLUS100"));
    // Make the network available to the subsequent test methods (requires test methods are run in order)
    emNetwork = network;
}
Also used : EMCreationParameters(org.baderlab.csplugins.enrichmentmap.model.EMCreationParameters) CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode) EdgeSimilarities(org.baderlab.csplugins.enrichmentmap.EdgeSimilarities) DataSetFiles(org.baderlab.csplugins.enrichmentmap.model.DataSetFiles) Test(org.junit.Test)

Aggregations

CyNetwork (org.cytoscape.model.CyNetwork)48 Test (org.junit.Test)20 CyNode (org.cytoscape.model.CyNode)16 CyNetworkView (org.cytoscape.view.model.CyNetworkView)13 EnrichmentMap (org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap)11 CyEdge (org.cytoscape.model.CyEdge)9 ArrayList (java.util.ArrayList)8 List (java.util.List)6 CyNetworkManager (org.cytoscape.model.CyNetworkManager)6 CyRow (org.cytoscape.model.CyRow)6 BaseIntegrationTest (org.baderlab.csplugins.enrichmentmap.integration.BaseIntegrationTest)5 DataSetFiles (org.baderlab.csplugins.enrichmentmap.model.DataSetFiles)5 EMDataSet (org.baderlab.csplugins.enrichmentmap.model.EMDataSet)5 CyTable (org.cytoscape.model.CyTable)5 Map (java.util.Map)4 Set (java.util.Set)4 EMCreationParameters (org.baderlab.csplugins.enrichmentmap.model.EMCreationParameters)4 View (org.cytoscape.view.model.View)4 Inject (com.google.inject.Inject)3 Color (java.awt.Color)3