Search in sources :

Example 56 with EMDataSet

use of org.baderlab.csplugins.enrichmentmap.model.EMDataSet in project EnrichmentMapApp by BaderLab.

the class ModelSerializer method deserialize.

public static EnrichmentMap deserialize(String json) {
    Type immutableIntSetType = new TypeToken<ImmutableSet<Integer>>() {
    }.getType();
    Gson gson = new GsonBuilder().registerTypeAdapter(BiMap.class, new BiMapAdapter()).registerTypeHierarchyAdapter(Path.class, new PathAdapter()).registerTypeAdapter(EnrichmentResult.class, new EnrichmentResultAdapter()).registerTypeAdapter(immutableIntSetType, new ImmutableIntSetAdapter()).create();
    try {
        EnrichmentMap map = gson.fromJson(json, EnrichmentMap.class);
        for (EMDataSet dataset : map.getDataSetList()) {
            dataset.setParent(map);
        }
        return map;
    } catch (JsonParseException e) {
        logger.error(e.getMessage(), e);
        return null;
    }
}
Also used : Path(java.nio.file.Path) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) EnrichmentMap(org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap) JsonParseException(com.google.gson.JsonParseException) Type(java.lang.reflect.Type) ImmutableSet(com.google.common.collect.ImmutableSet) EMDataSet(org.baderlab.csplugins.enrichmentmap.model.EMDataSet)

Example 57 with EMDataSet

use of org.baderlab.csplugins.enrichmentmap.model.EMDataSet in project EnrichmentMapApp by BaderLab.

the class ChartUtil method createRadialHeatMapLegend.

public static JFreeChart createRadialHeatMapLegend(List<EMDataSet> dataSets, ChartOptions options) {
    // All the slices must have the same size
    final DefaultPieDataset pieDataset = new DefaultPieDataset();
    for (EMDataSet ds : dataSets) pieDataset.setValue(ds.getName(), 1);
    JFreeChart chart = ChartFactory.createPieChart(// chart title
    null, // data
    pieDataset, // include legend
    false, // tooltips
    true, // urls
    false);
    chart.setAntiAlias(true);
    chart.setBorderVisible(false);
    chart.setBackgroundPaint(UIManager.getColor("Table.background"));
    chart.setBackgroundImageAlpha(0.0f);
    chart.setPadding(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
    final PiePlot plot = (PiePlot) chart.getPlot();
    plot.setCircular(true);
    plot.setOutlineVisible(false);
    plot.setBackgroundPaint(UIManager.getColor("Table.background"));
    plot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
    plot.setShadowPaint(TRANSPARENT_COLOR);
    plot.setShadowXOffset(0.0);
    plot.setShadowYOffset(0.0);
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}"));
    plot.setLabelFont(UIManager.getFont("Label.font").deriveFont(LookAndFeelUtil.getSmallFontSize()));
    plot.setLabelPaint(UIManager.getColor("Label.foreground"));
    plot.setLabelBackgroundPaint(TRANSPARENT_COLOR);
    plot.setLabelOutlinePaint(TRANSPARENT_COLOR);
    plot.setLabelShadowPaint(TRANSPARENT_COLOR);
    plot.setToolTipGenerator(new StandardPieToolTipGenerator("{0}"));
    ColorScheme colorScheme = options != null ? options.getColorScheme() : null;
    List<Color> colors = colorScheme != null ? colorScheme.getColors() : null;
    if (// UP, ZERO, DOWN:
    colors == null || colors.size() < 3)
        colors = Arrays.asList(new Color[] { Color.LIGHT_GRAY, Color.WHITE, Color.DARK_GRAY });
    int total = dataSets.size();
    int v = total / -2;
    for (EMDataSet ds : dataSets) {
        plot.setSectionPaint(ds.getName(), ColorUtil.getColor(v, -total, total, colors.get(2), colors.get(1), colors.get(0)));
        v++;
    }
    return chart;
}
Also used : DefaultPieDataset(org.jfree.data.general.DefaultPieDataset) StandardPieToolTipGenerator(org.jfree.chart.labels.StandardPieToolTipGenerator) Color(java.awt.Color) ColorScheme(org.baderlab.csplugins.enrichmentmap.style.ColorScheme) RectangleInsets(org.jfree.ui.RectangleInsets) PiePlot(org.jfree.chart.plot.PiePlot) EMDataSet(org.baderlab.csplugins.enrichmentmap.model.EMDataSet) StandardPieSectionLabelGenerator(org.jfree.chart.labels.StandardPieSectionLabelGenerator) JFreeChart(org.jfree.chart.JFreeChart) Paint(java.awt.Paint)

Example 58 with EMDataSet

use of org.baderlab.csplugins.enrichmentmap.model.EMDataSet in project EnrichmentMapApp by BaderLab.

the class ChartUtil method createHeatMapLegend.

