Search in sources :

Example 86 with CyTable

use of org.cytoscape.model.CyTable in project cytoscape-impl by cytoscape.

the class GraphMLWriter method writeEdges.

private void writeEdges(Document doc, Element parent) {
    final List<CyEdge> edges = network.getEdgeList();
    final CyTable table = network.getDefaultEdgeTable();
    final Collection<CyColumn> edgeColumns = table.getColumns();
    for (final CyEdge edge : edges) {
        final Element edgeElm = doc.createElement(EDGE);
        edgeElm.setAttribute(SOURCE, edge.getSource().getSUID().toString());
        edgeElm.setAttribute(TARGET, edge.getTarget().getSUID().toString());
        final CyRow row = network.getRow(edge);
        appendData(row, edgeColumns, doc, edgeElm, edge);
        parent.appendChild(edgeElm);
    }
}
Also used : CyTable(org.cytoscape.model.CyTable) Element(org.w3c.dom.Element) CyColumn(org.cytoscape.model.CyColumn) CyRow(org.cytoscape.model.CyRow) CyEdge(org.cytoscape.model.CyEdge)

Example 87 with CyTable

use of org.cytoscape.model.CyTable in project cytoscape-impl by cytoscape.

the class PerformanceScaffold method main.

public static void main(String[] args) {
    NetworkTestSupport testSupport = new NetworkTestSupport();
    CyNetwork network = testSupport.getNetwork();
    CyTable nodeTable = network.getDefaultNodeTable();
    nodeTable.createColumn(STRING_COLUMN, String.class, false);
    nodeTable.createColumn(INTEGER_COLUMN, Integer.class, false);
    nodeTable.createListColumn(LIST_STRING_COLUMN, String.class, false);
    // Use a fixed set of string attributes.
    // Worst case performance for trie expected for first entry
    // Best case performance expected for last entry
    Random random = new Random(1);
    String[] values = { "AAAAAAAAAAAAAAA", "AAAAAAAAAAAAAAB", "AAAAAAAAAAAAACA", "AAAAAAAAAAAADAA", "AAAAAAAAAAAEAAA", "AAAAAAAAAAFAAAA", "AAAAAAAAAGAAAAA", "AAAAAAAAHAAAAAA", "AAAAAAAIAAAAAAA", "AAAAAAJAAAAAAAA", "AAAAAKAAAAAAAAA", "AAAALAAAAAAAAAA", "AAAMAAAAAAAAAAA", "AANAAAAAAAAAAAA", "AOAAAAAAAAAAAAA", "PAAAAAAAAAAAAAA" };
    int totalNodes = TOTAL_NODES;
    int totalEdges = totalNodes * AVERAGE_EDGES_PER_NODE;
    long start;
    start = System.currentTimeMillis();
    List<CyNode> nodes = new ArrayList<CyNode>();
    for (int i = 0; i < totalNodes; i++) {
        CyNode node = network.addNode();
        int valueIndex = random.nextInt(values.length);
        network.getRow(node).set(STRING_COLUMN, values[valueIndex]);
        network.getRow(node).set(INTEGER_COLUMN, valueIndex);
        network.getRow(node).set(LIST_STRING_COLUMN, Collections.singletonList(values[valueIndex]));
        nodes.add(node);
    }
    // Construct random graph
    for (int i = 0; i < totalEdges; i++) {
        CyNode source = nodes.get(random.nextInt(totalNodes));
        CyNode target = nodes.get(random.nextInt(totalNodes));
        network.addEdge(source, target, true);
    }
    System.out.printf("Construct\t%d\n", System.currentTimeMillis() - start);
    TransformerManagerImpl transformerManager = new TransformerManagerImpl();
    Map<String, String> properties = Collections.emptyMap();
    transformerManager.registerTransformerSource(new CyNetworkSource(), properties);
    List<UseCase> useCases = new ArrayList<UseCase>();
    QuickFind quickFind = new QuickFindImpl();
    useCases.add(new NumberAttributeUseCase(quickFind, 0, transformerManager));
    useCases.add(new StringAttributeUseCase(quickFind, values[values.length - 1], transformerManager));
    useCases.add(new DegreeUseCase(3, transformerManager));
    for (UseCase useCase : useCases) {
        useCase.execute(network, ITERATIONS);
    }
}
Also used : NetworkTestSupport(org.cytoscape.model.NetworkTestSupport) ArrayList(java.util.ArrayList) CyNetwork(org.cytoscape.model.CyNetwork) QuickFindImpl(org.cytoscape.filter.internal.quickfind.util.QuickFindImpl) CyTable(org.cytoscape.model.CyTable) Random(java.util.Random) QuickFind(org.cytoscape.filter.internal.quickfind.util.QuickFind) CyNode(org.cytoscape.model.CyNode) TransformerManagerImpl(org.cytoscape.filter.internal.work.TransformerManagerImpl)

