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