@SuppressWarnings("serial")
public static JFreeChart createHeatMapLegend(List<EMDataSet> dataSets, ChartOptions options) {
    final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (EMDataSet ds : dataSets) dataset.addValue(1, options.getData().toString(), ds.getName());
    final JFreeChart chart = ChartFactory.createBarChart(// chart title
    null, // domain axis label
    null, // range axis label
    null, // data
    dataset, PlotOrientation.HORIZONTAL, // include legend
    false, // tooltips
    true, // urls
    false);
    chart.setAntiAlias(true);
    chart.setBorderVisible(false);
    chart.setBackgroundPaint(UIManager.getColor("Table.background"));
    chart.setBackgroundImageAlpha(0.0f);
    chart.setPadding(new RectangleInsets(0.0, 0.0, 0.0, 20.0));
    final CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setOutlineVisible(false);
    plot.setBackgroundPaint(UIManager.getColor("Table.background"));
    plot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);
    final CategoryAxis domainAxis = (CategoryAxis) plot.getDomainAxis();
    domainAxis.setVisible(true);
    domainAxis.setAxisLineVisible(false);
    domainAxis.setTickMarksVisible(false);
    domainAxis.setTickLabelFont(UIManager.getFont("Label.font").deriveFont(LookAndFeelUtil.getSmallFontSize()));
    domainAxis.setTickLabelPaint(UIManager.getColor("Label.foreground"));
    domainAxis.setTickLabelInsets(new RectangleInsets(0.0, 0.0, 0.0, 15.0));
    domainAxis.setCategoryMargin(0.0);
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setVisible(false);
    ColorScheme colorScheme = options != null ? options.getColorScheme() : null;
    List<Color> colors = colorScheme != null ? colorScheme.getColors() : null;
    if (// UP, ZERO, DOWN:
    colors == null || colors.size() < 3)
        colors = Arrays.asList(new Color[] { Color.LIGHT_GRAY, Color.WHITE, Color.DARK_GRAY });
    List<Color> itemColors = new ArrayList<>();
    int total = dataSets.size();
    int v = total / 2;
    for (int i = 0; i < total; i++) itemColors.add(ColorUtil.getColor(v--, -total, total, colors.get(2), colors.get(1), colors.get(0)));
    final BarRenderer renderer = new BarRenderer() {

        @Override
        public Paint getItemPaint(int row, int column) {
            return column < itemColors.size() ? itemColors.get(column) : Color.LIGHT_GRAY;
        }
    };
    plot.setRenderer(renderer);
    renderer.setBarPainter(new StandardBarPainter());
    renderer.setDrawBarOutline(true);
    renderer.setShadowVisible(false);
    renderer.setItemMargin(0.0);
    renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator("{1}", NumberFormat.getInstance()));
    return chart;
}
Also used : NumberAxis(org.jfree.chart.axis.NumberAxis) Color(java.awt.Color) ColorScheme(org.baderlab.csplugins.enrichmentmap.style.ColorScheme) ArrayList(java.util.ArrayList) BarRenderer(org.jfree.chart.renderer.category.BarRenderer) JFreeChart(org.jfree.chart.JFreeChart) CategoryPlot(org.jfree.chart.plot.CategoryPlot) Paint(java.awt.Paint) CategoryAxis(org.jfree.chart.axis.CategoryAxis) StandardCategoryToolTipGenerator(org.jfree.chart.labels.StandardCategoryToolTipGenerator) StandardBarPainter(org.jfree.chart.renderer.category.StandardBarPainter) RectangleInsets(org.jfree.ui.RectangleInsets) EMDataSet(org.baderlab.csplugins.enrichmentmap.model.EMDataSet) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset)

Aggregations

EMDataSet (org.baderlab.csplugins.enrichmentmap.model.EMDataSet)58 EnrichmentMap (org.baderlab.csplugins.enrichmentmap.model.EnrichmentMap)30 DataSetFiles (org.baderlab.csplugins.enrichmentmap.model.DataSetFiles)20 Test (org.junit.Test)19 Method (org.baderlab.csplugins.enrichmentmap.model.EMDataSet.Method)13 EnrichmentMapParameters (org.baderlab.csplugins.enrichmentmap.model.EnrichmentMapParameters)11 Map (java.util.Map)10 EMCreationParameters (org.baderlab.csplugins.enrichmentmap.model.EMCreationParameters)10 Set (java.util.Set)8 EnrichmentResult (org.baderlab.csplugins.enrichmentmap.model.EnrichmentResult)8 GeneSet (org.baderlab.csplugins.enrichmentmap.model.GeneSet)7 CyNode (org.cytoscape.model.CyNode)7 JPanel (javax.swing.JPanel)6 Inject (com.google.inject.Inject)5 Color (java.awt.Color)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 JLabel (javax.swing.JLabel)5 CyEdge (org.cytoscape.model.CyEdge)5 CyNetwork (org.cytoscape.model.CyNetwork)5