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);
}
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);
}
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;
}
}
}
}
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();
}
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;
}
Aggregations