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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations