use of org.cytoscape.model.CyEdge in project EnrichmentMapApp by BaderLab.
the class FilterNodesEdgesTask method filterEdges.
private void filterEdges(Set<CyNode> nodes, Set<CyEdge> edges, TaskMonitor taskMonitor, double initialProgress) {
CyNetwork net = networkView.getModel();
List<CyEdge> edgeList = net.getEdgeList();
int total = edgeList.size();
int count = 0;
float progress = (float) initialProgress;
for (CyEdge e : edgeList) {
if (cancelled)
return;
final View<CyEdge> ev = networkView.getEdgeView(e);
if (ev == null)
// Should never happen!
continue;
boolean filteredIn = edges.contains(e) && nodes.contains(e.getSource()) && nodes.contains(e.getTarget());
// Don't forget to remove all locked values first!
ev.clearValueLock(EDGE_VISIBLE);
ev.clearValueLock(EDGE_TRANSPARENCY);
ev.clearValueLock(EDGE_LABEL_TRANSPARENCY);
if (filteredIn) {
if (filterMode == FilterMode.SELECT)
net.getRow(e).set(CyNetwork.SELECTED, true);
} else {
switch(filterMode) {
case HIDE:
net.getRow(e).set(CyNetwork.SELECTED, false);
ev.setLockedValue(EDGE_VISIBLE, false);
break;
case HIGHLIGHT:
ev.setLockedValue(EDGE_TRANSPARENCY, FILTERED_OUT_EDGE_TRANSPARENCY);
ev.setLockedValue(EDGE_LABEL_TRANSPARENCY, FILTERED_OUT_EDGE_TRANSPARENCY);
break;
case SELECT:
net.getRow(e).set(CyNetwork.SELECTED, false);
break;
}
}
// Use only 2 decimals to avoid too many UI updates when setting very small numbers
float newProgress = Math.round((initialProgress + count * (1 - initialProgress) / total) * 100) / 100.0f;
if (newProgress != progress) {
taskMonitor.setProgress(newProgress);
progress = newProgress;
}
count++;
}
}
use of org.cytoscape.model.CyEdge in project EnrichmentMapApp by BaderLab.
the class CreateEMNetworkTask method createEdges.
/**
* Note, we expect that GenesetSimilarity object that don't pass the cutoff have already been filtered out.
* @param network
* @param nodes
*/
private void createEdges(CyNetwork network, Map<String, CyNode> nodes) {
Map<SimilarityKey, GenesetSimilarity> similarities = supplier.get();
for (SimilarityKey key : similarities.keySet()) {
GenesetSimilarity similarity = similarities.get(key);
CyNode node1 = nodes.get(similarity.getGeneset1Name());
CyNode node2 = nodes.get(similarity.getGeneset2Name());
CyEdge edge = network.addEdge(node1, node2, false);
String datasetName = key.getName();
if (datasetName != null) {
EMDataSet dataset = map.getDataSet(datasetName);
if (dataset != null) {
dataset.addEdgeSuid(edge.getSUID());
}
}
List<String> overlapGenes = similarity.getOverlappingGenes().stream().map(map::getGeneFromHashKey).collect(Collectors.toList());
String edgeName = key.toString();
CyRow row = network.getRow(edge);
row.set(CyNetwork.NAME, edgeName);
row.set(CyEdge.INTERACTION, similarity.getInteractionType());
Columns.EDGE_SIMILARITY_COEFF.set(row, prefix, null, similarity.getSimilarityCoeffecient());
Columns.EDGE_OVERLAP_SIZE.set(row, prefix, null, similarity.getSizeOfOverlap());
Columns.EDGE_OVERLAP_GENES.set(row, prefix, null, overlapGenes);
if (key.isCompound()) {
Columns.EDGE_DATASET.set(row, prefix, null, Columns.EDGE_DATASET_VALUE_COMPOUND);
} else {
Columns.EDGE_DATASET.set(row, prefix, null, similarity.getDataSetName());
}
}
}
use of org.cytoscape.model.CyEdge in project EnrichmentMapApp by BaderLab.
the class PostAnalysisTaskTest method test_2_PostAnalysisMannWhitney.
/**
* Run post-analysis with the default mann-whitney test.
* Uses the network that was created by the previous test method.
*/
@Test
public void test_2_PostAnalysisMannWhitney(@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_");
builder.addDataSetToRankFile(LegacySupport.DATASET1, LegacySupport.DATASET1);
PostAnalysisFilterParameters rankTest = new PostAnalysisFilterParameters(PostAnalysisFilterType.MANN_WHIT_TWO_SIDED);
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"));
EdgeSimilarities edges = TestUtils.getEdgeSimilarities(emNetwork);
assertEquals(8, edges.size());
CyEdge edge1 = edges.getEdge("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(PostAnalysisFilterType.MANN_WHIT_TWO_SIDED.toString(), emNetwork.getRow(edge1).get("EM1_Overlap_cutoff", String.class));
CyEdge edge2 = edges.getEdge("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(PostAnalysisFilterType.MANN_WHIT_TWO_SIDED.toString(), emNetwork.getRow(edge2).get("EM1_Overlap_cutoff", String.class));
}
use of org.cytoscape.model.CyEdge in project EnrichmentMapApp by BaderLab.
the class PostAnalysisTaskTest method test_4_WidthFunction.
@Test
public void test_4_WidthFunction(@Continuous VisualMappingFunctionFactory cmFactory, EnrichmentMapManager emManager, Provider<WidthFunction> widthFunctionProvider) {
CyNetworkManager networkManager = mock(CyNetworkManager.class);
when(networkManager.getNetworkSet()).thenReturn(Collections.singleton(emNetwork));
mockContinuousMappingFactory(cmFactory);
EdgeSimilarities edges = TestUtils.getEdgeSimilarities(emNetwork);
CyEdge sigEdge1 = edges.getEdge("PA_TOP8_MIDDLE8_BOTTOM8 (sig_Dataset 1) TOP8_PLUS100");
CyEdge sigEdge2 = edges.getEdge("PA_TOP8_MIDDLE8_BOTTOM8 (sig_Dataset 1) TOP1_PLUS100");
EnrichmentMap map = emManager.getEnrichmentMap(emNetwork.getSUID());
assertNotNull(map);
WidthFunction widthFunction = widthFunctionProvider.get();
widthFunction.setEdgeWidths(emNetwork, "EM1_", null);
String widthCol = Columns.EDGE_WIDTH_FORMULA_COLUMN.with("EM1_", null);
double sigWidth1 = emNetwork.getRow(sigEdge1).get(widthCol, Double.class);
assertEquals(8.0, sigWidth1, 0.0);
double sigWidth2 = emNetwork.getRow(sigEdge2).get(widthCol, Double.class);
assertEquals(1.0, sigWidth2, 0.0);
}
use of org.cytoscape.model.CyEdge in project EnrichmentMapApp by BaderLab.
the class PostAnalysisCutoffTest method test_1_FilterType_Number.
@Test
public void test_1_FilterType_Number(@Continuous VisualMappingFunctionFactory cmFactory) throws Exception {
mockContinuousMappingFactory(cmFactory);
PostAnalysisParameters.Builder builder = getBuilder();
PostAnalysisFilterParameters rankTest = new PostAnalysisFilterParameters(PostAnalysisFilterType.NUMBER, 5);
builder.setRankTestParameters(rankTest);
runPostAnalysis(emNetwork, builder, LegacySupport.DATASET1);
Map<String, CyEdge> edges = TestUtils.getEdges(emNetwork);
assertEquals(9, edges.size());
CyEdge edge = edges.get("PA_TOP8_MIDDLE8_BOTTOM8 (sig_Dataset 1) MIDDLE8_PLUS100");
assertNotNull(edge);
assertEquals(8, emNetwork.getRow(edge).get("EM1_k_intersection", Integer.class).intValue());
assertEquals(PostAnalysisFilterType.NUMBER.toString(), emNetwork.getRow(edge).get("EM1_Overlap_cutoff", String.class));
edge = edges.get("PA_TOP8_MIDDLE8_BOTTOM8 (sig_Dataset 1) BOTTOM8_PLUS100");
assertNotNull(edge);
assertEquals(8, emNetwork.getRow(edge).get("EM1_k_intersection", Integer.class).intValue());
assertEquals(PostAnalysisFilterType.NUMBER.toString(), emNetwork.getRow(edge).get("EM1_Overlap_cutoff", String.class));
edge = edges.get("PA_TOP8_MIDDLE8_BOTTOM8 (sig_Dataset 1) TOP8_PLUS100");
assertNotNull(edge);
assertEquals(8, emNetwork.getRow(edge).get("EM1_k_intersection", Integer.class).intValue());
assertEquals(PostAnalysisFilterType.NUMBER.toString(), emNetwork.getRow(edge).get("EM1_Overlap_cutoff", String.class));
edge = edges.get("PA_TOP8_MIDDLE8_BOTTOM8 (sig_Dataset 1) TOP1_PLUS100");
assertNull(edge);
}
Aggregations