Search in sources :

Example 1 with CyColumnIdentifier

use of org.cytoscape.view.presentation.property.values.CyColumnIdentifier in project EnrichmentMapApp by BaderLab.

the class AbstractChart method getSingleValueColumnNames.

/**
	 * @return The names of the data columns or an empty list if any of the data columns is of type List.
	 */
protected List<String> getSingleValueColumnNames(final CyNetwork network, final CyIdentifiable model) {
    final List<String> names = new ArrayList<>();
    final CyRow row = network.getRow(model);
    if (row == null)
        return names;
    final List<CyColumnIdentifier> dataColumns = getList(DATA_COLUMNS, CyColumnIdentifier.class);
    final CyTable table = row.getTable();
    boolean invalid = false;
    for (final CyColumnIdentifier colId : dataColumns) {
        final CyColumn column = table.getColumn(colId.getColumnName());
        if (column == null || column.getType() == List.class) {
            // Not a single value column!
            invalid = true;
            break;
        }
        names.add(colId.getColumnName());
    }
    if (invalid)
        names.clear();
    return names;
}
Also used : CyTable(org.cytoscape.model.CyTable) ArrayList(java.util.ArrayList) CyColumn(org.cytoscape.model.CyColumn) ArrayList(java.util.ArrayList) List(java.util.List) CyColumnIdentifier(org.cytoscape.view.presentation.property.values.CyColumnIdentifier) CyRow(org.cytoscape.model.CyRow)

Example 2 with CyColumnIdentifier

use of org.cytoscape.view.presentation.property.values.CyColumnIdentifier 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;
}
Also used : Color(java.awt.Color) UIManager(javax.swing.UIManager) Arrays(java.util.Arrays) CategoryLabelPositions(org.jfree.chart.axis.CategoryLabelPositions) StandardPieSectionLabelGenerator(org.jfree.chart.labels.StandardPieSectionLabelGenerator) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) CyNode(org.cytoscape.model.CyNode) PlotOrientation(org.jfree.chart.plot.PlotOrientation) NumberAxis(org.jfree.chart.axis.NumberAxis) NumberFormat(java.text.NumberFormat) ArrayList(java.util.ArrayList) CyRow(org.cytoscape.model.CyRow) StandardBarPainter(org.jfree.chart.renderer.category.StandardBarPainter) CyNetwork(org.cytoscape.model.CyNetwork) Map(java.util.Map) CyColumn(org.cytoscape.model.CyColumn) JFreeChart(org.jfree.chart.JFreeChart) ChartOptions(org.baderlab.csplugins.enrichmentmap.style.ChartOptions) CategoryAxis(org.jfree.chart.axis.CategoryAxis) Collator(java.text.Collator) RectangleInsets(org.jfree.ui.RectangleInsets) Collection(java.util.Collection) DefaultPieDataset(org.jfree.data.general.DefaultPieDataset) CyColumnIdentifier(org.cytoscape.view.presentation.property.values.CyColumnIdentifier) Collectors(java.util.stream.Collectors) ColorScheme(org.baderlab.csplugins.enrichmentmap.style.ColorScheme) ChartFactory(org.jfree.chart.ChartFactory) ColumnDescriptor(org.baderlab.csplugins.enrichmentmap.style.ColumnDescriptor) List(java.util.List) StandardPieToolTipGenerator(org.jfree.chart.labels.StandardPieToolTipGenerator) EMDataSet(org.baderlab.csplugins.enrichmentmap.model.EMDataSet) CategoryPlot(org.jfree.chart.plot.CategoryPlot) Paint(java.awt.Paint) LookAndFeelUtil(org.cytoscape.util.swing.LookAndFeelUtil) CyColumnIdentifierFactory(org.cytoscape.view.presentation.property.values.CyColumnIdentifierFactory) PiePlot(org.jfree.chart.plot.PiePlot) Collections(java.util.Collections) StandardCategoryToolTipGenerator(org.jfree.chart.labels.StandardCategoryToolTipGenerator) BarRenderer(org.jfree.chart.renderer.category.BarRenderer) ArrayList(java.util.ArrayList) CyColumn(org.cytoscape.model.CyColumn) CyColumnIdentifier(org.cytoscape.view.presentation.property.values.CyColumnIdentifier) CyRow(org.cytoscape.model.CyRow) CyNode(org.cytoscape.model.CyNode) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with CyColumnIdentifier

use of org.cytoscape.view.presentation.property.values.CyColumnIdentifier in project EnrichmentMapApp by BaderLab.

the class ChartUtil method getSortedColumnIdentifiers.

public static List<CyColumnIdentifier> getSortedColumnIdentifiers(String attributePrefix, Collection<EMDataSet> dataSets, ColumnDescriptor<Double> columnDescriptor, CyColumnIdentifierFactory columnIdFactory) {
    List<CyColumnIdentifier> columns = dataSets.stream().map(// column name
    ds -> columnDescriptor.with(attributePrefix, ds.getName())).map(// column id
    columnIdFactory::createColumnIdentifier).collect(Collectors.toList());
    // Sort the columns by name, so the chart items have the same order as the data set list
    Collator collator = Collator.getInstance();
    Collections.sort(columns, (CyColumnIdentifier o1, CyColumnIdentifier o2) -> {
        return collator.compare(o1.getColumnName(), o2.getColumnName());
    });
    return columns;
}
Also used : CyColumnIdentifier(org.cytoscape.view.presentation.property.values.CyColumnIdentifier) Collator(java.text.Collator)

Example 4 with CyColumnIdentifier

use of org.cytoscape.view.presentation.property.values.CyColumnIdentifier in project cytoscape-impl by cytoscape.