Example 88 with CyTable

use of org.cytoscape.model.CyTable in project cytoscape-impl by cytoscape.

the class GroupDataCollapseHandler method handleEvent.

public void handleEvent(GroupAboutToCollapseEvent e) {
    CyNetwork network = e.getNetwork();
    CyGroup group = e.getSource();
    if (e.collapsing()) {
        // Are we aggregating
        if (!cyGroupSettings.getEnableAttributeAggregation(group))
            return;
        // Yup -- all of our information is in the settings...
        CyTable nodeTable = network.getDefaultNodeTable();
        for (CyColumn column : nodeTable.getColumns()) {
            Class<?> type = column.getType();
            if (column.isPrimaryKey())
                continue;
            // Skip over our own columns
            if (CyGroupSettingsImpl.AGGREGATION_SETTINGS.equals(column.getName()))
                continue;
            if (CyGroupSettingsImpl.AGGREGATION_OVERRIDE_SETTINGS.equals(column.getName()))
                continue;
            if (CyGroupSettingsImpl.VIEW_SETTINGS.equals(column.getName()))
                continue;
            if (CyGroupImpl.CHILDREN_ATTR.equals(column.getName()))
                continue;
            if (CyGroupImpl.DESCENDENTS_ATTR.equals(column.getName()))
                continue;
            // Don't aggregate the name or shared name columns by default
            if (CyNetwork.NAME.equals(column.getName())) {
                if (!haveOverride(group, column))
                    continue;
            }
            if (CyRootNetwork.SHARED_NAME.equals(column.getName())) {
                if (!haveOverride(group, column))
                    continue;
            }
            // Do we have an override for this group and column?
            Aggregator<?> agg = cyGroupSettings.getAggregator(group, column);
            if (agg == null) {
                continue;
            }
            // OK, aggregate
            agg.aggregate(nodeTable, group, column);
        }
    }
}
Also used : CyGroup(org.cytoscape.group.CyGroup) CyTable(org.cytoscape.model.CyTable) CyColumn(org.cytoscape.model.CyColumn) CyNetwork(org.cytoscape.model.CyNetwork)

Example 89 with CyTable

use of org.cytoscape.model.CyTable in project cytoscape-impl by cytoscape.

the class VisualStyleTest method setUp.

@Before
@SuppressWarnings("unchecked")
public void setUp() throws Exception {
    NetworkViewTestSupport nvts = new NetworkViewTestSupport();
    network = nvts.getNetworkFactory().createNetwork();
    node1 = network.addNode();
    node2 = network.addNode();
    node3 = network.addNode();
    edge = network.addEdge(node1, node2, true);
    CyTable nodeTable = network.getDefaultNodeTable();
    nodeTable.createColumn(attrName, String.class, true);
    nodeTable.getRow(node1.getSUID()).set(attrName, "red");
    nodeTable.getRow(node2.getSUID()).set(attrName, "green");
    nodeTable.getRow(node3.getSUID()).set(attrName, "foo");
    networkView = nvts.getNetworkViewFactory().createNetworkView(network);
    // Create root node.
    final NullVisualProperty minimalRoot = new NullVisualProperty("MINIMAL_ROOT", "Minimal Root Visual Property");
    final BasicVisualLexicon minimalLex = new BasicVisualLexicon(minimalRoot);
    final Set<VisualLexicon> lexSet = new HashSet<VisualLexicon>();
    lexSet.add(minimalLex);
    final VisualMappingFunctionFactory ptFactory = mock(VisualMappingFunctionFactory.class);
    eventHelper = mock(CyEventHelper.class);
    final RenderingEngineFactory<CyNetwork> reFatory = mock(RenderingEngineFactory.class);
    when(reFatory.getVisualLexicon()).thenReturn(minimalLex);
    final NetworkViewRenderer nvRenderer = mock(NetworkViewRenderer.class);
    when(nvRenderer.getRenderingEngineFactory(NetworkViewRenderer.DEFAULT_CONTEXT)).thenReturn(reFatory);
    final CyApplicationManager appManager = mock(CyApplicationManager.class);
    when(appManager.getCurrentNetworkViewRenderer()).thenReturn(nvRenderer);
    final CyServiceRegistrar serviceRegistrar = mock(CyServiceRegistrar.class);
    when(serviceRegistrar.getService(CyEventHelper.class)).thenReturn(eventHelper);
    when(serviceRegistrar.getService(CyApplicationManager.class)).thenReturn(appManager);
    VisualProperty<NullDataType> rootVisualProperty = mock(VisualProperty.class);
    BasicVisualLexicon lexicon = new BasicVisualLexicon(rootVisualProperty);
    vpSet = new HashSet<VisualProperty<Paint>>();
    vpSet.add(BasicVisualLexicon.NODE_BORDER_PAINT);
    vpSet.add(BasicVisualLexicon.NODE_FILL_COLOR);
    dependency = new VisualPropertyDependency<Paint>("dep1", "Dep 1", vpSet, lexicon);
    final VisualStyleFactoryImpl visualStyleFactory = new VisualStyleFactoryImpl(serviceRegistrar, ptFactory);
    originalTitle = "Style 1";
    newTitle = "Style 2";
    style = visualStyleFactory.createVisualStyle(originalTitle);
    style.setDefaultValue(NODE_SIZE, DEF_NODE_SIZE);
    style.setDefaultValue(NODE_FILL_COLOR, DEF_NODE_COLOR);
    reset(eventHelper);
}
Also used : NullVisualProperty(org.cytoscape.view.presentation.property.NullVisualProperty) CyEventHelper(org.cytoscape.event.CyEventHelper) BasicVisualLexicon(org.cytoscape.view.presentation.property.BasicVisualLexicon) VisualLexicon(org.cytoscape.view.model.VisualLexicon) VisualMappingFunctionFactory(org.cytoscape.view.vizmap.VisualMappingFunctionFactory) CyNetwork(org.cytoscape.model.CyNetwork) Paint(java.awt.Paint) NetworkViewTestSupport(org.cytoscape.ding.NetworkViewTestSupport) CyServiceRegistrar(org.cytoscape.service.util.CyServiceRegistrar) CyApplicationManager(org.cytoscape.application.CyApplicationManager) CyTable(org.cytoscape.model.CyTable) NullDataType(org.cytoscape.view.model.NullDataType) BasicVisualLexicon(org.cytoscape.view.presentation.property.BasicVisualLexicon) VisualProperty(org.cytoscape.view.model.VisualProperty) NullVisualProperty(org.cytoscape.view.presentation.property.NullVisualProperty) HashSet(java.util.HashSet) NetworkViewRenderer(org.cytoscape.application.NetworkViewRenderer) Before(org.junit.Before)

