use of org.cytoscape.model.CyColumn in project EnrichmentMapApp by BaderLab.
the class SessionModelIO method clearTable.
private void clearTable(CyTable table) {
List<Object> rowKeys = new ArrayList<>();
CyColumn keyColumn = table.getPrimaryKey();
for (CyRow row : table.getAllRows()) {
Object key = row.get(keyColumn.getName(), keyColumn.getType());
rowKeys.add(key);
}
table.deleteRows(rowKeys);
}
use of org.cytoscape.model.CyColumn in project EnrichmentMapApp by BaderLab.
the class BaseIntegrationTest method assertEdgeTableRowsEqual.
/**
* For edges we need to ignore the directionality.
*/
private void assertEdgeTableRowsEqual(List<CyColumn> expectedColumns, List<CyRow> expectedRows, List<CyRow> actualRows) {
Set<String> columnsToIgnore = ImmutableSet.of(CyNetwork.NAME, CyRootNetwork.SHARED_NAME);
List<CyColumn> columnsToTest = expectedColumns.stream().filter(c -> !columnsToIgnore.contains(c.getName())).collect(Collectors.toList());
Map<SimilarityKey, CyRow> expectedRowsByKey = new HashMap<>();
for (CyRow row : expectedRows) {
SimilarityKey key = SimilarityKey.parse(row.get(CyNetwork.NAME, String.class));
expectedRowsByKey.put(key, row);
}
for (CyRow actual : actualRows) {
SimilarityKey key = SimilarityKey.parse(actual.get(CyNetwork.NAME, String.class));
CyRow expected = expectedRowsByKey.remove(key);
assertNotNull(key.toString(), expected);
assertAttributesEqual(columnsToTest, expected, actual);
}
assertTrue(expectedRowsByKey.isEmpty());
}
use of org.cytoscape.model.CyColumn in project EnrichmentMapApp by BaderLab.
the class BaseIntegrationTest method assertAttributesEqual.
private void assertAttributesEqual(List<CyColumn> columnsToTest, CyRow expected, CyRow actual) {
for (CyColumn column : columnsToTest) {
String name = column.getName();
Class<?> type = column.getType();
// if(!CyNetwork.SUID.equals(name)) {
Object expectedValue = expected.get(name, type);
Object actualValue = actual.get(name, type);
String message = "Col: " + name + ",";
if (type.equals(List.class)) {
// because CyListImpl doesn't implement equals()
assertArrayEquals(message, ((List<?>) expectedValue).toArray(), ((List<?>) actualValue).toArray());
} else {
assertEquals(message, expectedValue, actualValue);
}
// }
}
}
use of org.cytoscape.model.CyColumn in project EnrichmentMapApp by BaderLab.
the class BaseIntegrationTest method sort.
/**
* I don't need to actually sort the rows in a meaningful way, just make it deterministic.
*/
public void sort(List<CyColumn> columns, List<CyRow> rows) {
Comparator<CyRow> rowComparator = null;
for (CyColumn column : columns) {
// if(!CyNetwork.SUID.equals(column.getName())) {
Comparator<CyRow> c = Comparator.comparing((CyRow row) -> row.get(column.getName(), column.getType()).toString());
rowComparator = rowComparator == null ? c : rowComparator.thenComparing(c);
// }
}
Collections.sort(rows, rowComparator);
}
use of org.cytoscape.model.CyColumn in project EnrichmentMapApp by BaderLab.
the class BaseIntegrationTest method assertTablesEqual.
public void assertTablesEqual(CyTable expectedTable, CyTable actualTable, boolean edgeTable, Set<String> columnsToIgnore) {
List<CyColumn> expectedColumns = new ArrayList<>(expectedTable.getColumns());
// Remove columns to ignore
expectedColumns = expectedColumns.stream().filter(c -> !columnsToIgnore.contains(c.getName())).filter(c -> !CyNetwork.SUID.equals(c.getName())).collect(Collectors.toList());
// Test columns are the same
for (CyColumn expectedColumn : expectedColumns) {
String name = expectedColumn.getName();
// if(!CyNetwork.SUID.equals(name)) {
CyColumn actualColumn = actualTable.getColumn(name);
assertNotNull("Column '" + name + "' does not exist", actualColumn);
assertEquals("Column '" + name + "' is wrong type", expectedColumn.getType(), actualColumn.getType());
// }
}
List<CyRow> expectedRows = expectedTable.getAllRows();
List<CyRow> actualRows = actualTable.getAllRows();
assertEquals("Tables are not the same size", expectedRows.size(), actualRows.size());
if (edgeTable) {
assertEdgeTableRowsEqual(expectedColumns, expectedRows, actualRows);
} else {
// node table or other table
// need to sort both Lists
sort(expectedColumns, expectedRows);
sort(expectedColumns, actualRows);
for (int i = 0; i < expectedRows.size(); i++) {
CyRow expectedRow = expectedRows.get(i);
CyRow actualRow = actualRows.get(i);
assertAttributesEqual(expectedColumns, expectedRow, actualRow);
}
}
}
Aggregations