the class AbstractChart method getDataFromColumns.

public Map<String, List<Double>> getDataFromColumns(final CyNetwork network, final CyIdentifiable model, final List<CyColumnIdentifier> columnNames) {
    LinkedHashMap<String, List<Double>> data = new LinkedHashMap<>();
    final CyRow row = network.getRow(model);
    if (row == null)
        return data;
    final CyTable table = row.getTable();
    final List<Double> singleSeriesValues = new ArrayList<>();
    final StringBuilder singleSeriesKey = new StringBuilder();
    int singleSeriesIndex = -1;
    int count = 0;
    for (final CyColumnIdentifier colId : columnNames) {
        final CyColumn column = table.getColumn(colId.getColumnName());
        if (column == null)
            continue;
        final String colName = column.getName();
        final List<Double> values = new ArrayList<Double>();
        if (column.getType() == List.class) {
            // List Column: One column = one data series
            final Class<?> type = column.getListElementType();
            if (type == Double.class) {
                List<Double> list = row.getList(colName, Double.class);
                if (list != null)
                    values.addAll(list);
            } else if (type == Integer.class) {
                List<Integer> list = row.getList(colName, Integer.class);
                if (list != null) {
                    for (Integer i : list) values.add(i.doubleValue());
                }
            } else if (type == Long.class) {
                List<Long> list = row.getList(colName, Long.class);
                if (list != null) {
                    for (Long l : list) values.add(l.doubleValue());
                }
            } else if (type == Float.class) {
                List<Float> list = row.getList(colName, Float.class);
                if (list != null) {
                    for (Float f : list) values.add(f.doubleValue());
                }
            }
            data.put(colName, values);
        } else {
            // Single Column: All single columns together make only one data series
            final Class<?> type = column.getType();
            if (Number.class.isAssignableFrom(type)) {
                if (!row.isSet(colName)) {
                    singleSeriesValues.add(Double.NaN);
                } else if (type == Double.class) {
                    singleSeriesValues.add(row.get(colName, Double.class));
                } else if (type == Integer.class) {
                    Integer i = row.get(colName, Integer.class);
                    singleSeriesValues.add(i.doubleValue());
                } else if (type == Float.class) {
                    Float f = row.get(colName, Float.class);
                    singleSeriesValues.add(f.doubleValue());
                }
                singleSeriesKey.append(colName + ",");
                // The index of this data series is the index of the first single column
                if (singleSeriesIndex == -1)
                    singleSeriesIndex = count;
            }
        }
        count++;
    }
    if (!singleSeriesValues.isEmpty()) {
        singleSeriesKey.deleteCharAt(singleSeriesKey.length() - 1);
        // To add the series of single columns into the correct position, we have to rebuild the data map
        final Set<Entry<String, List<Double>>> entrySet = data.entrySet();
        data = new LinkedHashMap<>();
        int i = 0;
        for (final Entry<String, List<Double>> entry : entrySet) {
            if (i == singleSeriesIndex)
                data.put(singleSeriesKey.toString(), singleSeriesValues);
            data.put(entry.getKey(), entry.getValue());
            i++;
        }
        if (// (entrySet.isEmpty() || i >= entrySet.size())
        !data.containsKey(singleSeriesKey.toString()))
            data.put(singleSeriesKey.toString(), singleSeriesValues);
    }
    return data;
}
Also used : ArrayList(java.util.ArrayList) CyColumn(org.cytoscape.model.CyColumn) CyColumnIdentifier(org.cytoscape.view.presentation.property.values.CyColumnIdentifier) CyRow(org.cytoscape.model.CyRow) LinkedHashMap(java.util.LinkedHashMap) CyTable(org.cytoscape.model.CyTable) Entry(java.util.Map.Entry) ArrayList(java.util.ArrayList) List(java.util.List)

Example 5 with CyColumnIdentifier

use of org.cytoscape.view.presentation.property.values.CyColumnIdentifier in project cytoscape-impl by cytoscape.

the class AbstractChart method getItemLabels.

protected List<String> getItemLabels(final CyNetwork network, final CyIdentifiable model) {
    List<String> labels = getList(ITEM_LABELS, String.class);
    if (labels == null || labels.isEmpty()) {
        final CyColumnIdentifier labelsColumn = get(ITEM_LABELS_COLUMN, CyColumnIdentifier.class);
        labels = getLabelsFromColumn(network, model, labelsColumn);
    }
    return labels;
}
Also used : CyColumnIdentifier(org.cytoscape.view.presentation.property.values.CyColumnIdentifier)

Aggregations

CyColumnIdentifier (org.cytoscape.view.presentation.property.values.CyColumnIdentifier)21 Color (java.awt.Color)6 ArrayList (java.util.ArrayList)6 List (java.util.List)6 CyColumn (org.cytoscape.model.CyColumn)6 CyRow (org.cytoscape.model.CyRow)6 AbstractCustomGraphics2Test (org.cytoscape.ding.customgraphics.AbstractCustomGraphics2Test)5 ColorScheme (org.cytoscape.ding.customgraphics.ColorScheme)5 CyTable (org.cytoscape.model.CyTable)4 Test (org.junit.Test)4 ActionEvent (java.awt.event.ActionEvent)3 ActionListener (java.awt.event.ActionListener)3 Orientation (org.cytoscape.ding.customgraphics.Orientation)3 MappableVisualPropertyValue (org.cytoscape.view.presentation.property.values.MappableVisualPropertyValue)3 Collator (java.text.Collator)2 HashSet (java.util.HashSet)2 LinkedHashMap (java.util.LinkedHashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 Entry (java.util.Map.Entry)2 Set (java.util.Set)2