Example 90 with CyTable

use of org.cytoscape.model.CyTable in project cytoscape-impl by cytoscape.

the class ImportTableDataTask method getColumns.

private ListSingleSelection<String> getColumns(final Collection<? extends CyNetwork> networkList, final TableType tableType, final String namespace) {
    Set<ColumnDescriptor> colDescSet = null;
    // Get set of columns with same name and type that are common to all networks
    for (CyNetwork network : networkList) {
        final CyTable table = getTable(network, tableType, namespace);
        final Set<ColumnDescriptor> subSet = new HashSet<>();
        for (CyColumn col : table.getColumns()) {
            if (isMappableColumn(col))
                subSet.add(new ColumnDescriptor(col.getName(), col.getType()));
        }
        if (colDescSet == null)
            // First network? Just save the mappable columns...
            colDescSet = subSet;
        else
            // From now on just keep the common columns...
            colDescSet.retainAll(subSet);
    }
    final List<String> columnNames = new ArrayList<>();
    if (colDescSet != null) {
        for (ColumnDescriptor cd : colDescSet) columnNames.add(cd.name);
        sort(columnNames);
    }
    final ListSingleSelection<String> columns = new ListSingleSelection<>(columnNames);
    if (columns.getPossibleValues().contains(CyRootNetwork.SHARED_NAME))
        columns.setSelectedValue(CyRootNetwork.SHARED_NAME);
    return columns;
}
Also used : CyTable(org.cytoscape.model.CyTable) ListSingleSelection(org.cytoscape.work.util.ListSingleSelection) CyColumn(org.cytoscape.model.CyColumn) ArrayList(java.util.ArrayList) CyNetwork(org.cytoscape.model.CyNetwork) HashSet(java.util.HashSet)

Aggregations

CyTable (org.cytoscape.model.CyTable)282 CyNetwork (org.cytoscape.model.CyNetwork)79 CyRow (org.cytoscape.model.CyRow)73 CyColumn (org.cytoscape.model.CyColumn)71 ArrayList (java.util.ArrayList)55 CyNode (org.cytoscape.model.CyNode)43 CyEdge (org.cytoscape.model.CyEdge)35 Test (org.junit.Test)29 List (java.util.List)26 HashMap (java.util.HashMap)24 CyApplicationManager (org.cytoscape.application.CyApplicationManager)19 HashSet (java.util.HashSet)18 CyIdentifiable (org.cytoscape.model.CyIdentifiable)14 CyNetworkView (org.cytoscape.view.model.CyNetworkView)14 CyNetworkTableManager (org.cytoscape.model.CyNetworkTableManager)13 RowSetRecord (org.cytoscape.model.events.RowSetRecord)11 CyRootNetwork (org.cytoscape.model.subnetwork.CyRootNetwork)11 CySubNetwork (org.cytoscape.model.subnetwork.CySubNetwork)11 CyEventHelper (org.cytoscape.event.CyEventHelper)10 CyTableManager (org.cytoscape.model.CyTableManager)10