use of org.cytoscape.model.subnetwork.CyRootNetwork in project cytoscape-impl by cytoscape.
the class GraphMLReader method run.
@Override
public void run(final TaskMonitor taskMonitor) throws Exception {
this.taskMonitor = taskMonitor;
try {
final SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setNamespaceAware(true);
final SAXParser sp = spf.newSAXParser();
final XMLReader xmlReader = sp.getXMLReader();
CyRootNetwork root = getRootNetwork();
final CySubNetwork newNetwork;
if (root != null) {
newNetwork = root.addSubNetwork();
} else {
// Need to create new network with new root.
newNetwork = (CySubNetwork) cyNetworkFactory.createNetwork();
root = newNetwork.getRootNetwork();
}
parser = new GraphMLParser(taskMonitor, cyNetworkFactory, cyRootNetworkManager, root, newNetwork);
xmlReader.setContentHandler(parser);
final InputSource inputSource = new InputSource(inputStream);
inputSource.setEncoding("UTF-8");
xmlReader.parse(inputSource);
createGroups(root, newNetwork);
} finally {
if (inputStream != null) {
try {
inputStream.close();
inputStream = null;
} catch (Exception e) {
logger.warn("Cannot close GraphML input stream", e);
}
}
}
}
use of org.cytoscape.model.subnetwork.CyRootNetwork in project cytoscape-impl by cytoscape.
the class GenericXGMMLReaderTest method assertCustomColumnsAreMutable.
private void assertCustomColumnsAreMutable(CyNetwork net) {
// User or non-default columns should be immutable
List<CyTable> tables = new ArrayList<CyTable>();
tables.add(net.getTable(CyNetwork.class, LOCAL_ATTRS));
tables.add(net.getTable(CyNetwork.class, HIDDEN_ATTRS));
tables.add(net.getTable(CyNetwork.class, DEFAULT_ATTRS));
tables.add(net.getTable(CyNode.class, LOCAL_ATTRS));
tables.add(net.getTable(CyNode.class, HIDDEN_ATTRS));
tables.add(net.getTable(CyNode.class, DEFAULT_ATTRS));
tables.add(net.getTable(CyEdge.class, LOCAL_ATTRS));
tables.add(net.getTable(CyEdge.class, HIDDEN_ATTRS));
tables.add(net.getTable(CyEdge.class, DEFAULT_ATTRS));
if (net instanceof CyRootNetwork) {
tables.add(net.getTable(CyNetwork.class, SHARED_ATTRS));
tables.add(net.getTable(CyNode.class, SHARED_ATTRS));
tables.add(net.getTable(CyEdge.class, SHARED_ATTRS));
}
for (CyTable t : tables) {
for (CyColumn c : t.getColumns()) {
String name = c.getName();
if (!name.equals(CyNetwork.SUID) && !name.equals(NAME) && !name.equals(CyNetwork.SELECTED) && !name.equals(CyEdge.INTERACTION) && !name.equals(CyRootNetwork.SHARED_NAME) && !name.equals(CyRootNetwork.SHARED_INTERACTION)) {
assertFalse("Column " + c.getName() + " should NOT be immutable", c.isImmutable());
}
}
}
}
use of org.cytoscape.model.subnetwork.CyRootNetwork in project cytoscape-impl by cytoscape.
the class GroupUtil method updateGroupNodeLocation.
private void updateGroupNodeLocation(final CyNetworkView view, final CyNode groupNode) {
if (view == null)
return;
CyRootNetwork rootNetwork = ((CySubNetwork) view.getModel()).getRootNetwork();
View<CyNode> nView = view.getNodeView(groupNode);
double x = nView.getVisualProperty(BasicVisualLexicon.NODE_X_LOCATION);
double y = nView.getVisualProperty(BasicVisualLexicon.NODE_Y_LOCATION);
// Save it
// TODO these attributes will not work with multiple views per network!
CyRow hRow = rootNetwork.getRow(groupNode, CyNetwork.HIDDEN_ATTRS);
createColumn(hRow.getTable(), X_LOCATION_ATTR, Double.class);
createColumn(hRow.getTable(), Y_LOCATION_ATTR, Double.class);
hRow.set(X_LOCATION_ATTR, new Double(x));
hRow.set(Y_LOCATION_ATTR, new Double(y));
}
use of org.cytoscape.model.subnetwork.CyRootNetwork in project cytoscape-impl by cytoscape.
the class GroupUtil method getGroupNodeEdges.
public List<CyEdge> getGroupNodeEdges(final CyNetwork network) {
CyRootNetwork rootNetwork = ((CySubNetwork) network).getRootNetwork();
// Don't need to worry about this for collapsed groups
List<CyNode> groupNodes = getExpandedGroups(network);
List<CyEdge> groupNodeEdges = new ArrayList<>();
for (CyNode groupNode : groupNodes) {
groupNodeEdges.addAll(rootNetwork.getAdjacentEdgeList(groupNode, CyEdge.Type.ANY));
}
return groupNodeEdges;
}
use of org.cytoscape.model.subnetwork.CyRootNetwork in project cytoscape-impl by cytoscape.
the class GenericXGMMLWriter method getRowFromNetOrRoot.
protected CyRow getRowFromNetOrRoot(final CyNetwork network, final CyIdentifiable entry, String namespace) {
CyRow row = null;
try {
row = namespace == null ? network.getRow(entry) : network.getRow(entry, namespace);
} catch (final IllegalArgumentException e) {
// Ignore this exception
} catch (final RuntimeException e) {
logger.error("Cannot get \"" + namespace + "\" row for entry \"" + entry + "\" in network \"" + network + "\".", e);
}
if (row == null && network instanceof CySubNetwork) {
// Doesn't exist in subnetwork? Try to get it from the root network.
final CyRootNetwork root = ((CySubNetwork) network).getRootNetwork();
row = namespace == null ? root.getRow(entry) : root.getRow(entry, namespace);
}
return row;
}
Aggregations