|
9 | 9 | import java.awt.Color;
|
10 | 10 | import java.awt.Paint;
|
11 | 11 | import java.util.List;
|
12 |
| -import java.util.stream.Collectors; |
13 | 12 |
|
14 | 13 | import org.baderlab.csplugins.enrichmentmap.CytoscapeServiceModule.Continuous;
|
15 | 14 | import org.baderlab.csplugins.enrichmentmap.CytoscapeServiceModule.Discrete;
|
16 | 15 | import org.baderlab.csplugins.enrichmentmap.CytoscapeServiceModule.Passthrough;
|
17 |
| -import org.baderlab.csplugins.enrichmentmap.model.AbstractDataSet; |
18 | 16 | import org.baderlab.csplugins.enrichmentmap.model.EMDataSet;
|
| 17 | +import org.baderlab.csplugins.enrichmentmap.model.EMDataSet.Method; |
19 | 18 | import org.baderlab.csplugins.enrichmentmap.model.EMSignatureDataSet;
|
20 | 19 | import org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap;
|
21 | 20 | import org.baderlab.csplugins.enrichmentmap.view.util.ChartUtil;
|
@@ -491,77 +490,74 @@ private void setNodeBorderColors(VisualStyle vs, EMStyleOptions options) {
|
491 | 490 | vs.addVisualMappingFunction(dm);
|
492 | 491 | }
|
493 | 492 |
|
494 |
| - private void setNodeColors(VisualStyle vs, EMStyleOptions options) { |
495 |
| - String prefix = options.getAttributePrefix(); |
496 |
| - List<AbstractDataSet> dataSets = options.getDataSets().stream() |
497 |
| - .filter(ds -> ds instanceof EMDataSet) // Ignore Signature Data Sets in charts |
498 |
| - .collect(Collectors.toList()); |
499 |
| - |
500 |
| - if (dataSets.size() == 1) { |
501 |
| - // Only 1 Data Set? Set a continuous mapping for node colour... |
502 |
| - CyNetworkView netView = options.getNetworkView(); |
503 |
| - CyNetwork net = netView.getModel(); |
504 |
| - |
505 |
| - var logPValCol = Columns.NODE_LOG_PVALUE_MAX.with(prefix); |
506 |
| - |
| 493 | + |
| 494 | + private ContinuousMapping<Double,Paint> createLog10NodeColorMapping(EMStyleOptions options) { |
| 495 | + var map = options.getEnrichmentMap(); |
| 496 | + var prefix = options.getAttributePrefix(); |
| 497 | + |
| 498 | + boolean isSingleGSEA = map.getDataSetCount() == 1 && map.getDataSetList().get(0).getMethod() == Method.GSEA; |
| 499 | + |
| 500 | + String logPValCol; |
| 501 | + if(isSingleGSEA) |
| 502 | + logPValCol = Columns.NODE_LOG_PVALUE_NES.with(prefix, map.getDataSetList().get(0)); |
| 503 | + else |
| 504 | + logPValCol = Columns.NODE_LOG_PVALUE_MAX.with(prefix); |
| 505 | + |
| 506 | + |
| 507 | + var mapping = (ContinuousMapping<Double,Paint>) cmFactory.createVisualMappingFunction( |
| 508 | + logPValCol, Double.class, BasicVisualLexicon.NODE_FILL_COLOR); |
| 509 | + |
| 510 | + if(mapping != null) { // can happen in tests |
| 511 | + var network = options.getNetworkView().getModel(); |
507 | 512 | var colList = List.of(columnIdFactory.createColumnIdentifier(logPValCol));
|
508 |
| - var range = ChartUtil.calculateGlobalRange(net, colList); |
509 |
| - var min = range.get(0); |
510 |
| - var max = range.get(1); |
511 |
| - |
512 |
| - // Continuous Mapping - set node colour based on the sign of the ES score of the dataset |
513 |
| - var cm = (ContinuousMapping<Double, Paint>) cmFactory.createVisualMappingFunction( |
514 |
| - logPValCol, Double.class, BasicVisualLexicon.NODE_FILL_COLOR); |
515 |
| - |
516 |
| - var color0 = ColorScheme.RD_BU_3.getColors().get(1); |
517 |
| - var color1 = ColorScheme.RD_BU_3.getColors().get(0); |
| 513 | + var range = ChartUtil.calculateGlobalRange(network, colList, true); |
518 | 514 |
|
519 |
| - var point0 = new BoundaryRangeValues<Paint>(color0, color0, color0); |
520 |
| - var point1 = new BoundaryRangeValues<Paint>(color1, color1, color1); |
| 515 | + var colors = ColorScheme.RD_BU_3.getColors(); |
| 516 | + var negColor = colors.get(2); |
| 517 | + var zeroColor = colors.get(1); |
| 518 | + var posColor = colors.get(0); |
521 | 519 |
|
522 |
| - eventHelper.silenceEventSource(cm); |
| 520 | + var negPoint = new BoundaryRangeValues<Paint>(negColor, negColor, negColor); |
| 521 | + var zeroPoint = new BoundaryRangeValues<Paint>(zeroColor, zeroColor, zeroColor); |
| 522 | + var posPoint = new BoundaryRangeValues<Paint>(posColor, posColor, posColor); |
| 523 | + |
| 524 | + eventHelper.silenceEventSource(mapping); |
523 | 525 | try {
|
524 |
| - cm.addPoint(min, point0); |
525 |
| - cm.addPoint(max, point1); |
| 526 | + if(isSingleGSEA) { |
| 527 | + mapping.addPoint(-range.max, negPoint); |
| 528 | + } |
| 529 | + mapping.addPoint(0.0, zeroPoint); |
| 530 | + mapping.addPoint(range.max, posPoint); |
526 | 531 | } finally {
|
527 |
| - eventHelper.unsilenceEventSource(cm); |
| 532 | + eventHelper.unsilenceEventSource(mapping); |
528 | 533 | }
|
529 |
| - |
530 |
| - vs.addVisualMappingFunction(cm); |
531 |
| - |
532 |
| - // Then we need to use bypass to colour the hub nodes (signature genesets) |
533 |
| - List<EMSignatureDataSet> signatureDataSets = options.getEnrichmentMap().getSignatureSetList(); |
534 |
| - |
535 |
| - // For "signature" nodes that were added by Post Analysis |
536 |
| - for (EMSignatureDataSet sds : signatureDataSets) { |
537 |
| - for (Long suid : sds.getNodeSuids()) { |
538 |
| - CyNode node = net.getNode(suid); |
539 |
| - if (node != null) { |
540 |
| - View<CyNode> nv = netView.getNodeView(node); |
541 |
| - if (nv != null) { |
542 |
| - nv.setLockedValue(NODE_FILL_COLOR, Colors.SIG_NODE_COLOR); |
543 |
| - } |
| 534 | + } |
| 535 | + |
| 536 | + return mapping; |
| 537 | + } |
| 538 | + |
| 539 | + |
| 540 | + private void setNodeColors(VisualStyle vs, EMStyleOptions options) { |
| 541 | + CyNetworkView netView = options.getNetworkView(); |
| 542 | + CyNetwork net = netView.getModel(); |
| 543 | + |
| 544 | + var mapping = createLog10NodeColorMapping(options); |
| 545 | + vs.addVisualMappingFunction(mapping); |
| 546 | + |
| 547 | + // Then we need to use bypass to colour the hub nodes (signature genesets) |
| 548 | + List<EMSignatureDataSet> signatureDataSets = options.getEnrichmentMap().getSignatureSetList(); |
| 549 | + |
| 550 | + // For "signature" nodes that were added by Post Analysis |
| 551 | + for (EMSignatureDataSet sds : signatureDataSets) { |
| 552 | + for (Long suid : sds.getNodeSuids()) { |
| 553 | + CyNode node = net.getNode(suid); |
| 554 | + if (node != null) { |
| 555 | + View<CyNode> nv = netView.getNodeView(node); |
| 556 | + if (nv != null) { |
| 557 | + nv.setLockedValue(NODE_FILL_COLOR, Colors.SIG_NODE_COLOR); |
544 | 558 | }
|
545 | 559 | }
|
546 | 560 | }
|
547 |
| - |
548 |
| - } else { |
549 |
| - // 2 or more Data Sets? Use simple node colours and charts... |
550 |
| - // Add mapping function for node fill color |
551 |
| - var dm = (DiscreteMapping<String, Paint>) dmFactory.createVisualMappingFunction( |
552 |
| - Columns.NODE_GS_TYPE.with(prefix, null), String.class, NODE_FILL_COLOR); |
553 |
| - |
554 |
| - // Silence events fired by this mapping to prevent unnecessary style and view updates |
555 |
| - eventHelper.silenceEventSource(dm); |
556 |
| - |
557 |
| - try { |
558 |
| - dm.putMapValue(Columns.NODE_GS_TYPE_ENRICHMENT, Colors.DEF_NODE_COLOR); |
559 |
| - dm.putMapValue(Columns.NODE_GS_TYPE_SIGNATURE, Colors.SIG_NODE_COLOR); |
560 |
| - } finally { |
561 |
| - eventHelper.unsilenceEventSource(dm); |
562 |
| - } |
563 |
| - |
564 |
| - vs.addVisualMappingFunction(dm); |
565 | 561 | }
|
566 | 562 | }
|
567 | 563 |
|
|
0 commit comments