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