use of org.cytoscape.model.CyNetwork in project EnrichmentMapApp by BaderLab.
the class LegacySessionLoadTest method test_1_LoadedLegacyData.
@Test
@SessionFile("em_session_2.2.cys")
public void test_1_LoadedLegacyData() throws Exception {
EnrichmentMap map = getEnrichmentMap();
assertEquals("EM1_Enrichment Map", map.getName());
CyNetwork network = networkManager.getNetwork(map.getNetworkID());
assertNotNull(network);
assertEquals(1, map.getDataSetCount());
assertEquals(14067, map.getNumberOfGenes());
assertEquals(14067, map.getAllGenes().size());
// Number of edges: 3339 - that's how many geneset similarity objects there should be!!!
CyTable edgeTable = network.getDefaultEdgeTable();
assertEquals(3339, edgeTable.getRowCount());
EMCreationParameters params = map.getParams();
String prefix = params.getAttributePrefix();
assertEquals("EM1_", prefix);
assertEquals(0.5, params.getCombinedConstant(), 0.0);
assertFalse(params.isEMgmt());
assertEquals("Geneset_Overlap", params.getEnrichmentEdgeType());
assertTrue(params.isFDR());
assertEquals(GreatFilter.HYPER, params.getGreatFilter());
assertEquals(0.005, params.getPvalue(), 0.0);
assertEquals(1.0, params.getPvalueMin(), 0.0);
assertEquals(0.1, params.getQvalue(), 0.0);
assertEquals(1.0, params.getQvalueMin(), 0.0);
assertEquals(0.5, params.getSimilarityCutoff(), 0.0);
assertEquals(SimilarityMetric.OVERLAP, params.getSimilarityMetric());
// assertFalse(params.isDistinctExpressionSets());
String geneset1 = "RESOLUTION OF SISTER CHROMATID COHESION%REACTOME%REACT_150425.2";
String geneset2 = "CHROMOSOME, CENTROMERIC REGION%GO%GO:0000775";
Collection<CyRow> rows = edgeTable.getMatchingRows(CyNetwork.NAME, geneset1 + " (Geneset_Overlap) " + geneset2);
assertEquals(1, rows.size());
CyRow row = rows.iterator().next();
assertEquals("Geneset_Overlap", row.get(CyEdge.INTERACTION, String.class));
assertEquals(0.6097560975609756, EMStyleBuilder.Columns.EDGE_SIMILARITY_COEFF.get(row, prefix), 0.0);
EMDataSet dataset = map.getDataSet("Dataset 1");
assertNotNull(dataset);
assertSame(map, dataset.getMap());
assertEquals(Method.GSEA, dataset.getMethod());
assertEquals(12653, dataset.getDataSetGenes().size());
assertEquals(389, dataset.getGeneSetsOfInterest().getGeneSets().size());
// assertEquals(17259, dataset.getSetofgenesets().getGenesets().size()); // MKTODO why? what is this used for
assertEndsWith(dataset.getSetOfGeneSets().getFilename(), "Human_GO_AllPathways_no_GO_iea_April_15_2013_symbol.gmt");
for (long suid : dataset.getNodeSuids()) {
assertNotNull(network.getNode(suid));
}
GeneSet geneset = dataset.getGeneSetsOfInterest().getGeneSets().get("NCRNA PROCESSING%GO%GO:0034470");
assertEquals(88, geneset.getGenes().size());
assertEquals("NCRNA PROCESSING%GO%GO:0034470", geneset.getName());
assertEquals("ncRNA processing", geneset.getDescription());
assertEquals(Optional.of("GO"), geneset.getSource());
SetOfEnrichmentResults enrichments = dataset.getEnrichments();
assertEquals(4756, enrichments.getEnrichments().size());
assertEndsWith(enrichments.getFilename1(), "gsea_report_for_ES12_1473194913081.xls");
assertEndsWith(enrichments.getFilename2(), "gsea_report_for_NT12_1473194913081.xls");
assertEquals("ES12", enrichments.getPhenotype1());
assertEquals("NT12", enrichments.getPhenotype2());
EnrichmentResult result = enrichments.getEnrichments().get("RIBONUCLEOSIDE TRIPHOSPHATE BIOSYNTHETIC PROCESS%GO%GO:0009201");
assertTrue(result instanceof GSEAResult);
GSEAResult gseaResult = (GSEAResult) result;
assertEquals("RIBONUCLEOSIDE TRIPHOSPHATE BIOSYNTHETIC PROCESS%GO%GO:0009201", gseaResult.getName());
assertEquals(0.42844063, gseaResult.getES(), 0.0);
assertEquals(0.45225498, gseaResult.getFdrqvalue(), 0.0);
assertEquals(1.0, gseaResult.getFwerqvalue(), 0.0);
assertEquals(23, gseaResult.getGsSize());
assertEquals(1.1938541, gseaResult.getNES(), 0.0);
assertEquals(0.2457786, gseaResult.getPvalue(), 0.0);
assertEquals(4689, gseaResult.getRankAtMax());
assertEquals(Optional.of("GO"), gseaResult.getSource());
GeneExpressionMatrix expressions = dataset.getExpressionSets();
assertEquals(20326, expressions.getExpressionUniverse());
assertEquals(3.686190609, expressions.getClosesttoZero(), 0.0);
// assertEndsWith(expressions.getFilename(), "MCF7_ExprMx_v2_names.gct");
assertEquals(15380.42388, expressions.getMaxExpression(), 0.0);
assertEquals(3.686190609, expressions.getMinExpression(), 0.0);
assertEquals(20, expressions.getNumConditions());
assertEquals(12653, expressions.getExpressionMatrix().size());
assertEquals(12653, expressions.getExpressionMatrix_rowNormalized().size());
GeneExpression expression = expressions.getExpressionMatrix().get(0);
assertEquals("MOCOS", expression.getName());
assertEquals("MOCOS (molybdenum cofactor sulfurase)", expression.getDescription());
assertEquals(18, expression.getExpression().length);
Ranking ranking = expressions.getRanks().get("GSEARanking");
assertEquals(12653, ranking.getAllRanks().size());
assertEquals(12653, ranking.getRanking().size());
Rank rank = ranking.getRanking().get(0);
assertEquals("MOCOS", rank.getName());
assertEquals(1238, rank.getRank().intValue());
assertEquals(0.54488367, rank.getScore(), 0.0);
DataSetFiles files = dataset.getDataSetFiles();
assertEndsWith(files.getClassFile(), "ES_NT.cls");
assertEndsWith(files.getEnrichmentFileName1(), "gsea_report_for_ES12_1473194913081.xls");
assertEndsWith(files.getEnrichmentFileName2(), "gsea_report_for_NT12_1473194913081.xls");
// assertEndsWith(files.getExpressionFileName(), "MCF7_ExprMx_v2_names.gct");
assertEndsWith(files.getGMTFileName(), "Human_GO_AllPathways_no_GO_iea_April_15_2013_symbol.gmt");
assertEndsWith(files.getGseaHtmlReportFile(), "estrogen_treatment_12hr_gsea_enrichment_results.Gsea.1473194913081/index.html");
assertEndsWith(files.getRankedFile(), "ranked_gene_list_ES12_versus_NT12_1473194913081.xls");
assertEquals("ES12", files.getPhenotype1());
assertEquals("NT12", files.getPhenotype2());
}
use of org.cytoscape.model.CyNetwork in project EnrichmentMapApp by BaderLab.
the class CreateEnrichmentMapTaskTest method testEnrichmentMapBuildMapTask.
@Test
public void testEnrichmentMapBuildMapTask() throws Exception {
String geneSetsFile = TestUtils.createTempFile(PATH, "gene_sets.gmt").getAbsolutePath();
String expressionFile = TestUtils.createTempFile(PATH, "FakeExpression.txt").getAbsolutePath();
String enrichmentFile = TestUtils.createTempFile(PATH, "fakeEnrichments.txt").getAbsolutePath();
String rankFile = TestUtils.createTempFile(PATH, "FakeRank.rnk").getAbsolutePath();
PropertyManager pm = new PropertyManager();
EMCreationParameters params = new EMCreationParameters("EM1_", pm.getDefaultPvalue(), pm.getDefaultQvalue(), NESFilter.ALL, Optional.empty(), SimilarityMetric.JACCARD, pm.getDefaultJaccardCutOff(), pm.getDefaultCombinedConstant());
DataSetFiles dataset1files = new DataSetFiles();
dataset1files.setGMTFileName(geneSetsFile);
dataset1files.setExpressionFileName(expressionFile);
dataset1files.setEnrichmentFileName1(enrichmentFile);
dataset1files.setRankedFile(rankFile);
buildEnrichmentMap(params, dataset1files, 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"));
}
use of org.cytoscape.model.CyNetwork in project EnrichmentMapApp by BaderLab.
the class ControlPanelMediator method reset.
public void reset() {
invokeOnEDT(() -> {
updating = true;
try {
for (CyNetworkView view : networkViewManager.getNetworkViewSet()) getControlPanel().removeEnrichmentMapView(view);
Map<Long, EnrichmentMap> maps = emManager.getAllEnrichmentMaps();
for (EnrichmentMap map : maps.values()) {
CyNetwork network = networkManager.getNetwork(map.getNetworkID());
Collection<CyNetworkView> networkViews = networkViewManager.getNetworkViews(network);
for (CyNetworkView netView : networkViews) addNetworkView(netView);
}
} finally {
updating = false;
}
setCurrentNetworkView(applicationManager.getCurrentNetworkView());
});
}
use of org.cytoscape.model.CyNetwork in project EnrichmentMapApp by BaderLab.
the class ChartUtil method calculateGlobalRange.
/**
* @return List whose first item is the minimum value of the range, and whose second item is the maximum value.
*/
@SuppressWarnings("unchecked")
public static List<Double> calculateGlobalRange(CyNetwork network, List<CyColumnIdentifier> dataColumns) {
List<Double> range = new ArrayList<>(2);
List<CyNode> nodes = network.getNodeList();
if (!nodes.isEmpty()) {
double min = Double.POSITIVE_INFINITY;
double max = Double.NEGATIVE_INFINITY;
Collection<CyColumn> columns = network.getDefaultNodeTable().getColumns();
Map<String, CyColumn> columnMap = columns.stream().collect(Collectors.toMap(CyColumn::getName, c -> c));
for (final CyColumnIdentifier colId : dataColumns) {
final CyColumn column = columnMap.get(colId.getColumnName());
if (column == null)
continue;
final Class<?> colType = column.getType();
final Class<?> colListType = column.getListElementType();
if (Number.class.isAssignableFrom(colType) || (List.class.isAssignableFrom(colType) && Number.class.isAssignableFrom(colListType))) {
for (final CyNode n : nodes) {
List<? extends Number> values = null;
final CyRow row = network.getRow(n);
if (List.class.isAssignableFrom(colType))
values = (List<? extends Number>) row.getList(column.getName(), colListType);
else if (row.isSet(column.getName()))
values = Collections.singletonList((Number) row.get(column.getName(), colType));
double[] mm = minMax(min, max, values);
min = mm[0];
max = mm[1];
}
}
}
if (min != Double.POSITIVE_INFINITY && max != Double.NEGATIVE_INFINITY) {
range.add(min);
range.add(max);
}
} else {
range.add(0d);
range.add(0d);
}
return range;
}
use of org.cytoscape.model.CyNetwork 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++;
}
}
Aggregations