Search in sources :

Example 6 with CyColumn

use of org.cytoscape.model.CyColumn 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 7 with CyColumn

use of org.cytoscape.model.CyColumn in project EnrichmentMapApp by BaderLab.

the class AbstractChart method getLabelsFromColumn.

@SuppressWarnings("unchecked")
public List<String> getLabelsFromColumn(final CyNetwork network, final CyIdentifiable model, final CyColumnIdentifier columnId) {
    final List<String> labels = new ArrayList<>();
    final CyRow row = network.getRow(model);
    if (row != null && columnId != null) {
        final CyTable table = row.getTable();
        final CyColumn column = table.getColumn(columnId.getColumnName());
        if (column != null && column.getType() == List.class) {
            final Class<?> type = column.getListElementType();
            final List<?> values = row.getList(columnId.getColumnName(), type);
            if (type == String.class) {
                labels.addAll((List<String>) values);
            } else {
                for (Object obj : values) labels.add(obj.toString());
            }
        }
    }
    return labels;
}
Also used : CyTable(org.cytoscape.model.CyTable) ArrayList(java.util.ArrayList) CyColumn(org.cytoscape.model.CyColumn) ArrayList(java.util.ArrayList) List(java.util.List) CyRow(org.cytoscape.model.CyRow)

Example 8 with CyColumn

use of org.cytoscape.model.CyColumn 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 9 with CyColumn

use of org.cytoscape.model.CyColumn in project cytoscape-api by cytoscape.

the class AbstractCyNetworkReader method getTargetColumns.

private final ListSingleSelection<String> getTargetColumns(final CyNetwork network) {
    final CyTable selectedTable = network.getTable(CyNode.class, CyRootNetwork.SHARED_ATTRS);
    final List<String> colNames = new ArrayList<>();
    for (CyColumn col : selectedTable.getColumns()) {
        // Exclude SUID from the mapping key list
        if (!col.getName().equalsIgnoreCase(CyIdentifiable.SUID) && !col.getName().endsWith(".SUID") && (col.getType() == String.class || col.getType() == Integer.class || col.getType() == Long.class))
            colNames.add(col.getName());
    }
    if (colNames.isEmpty() || (colNames.size() == 1 && colNames.contains(CyRootNetwork.SHARED_NAME)))
        return new ListSingleSelection<>();
    sort(colNames);
    return new ListSingleSelection<>(colNames);
}
Also used : CyTable(org.cytoscape.model.CyTable) ListSingleSelection(org.cytoscape.work.util.ListSingleSelection) ArrayList(java.util.ArrayList) CyColumn(org.cytoscape.model.CyColumn)

Example 10 with CyColumn

use of org.cytoscape.model.CyColumn in project cytoscape-api by cytoscape.

the class EquationUtil method refreshEquations.

/** Refreshes all the equations in the given CyTable
	 *  @param table the CyTable
	 *  @param compiler an EquationCompiler
	 */
public static void refreshEquations(CyTable table, EquationCompiler compiler) {
    Map<String, Class<?>> variableNameToTypeMap = new HashMap<String, Class<?>>();
    for (CyColumn column : table.getColumns()) {
        variableNameToTypeMap.put(column.getName(), column.getType() == Integer.class ? Long.class : column.getType());
    }
    for (CyRow row : table.getAllRows()) {
        for (CyColumn column : table.getColumns()) {
            String name = column.getName();
            Object value = row.getRaw(name);
            if (!(value instanceof Equation)) {
                continue;
            }
            Equation equation = (Equation) value;
            final Class<?> columnType = column.getType();
            final Class<?> listElementType = column.getListElementType();
            final Class<?> expectedType = variableNameToTypeMap.remove(name);
            try {
                if (compiler.compile(equation.toString(), variableNameToTypeMap)) {
                    final Class<?> eqnType = compiler.getEquation().getType();
                    if (eqnTypeIsCompatible(columnType, listElementType, eqnType))
                        equation = compiler.getEquation();
                    else {
                        final String errorMsg = "Equation result type is " + getUnqualifiedName(eqnType) + ", column type is " + getUnqualifiedName(columnType) + ".";
                        equation = compiler.getErrorEquation(equation.toString(), expectedType, errorMsg);
                    }
                    row.set(name, compiler.getEquation());
                }
            } catch (Exception e) {
                logger.error("Unexpected error while restoring equation: " + equation.toString(), e);
            }
            variableNameToTypeMap.put(name, expectedType);
        }
    }
}
Also used : HashMap(java.util.HashMap) CyColumn(org.cytoscape.model.CyColumn) CyRow(org.cytoscape.model.CyRow)

Aggregations

CyColumn (org.cytoscape.model.CyColumn)16 CyRow (org.cytoscape.model.CyRow)10 CyTable (org.cytoscape.model.CyTable)10 ArrayList (java.util.ArrayList)9 List (java.util.List)6 Test (org.junit.Test)4 Arrays (java.util.Arrays)3 Collections (java.util.Collections)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Collectors (java.util.stream.Collectors)3 CyNetwork (org.cytoscape.model.CyNetwork)3 CyColumnIdentifier (org.cytoscape.view.presentation.property.values.CyColumnIdentifier)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 File (java.io.File)2 IOException (java.io.IOException)2 Comparator (java.util.Comparator)2 Set (java.util.Set)2 Inject (javax.inject.Inject)2 CyNetworkManager (org.cytoscape.model.CyNetworkManager)2