Search in sources :

Example 1 with CyColumn

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);
}
Also used : ArrayList(java.util.ArrayList) CyColumn(org.cytoscape.model.CyColumn) CyRow(org.cytoscape.model.CyRow)

Example 2 with CyColumn

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());
}
Also used : PaxExam(org.ops4j.pax.exam.junit.PaxExam) Arrays(java.util.Arrays) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) TaskIterator(org.cytoscape.work.TaskIterator) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) CyRow(org.cytoscape.model.CyRow) CyNetwork(org.cytoscape.model.CyNetwork) Map(java.util.Map) CyColumn(org.cytoscape.model.CyColumn) CyTable(org.cytoscape.model.CyTable) ImmutableSet(com.google.common.collect.ImmutableSet) LoadNetworkFileTaskFactory(org.cytoscape.task.read.LoadNetworkFileTaskFactory) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Set(java.util.Set) IOException(java.io.IOException) CyNetworkManager(org.cytoscape.model.CyNetworkManager) Collectors(java.util.stream.Collectors) File(java.io.File) List(java.util.List) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork) Comparator(java.util.Comparator) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) HashMap(java.util.HashMap) CyColumn(org.cytoscape.model.CyColumn) CyRow(org.cytoscape.model.CyRow)

Example 3 with CyColumn

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);
        }
    //			}
    }
}
Also used : CyColumn(org.cytoscape.model.CyColumn)

Example 4 with CyColumn

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);
}
Also used : CyColumn(org.cytoscape.model.CyColumn) CyRow(org.cytoscape.model.CyRow)

Example 5 with CyColumn

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);
        }
    }
}
Also used : PaxExam(org.ops4j.pax.exam.junit.PaxExam) Arrays(java.util.Arrays) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) TaskIterator(org.cytoscape.work.TaskIterator) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) CyRow(org.cytoscape.model.CyRow) CyNetwork(org.cytoscape.model.CyNetwork) Map(java.util.Map) CyColumn(org.cytoscape.model.CyColumn) CyTable(org.cytoscape.model.CyTable) ImmutableSet(com.google.common.collect.ImmutableSet) LoadNetworkFileTaskFactory(org.cytoscape.task.read.LoadNetworkFileTaskFactory) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Set(java.util.Set) IOException(java.io.IOException) CyNetworkManager(org.cytoscape.model.CyNetworkManager) Collectors(java.util.stream.Collectors) File(java.io.File) List(java.util.List) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork) Comparator(java.util.Comparator) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) ArrayList(java.util.ArrayList) 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