use of org.cytoscape.view.vizmap.mappings.ContinuousMapping in project EnrichmentMapApp by BaderLab.
the class EMStyleBuilder method setEdgeWidth.
private void setEdgeWidth(VisualStyle vs, EMStyleOptions options) {
String prefix = options.getAttributePrefix();
EnrichmentMap map = options.getEnrichmentMap();
if (options.isPostAnalysis()) {
// Replace the edge width mapping that was created by EnrichmentMapVisualStyle
String widthAttribute = Columns.EDGE_WIDTH_FORMULA_COLUMN.with(prefix, null);
PassthroughMapping<Double, Double> edgewidth = (PassthroughMapping<Double, Double>) pmFactory.createVisualMappingFunction(widthAttribute, Double.class, BasicVisualLexicon.EDGE_WIDTH);
vs.addVisualMappingFunction(edgewidth);
} else {
// Continous Mapping - set edge line thickness based on the number of genes in the overlap
ContinuousMapping<Double, Double> cm = (ContinuousMapping<Double, Double>) cmFactory.createVisualMappingFunction(Columns.EDGE_SIMILARITY_COEFF.with(prefix, null), Double.class, EDGE_WIDTH);
Double underWidth = 0.5;
Double minWidth = 1.0;
Double maxWidth = 5.0;
Double overWidth = 6.0;
// Create boundary conditions
BoundaryRangeValues<Double> bv4 = new BoundaryRangeValues<>(underWidth, minWidth, minWidth);
BoundaryRangeValues<Double> bv5 = new BoundaryRangeValues<>(maxWidth, maxWidth, overWidth);
// Silence events fired by this mapping to prevent unnecessary style and view updates
eventHelper.silenceEventSource(cm);
try {
cm.addPoint(map.getParams().getSimilarityCutoff(), bv4);
cm.addPoint(1.0, bv5);
} finally {
eventHelper.unsilenceEventSource(cm);
}
vs.addVisualMappingFunction(cm);
}
}
use of org.cytoscape.view.vizmap.mappings.ContinuousMapping in project EnrichmentMapApp by BaderLab.
the class EMStyleBuilder method setNodeColors.
private void setNodeColors(VisualStyle vs, EMStyleOptions options) {
String prefix = options.getAttributePrefix();
List<AbstractDataSet> dataSets = options.getDataSets().stream().filter(// Ignore Signature Data Sets in charts
ds -> ds instanceof EMDataSet).collect(Collectors.toList());
if (dataSets.size() == 1) {
// Only 1 Data Set? Use node colour instead of charts...
EMDataSet ds = (EMDataSet) dataSets.iterator().next();
// Create boundary conditions
BoundaryRangeValues<Paint> bv3a = new BoundaryRangeValues<>(Colors.MAX_PHENOTYPE_2, Colors.MAX_PHENOTYPE_2, Colors.MAX_PHENOTYPE_2);
BoundaryRangeValues<Paint> bv3b = new BoundaryRangeValues<>(Colors.LIGHTER_PHENOTYPE_2, Colors.LIGHTER_PHENOTYPE_2, Colors.MAX_PHENOTYPE_2);
BoundaryRangeValues<Paint> bv3c = new BoundaryRangeValues<>(Colors.LIGHTEST_PHENOTYPE_2, Colors.LIGHTEST_PHENOTYPE_2, Colors.LIGHTER_PHENOTYPE_2);
BoundaryRangeValues<Paint> bv3d = new BoundaryRangeValues<>(Colors.LIGHTEST_PHENOTYPE_2, Colors.OVER_COLOR, Colors.OVER_COLOR);
BoundaryRangeValues<Paint> bv3e = new BoundaryRangeValues<>(Colors.OVER_COLOR, Colors.OVER_COLOR, Colors.OVER_COLOR);
BoundaryRangeValues<Paint> bv3f = new BoundaryRangeValues<>(Colors.OVER_COLOR, Colors.OVER_COLOR, Colors.LIGHTEST_PHENOTYPE_1);
BoundaryRangeValues<Paint> bv3g = new BoundaryRangeValues<>(Colors.LIGHTEST_PHENOTYPE_1, Colors.LIGHTEST_PHENOTYPE_1, Colors.LIGHTER_PHENOTYPE_1);
BoundaryRangeValues<Paint> bv3h = new BoundaryRangeValues<>(Colors.LIGHTER_PHENOTYPE_1, Colors.LIGHTER_PHENOTYPE_1, Colors.MAX_PHENOTYPE_1);
BoundaryRangeValues<Paint> bv3i = new BoundaryRangeValues<>(Colors.MAX_PHENOTYPE_1, Colors.MAX_PHENOTYPE_1, Colors.MAX_PHENOTYPE_1);
// Continuous Mapping - set node colour based on the sign of the ES score of the dataset
ContinuousMapping<Double, Paint> cm = (ContinuousMapping<Double, Paint>) cmFactory.createVisualMappingFunction(Columns.NODE_COLOURING.with(prefix, ds.getName()), Double.class, BasicVisualLexicon.NODE_FILL_COLOR);
// Silence events fired by this mapping to prevent unnecessary style and view updates
eventHelper.silenceEventSource(cm);
try {
// Set the attribute point values associated with the boundary values
cm.addPoint(-1.0, bv3a);
cm.addPoint(-0.995, bv3b);
cm.addPoint(-0.95, bv3c);
cm.addPoint(-0.9, bv3d);
cm.addPoint(0.0, bv3e);
cm.addPoint(0.9, bv3f);
cm.addPoint(0.95, bv3g);
cm.addPoint(0.995, bv3h);
cm.addPoint(1.0, bv3i);
} finally {
eventHelper.unsilenceEventSource(cm);
}
vs.addVisualMappingFunction(cm);
// Then we need to use bypass to colour the hub nodes (signature genesets)
List<EMSignatureDataSet> signatureDataSets = options.getEnrichmentMap().getSignatureSetList();
CyNetworkView netView = options.getNetworkView();
CyNetwork net = netView.getModel();
for (EMSignatureDataSet sds : signatureDataSets) {
for (Long suid : sds.getNodeSuids()) {
CyNode node = net.getNode(suid);
if (node != null) {
View<CyNode> nv = netView.getNodeView(node);
if (nv != null)
nv.setLockedValue(NODE_FILL_COLOR, Colors.SIG_NODE_COLOR);
}
}
}
} else {
// 2 or more Data Sets? Use simple node colours and charts...
// Add mapping function for node fill color
DiscreteMapping<String, Paint> dm = (DiscreteMapping<String, Paint>) dmFactory.createVisualMappingFunction(Columns.NODE_GS_TYPE.with(prefix, null), String.class, NODE_FILL_COLOR);
// Silence events fired by this mapping to prevent unnecessary style and view updates
eventHelper.silenceEventSource(dm);
try {
dm.putMapValue(Columns.NODE_GS_TYPE_ENRICHMENT, Colors.DEF_NODE_COLOR);
dm.putMapValue(Columns.NODE_GS_TYPE_SIGNATURE, Colors.SIG_NODE_COLOR);
} finally {
eventHelper.unsilenceEventSource(dm);
}
vs.addVisualMappingFunction(dm);
}
}
use of org.cytoscape.view.vizmap.mappings.ContinuousMapping in project EnrichmentMapApp by BaderLab.
the class EMStyleBuilder method setNodeSize.
@SuppressWarnings("rawtypes")
private void setNodeSize(VisualStyle vs, EMStyleOptions options, ChartType chartType) {
if (chartType == null || chartType == ChartType.RADIAL_HEAT_MAP) {
String prefix = options.getAttributePrefix();
String columnName = Columns.NODE_GS_SIZE.with(prefix, null);
int val0 = 10;
int val1 = 474;
VisualMappingFunction<?, Double> oldMapping = vs.getVisualMappingFunction(NODE_SIZE);
// This is done for performance optimization only!
boolean update = oldMapping instanceof ContinuousMapping == false;
if (!update) {
try {
// Also test the mapped column name and number of points
update = !columnName.equals(oldMapping.getMappingColumnName()) || ((ContinuousMapping) oldMapping).getPointCount() != 2;
if (!update) {
// And the mapping values
ContinuousMappingPoint pt0 = ((ContinuousMapping) oldMapping).getPoint(0);
ContinuousMappingPoint pt1 = ((ContinuousMapping) oldMapping).getPoint(1);
update = val0 != (Integer) pt0.getValue();
update = update || val1 != (Integer) pt1.getValue();
if (// Finally test the boundary ranges
!update)
update = MIN_NODE_SIZE != (Double) pt0.getRange().equalValue || MAX_NODE_SIZE != (Double) pt1.getRange().equalValue;
}
} catch (NullPointerException | ClassCastException e) {
update = true;
}
}
if (update) {
ContinuousMapping<Integer, Double> cm = (ContinuousMapping<Integer, Double>) cmFactory.createVisualMappingFunction(columnName, Integer.class, NODE_SIZE);
BoundaryRangeValues<Double> bv0 = new BoundaryRangeValues<>(MIN_NODE_SIZE, MIN_NODE_SIZE, MIN_NODE_SIZE);
BoundaryRangeValues<Double> bv1 = new BoundaryRangeValues<>(MAX_NODE_SIZE, MAX_NODE_SIZE, MAX_NODE_SIZE);
// Silence events fired by this mapping to prevent unnecessary style and view updates
eventHelper.silenceEventSource(cm);
try {
cm.addPoint(val0, bv0);
cm.addPoint(val1, bv1);
} finally {
eventHelper.unsilenceEventSource(cm);
}
vs.addVisualMappingFunction(cm);
}
} else {
vs.removeVisualMappingFunction(NODE_SIZE);
}
}
use of org.cytoscape.view.vizmap.mappings.ContinuousMapping in project EnrichmentMapApp by BaderLab.
the class WidthFunction method calculateAndSetEdgeWidths.
private void calculateAndSetEdgeWidths(CyNetwork network, String prefix, TaskMonitor taskMonitor) {
EdgeWidthParams edgeWidthParams = EdgeWidthParams.restore(network);
EnrichmentMap map = emManager.getEnrichmentMap(network.getSUID());
// String widthAttribute = prefix + EDGE_WIDTH_FORMULA_COLUMN;
int n = network.getDefaultEdgeTable().getRowCount();
int i = 0;
for (CyRow row : network.getDefaultEdgeTable().getAllRows()) {
if (taskMonitor != null)
taskMonitor.setProgress((double) i / (double) n);
i++;
String interaction = row.get(CyEdge.INTERACTION, String.class);
if (isSignature(interaction)) {
String cutoffType = EDGE_CUTOFF_TYPE.get(row, prefix, null);
PostAnalysisFilterType filterType = PostAnalysisFilterType.fromDisplayString(cutoffType);
if (filterType == null) {
EDGE_WIDTH_FORMULA_COLUMN.set(row, prefix, null, null);
continue;
}
Double pvalue, cutoff;
switch(filterType) {
case MANN_WHIT_TWO_SIDED:
pvalue = EDGE_MANN_WHIT_TWOSIDED_PVALUE.get(row, prefix);
cutoff = EDGE_MANN_WHIT_CUTOFF.get(row, prefix);
break;
case MANN_WHIT_GREATER:
pvalue = EDGE_MANN_WHIT_GREATER_PVALUE.get(row, prefix);
cutoff = EDGE_MANN_WHIT_CUTOFF.get(row, prefix);
break;
case MANN_WHIT_LESS:
pvalue = EDGE_MANN_WHIT_LESS_PVALUE.get(row, prefix);
cutoff = EDGE_MANN_WHIT_CUTOFF.get(row, prefix);
break;
default:
pvalue = EDGE_HYPERGEOM_PVALUE.get(row, prefix);
cutoff = EDGE_HYPERGEOM_CUTOFF.get(row, prefix);
break;
}
if (pvalue == null || cutoff == null) {
EDGE_WIDTH_FORMULA_COLUMN.set(row, prefix, null);
} else if (pvalue <= cutoff / 100) {
EDGE_WIDTH_FORMULA_COLUMN.set(row, prefix, edgeWidthParams.pa_lessThan100);
} else if (pvalue <= cutoff / 10) {
EDGE_WIDTH_FORMULA_COLUMN.set(row, prefix, edgeWidthParams.pa_lessThan10);
} else {
EDGE_WIDTH_FORMULA_COLUMN.set(row, prefix, edgeWidthParams.pa_greater);
}
} else {
// Can use a continuous mapping object to perform calculation
// even though it won't be added to the visual style.
ContinuousMapping<Double, Double> conmapping_edgewidth = (ContinuousMapping<Double, Double>) vmfFactoryContinuous.createVisualMappingFunction(prefix + EDGE_SIMILARITY_COEFF, Double.class, BasicVisualLexicon.EDGE_WIDTH);
Double under_width = 0.5;
Double min_width = edgeWidthParams.em_lower;
Double max_width = edgeWidthParams.em_upper;
Double over_width = 6.0;
// Create boundary conditions less than, equals, greater than
BoundaryRangeValues<Double> bv4 = new BoundaryRangeValues<>(under_width, min_width, min_width);
BoundaryRangeValues<Double> bv5 = new BoundaryRangeValues<>(max_width, max_width, over_width);
conmapping_edgewidth.addPoint(map.getParams().getSimilarityCutoff(), bv4);
conmapping_edgewidth.addPoint(1.0, bv5);
Double value = conmapping_edgewidth.getMappedValue(row);
EDGE_WIDTH_FORMULA_COLUMN.set(row, prefix, value);
}
}
}
Aggregations