|
14 | 14 | import org.baderlab.csplugins.enrichmentmap.CytoscapeServiceModule.Discrete;
|
15 | 15 | import org.baderlab.csplugins.enrichmentmap.CytoscapeServiceModule.Passthrough;
|
16 | 16 | import org.baderlab.csplugins.enrichmentmap.model.EMDataSet;
|
17 |
| -import org.baderlab.csplugins.enrichmentmap.model.EMDataSet.Method; |
18 | 17 | import org.baderlab.csplugins.enrichmentmap.model.EMSignatureDataSet;
|
19 | 18 | import org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap;
|
20 | 19 | import org.baderlab.csplugins.enrichmentmap.view.util.ChartUtil;
|
@@ -71,6 +70,8 @@ public class EMStyleBuilder {
|
71 | 70 |
|
72 | 71 | private static final NodeShape SIGNATURE_NODE_SHAPE = DIAMOND;
|
73 | 72 |
|
| 73 | + public static final ColorScheme DEF_NODE_COLOR_SCHEME = ColorScheme.RD_BU_3; |
| 74 | + |
74 | 75 | public static class Columns {
|
75 | 76 | public static final String NAMESPACE = "EnrichmentMap";
|
76 | 77 | public static final String NAMESPACE_PREFIX = NAMESPACE + "::"; // added in Cytoscape 3.7
|
@@ -152,14 +153,15 @@ public static class Colors {
|
152 | 153 | public static final Color SIG_EDGE_COLOR = new Color(252, 141, 98);
|
153 | 154 | public static final Color COMPOUND_EDGE_COLOR = new Color(102, 194, 165);
|
154 | 155 |
|
155 |
| - /* See http://colorbrewer2.org/#type=diverging&scheme=RdBu&n=9 */ |
156 |
| - public static final Color MAX_PHENOTYPE_1 = new Color(178, 24, 43); |
157 |
| - public static final Color LIGHTER_PHENOTYPE_1 = new Color(214, 96, 77); |
158 |
| - public static final Color LIGHTEST_PHENOTYPE_1 = new Color(244, 165, 130); |
159 |
| - public static final Color OVER_COLOR = new Color(247, 247, 247); |
160 |
| - public static final Color MAX_PHENOTYPE_2 = new Color(33, 102, 172); |
161 |
| - public static final Color LIGHTER_PHENOTYPE_2 = new Color(67, 147, 195); |
162 |
| - public static final Color LIGHTEST_PHENOTYPE_2 = new Color(146, 197, 222); |
| 156 | +// /* See http://colorbrewer2.org/#type=diverging&scheme=RdBu&n=9 */ |
| 157 | + // These are deprecated, use ColorScheme.RD_BU_9 instead |
| 158 | + @Deprecated public static final Color MAX_PHENOTYPE_1 = new Color(178, 24, 43); |
| 159 | + @Deprecated public static final Color LIGHTER_PHENOTYPE_1 = new Color(214, 96, 77); |
| 160 | + @Deprecated public static final Color LIGHTEST_PHENOTYPE_1 = new Color(244, 165, 130); |
| 161 | + @Deprecated public static final Color OVER_COLOR = new Color(247, 247, 247); |
| 162 | + @Deprecated public static final Color MAX_PHENOTYPE_2 = new Color(33, 102, 172); |
| 163 | + @Deprecated public static final Color LIGHTER_PHENOTYPE_2 = new Color(67, 147, 195); |
| 164 | + @Deprecated public static final Color LIGHTEST_PHENOTYPE_2 = new Color(146, 197, 222); |
163 | 165 |
|
164 | 166 | public static final Color LIGHT_GREY = new Color(190, 190, 190);
|
165 | 167 | private static final Color BG_COLOR = Color.WHITE;
|
@@ -490,47 +492,57 @@ private void setNodeBorderColors(VisualStyle vs, EMStyleOptions options) {
|
490 | 492 | vs.addVisualMappingFunction(dm);
|
491 | 493 | }
|
492 | 494 |
|
| 495 | + public static ColumnDescriptor<Double> getDefaultMappingColumn(EMStyleOptions options) { |
| 496 | + var isSingleGSEA = options.getEnrichmentMap().isSingleGSEA(); |
| 497 | + if(isSingleGSEA) |
| 498 | + return Columns.NODE_LOG_PVALUE_NES; |
| 499 | + else |
| 500 | + return Columns.NODE_LOG_PVALUE_MAX; |
| 501 | + } |
493 | 502 |
|
494 |
| - private ContinuousMapping<Double,Paint> createLog10NodeColorMapping(EMStyleOptions options) { |
| 503 | + public static String getDefaultMappingColumnName(EMStyleOptions options) { |
495 | 504 | var map = options.getEnrichmentMap();
|
496 | 505 | var prefix = options.getAttributePrefix();
|
| 506 | + boolean isSingleGSEA = map.isSingleGSEA(); |
497 | 507 |
|
498 |
| - boolean isSingleGSEA = map.getDataSetCount() == 1 && map.getDataSetList().get(0).getMethod() == Method.GSEA; |
499 |
| - |
500 |
| - String logPValCol; |
501 | 508 | if(isSingleGSEA)
|
502 |
| - logPValCol = Columns.NODE_LOG_PVALUE_NES.with(prefix, map.getDataSetList().get(0)); |
| 509 | + return Columns.NODE_LOG_PVALUE_NES.with(prefix, map.getDataSetList().get(0)); |
503 | 510 | else
|
504 |
| - logPValCol = Columns.NODE_LOG_PVALUE_MAX.with(prefix); |
505 |
| - |
| 511 | + return Columns.NODE_LOG_PVALUE_MAX.with(prefix); |
| 512 | + } |
| 513 | + |
| 514 | + |
| 515 | + private ContinuousMapping<Double,Paint> createLog10NodeColorMapping(EMStyleOptions options) { |
| 516 | + var logPValCol = getDefaultMappingColumnName(options); |
506 | 517 |
|
507 | 518 | var mapping = (ContinuousMapping<Double,Paint>) cmFactory.createVisualMappingFunction(
|
508 | 519 | logPValCol, Double.class, BasicVisualLexicon.NODE_FILL_COLOR);
|
509 | 520 |
|
510 |
| - if(mapping != null) { // can happen in tests |
511 |
| - var network = options.getNetworkView().getModel(); |
512 |
| - var colList = List.of(columnIdFactory.createColumnIdentifier(logPValCol)); |
513 |
| - var range = ChartUtil.calculateGlobalRange(network, colList, true); |
514 |
| - |
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); |
519 |
| - |
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); |
525 |
| - try { |
526 |
| - if(isSingleGSEA) { |
527 |
| - mapping.addPoint(-range.max, negPoint); |
528 |
| - } |
529 |
| - mapping.addPoint(0.0, zeroPoint); |
530 |
| - mapping.addPoint(range.max, posPoint); |
531 |
| - } finally { |
532 |
| - eventHelper.unsilenceEventSource(mapping); |
| 521 | + if(mapping == null) // can happen in tests |
| 522 | + return null; |
| 523 | + |
| 524 | + var network = options.getNetworkView().getModel(); |
| 525 | + var colList = List.of(columnIdFactory.createColumnIdentifier(logPValCol)); |
| 526 | + var range = ChartUtil.calculateGlobalRange(network, colList, true); |
| 527 | + |
| 528 | + var colors = DEF_NODE_COLOR_SCHEME.getColors(); |
| 529 | + var negColor = colors.get(2); |
| 530 | + var zeroColor = colors.get(1); |
| 531 | + var posColor = colors.get(0); |
| 532 | + |
| 533 | + var negPoint = new BoundaryRangeValues<Paint>(negColor, negColor, negColor); |
| 534 | + var zeroPoint = new BoundaryRangeValues<Paint>(zeroColor, zeroColor, zeroColor); |
| 535 | + var posPoint = new BoundaryRangeValues<Paint>(posColor, posColor, posColor); |
| 536 | + |
| 537 | + eventHelper.silenceEventSource(mapping); |
| 538 | + try { |
| 539 | + if(options.getEnrichmentMap().isSingleGSEA()) { |
| 540 | + mapping.addPoint(-range.max, negPoint); |
533 | 541 | }
|
| 542 | + mapping.addPoint(0.0, zeroPoint); |
| 543 | + mapping.addPoint(range.max, posPoint); |
| 544 | + } finally { |
| 545 | + eventHelper.unsilenceEventSource(mapping); |
534 | 546 | }
|
535 | 547 |
|
536 | 548 | return mapping;
|
|
0 commit comments