use of org.cytoscape.io.read.CyNetworkReader in project cytoscape-impl by cytoscape.
the class Cy2SessionReaderImpl method extractNetworksAndViews.
/**
* @param is
* @param entryName
* @param parent
* @param createView
* @return The top-level network that was extracted from the XGMML file.
* @throws Exception
*/
private CyNetwork extractNetworksAndViews(final InputStream is, final String entryName, final CyNetwork parent, final boolean createView) throws Exception {
CyNetwork topNetwork = null;
final CyNetworkReader reader = networkReaderMgr.getReader(is, entryName);
if (parent != null) {
if (reader instanceof SessionXGMMLNetworkReader) {
((SessionXGMMLNetworkReader) reader).setParent(parent);
} else {
logger.error("CyNetworkReader should be an instance of XGMMLNetworkReader. " + "Cannot extract network as sub-nertwork of: " + entryName);
}
}
reader.run(taskMonitor);
final CyNetwork[] netArray = reader.getNetworks();
if (netArray != null && netArray.length > 0) {
topNetwork = netArray[0];
for (int i = 0; i < netArray.length; i++) {
// Process each CyNetwork
final CyNetwork net = netArray[i];
final String netName = net.getRow(net).get(CyNetwork.NAME, String.class);
networkLookup.put(netName, net);
// Add parent network attribute to a column in the hidden table,
// to preserve the network hierarchy info from Cytoscape 2.x
final CyRow hRow = net.getRow(net, CyNetwork.HIDDEN_ATTRS);
final CyTable hTbl = hRow.getTable();
if (parent instanceof CySubNetwork) {
if (hTbl.getColumn(CY3_PARENT_NETWORK_COLUMN) == null)
hTbl.createColumn(CY3_PARENT_NETWORK_COLUMN, Long.class, false);
hRow.set(CY3_PARENT_NETWORK_COLUMN, parent.getSUID());
}
final CyTable tbl = net.getRow(net, CyNetwork.LOCAL_ATTRS).getTable();
// (e.g. the user imported a Cy3 XGMML that contains this attribute into Cy2)
if (tbl.getColumn(CY2_PARENT_NETWORK_COLUMN) != null && parent instanceof CySubNetwork == false)
tbl.deleteColumn(CY2_PARENT_NETWORK_COLUMN);
// Restore node/edge selection
List<Node> selNodes = nodeSelectionLookup.get(netName);
List<Edge> selEdges = edgeSelectionLookup.get(netName);
if (selNodes != null)
setBooleanNodeAttr(net, selNodes, SELECTED, DEFAULT_ATTRS);
if (selEdges != null)
setBooleanEdgeAttr(net, selEdges, SELECTED, DEFAULT_ATTRS);
networks.add(net);
if (!cancelled && i == 0 && createView) {
// Create a network view for the first network only,
// which is supposed to be the top-level one
final CyNetworkView view = reader.buildCyNetworkView(net);
networkViewLookup.put(netName, view);
networkViews.add(view);
cache.cache(netName, view);
}
}
}
return topNetwork;
}
use of org.cytoscape.io.read.CyNetworkReader in project cytoscape-impl by cytoscape.
the class Cy3SessionReaderImpl method extractNetworkView.
private void extractNetworkView(InputStream is, String entryName) throws Exception {
// Get the token which identifies the network
Matcher matcher = NETWORK_VIEW_PATTERN.matcher(entryName);
Long oldNetId = null;
if (matcher.matches()) {
String netViewToken = matcher.group(2);
matcher = NETWORK_VIEW_NAME_PATTERN.matcher(netViewToken);
if (matcher.matches()) {
try {
oldNetId = Long.valueOf(matcher.group(1));
} catch (NumberFormatException nfe) {
logger.error("Cannot extract network view SUID from: " + netViewToken);
}
}
}
if (oldNetId != null) {
final CyNetwork network = cache.getNetwork(oldNetId);
if (network != null && !cancelled) {
// Create the view
final CyNetworkReader reader = networkReaderMgr.getReader(is, entryName);
reader.run(taskMonitor);
final CyNetworkView view = reader.buildCyNetworkView(network);
networkViews.add(view);
// Get its visual style name
if (reader instanceof SessionXGMMLNetworkViewReader) {
final String vsName = ((SessionXGMMLNetworkViewReader) reader).getVisualStyleName();
if (vsName != null && !vsName.isEmpty())
this.visualStyleMap.put(view, vsName);
}
}
} else {
logger.error("The network view will cannot be recreated. The network view entry is invalid: " + entryName);
}
}
use of org.cytoscape.io.read.CyNetworkReader in project cytoscape-impl by cytoscape.
the class LoadNetworkFileTask method run.
@Override
public void run(TaskMonitor taskMonitor) throws Exception {
this.taskMonitor = taskMonitor;
if (file == null)
throw new NullPointerException("No file specified.");
CyNetworkReader reader = serviceRegistrar.getService(CyNetworkReaderManager.class).getReader(file.toURI(), file.getName());
if (cancelled)
return;
if (reader == null)
throw new NullPointerException("Failed to find appropriate reader for file: " + file);
uri = file.toURI();
name = file.getName();
loadNetwork(reader);
}
use of org.cytoscape.io.read.CyNetworkReader in project cytoscape-impl by cytoscape.
the class ImportOntologyAndAnnotationTask method run.
@Override
public void run(TaskMonitor tm) throws Exception {
tm.setTitle("Importing ontology and annotations");
tm.setStatusMessage("Loading Ontology...");
tm.setProgress(-1d);
final CyNetworkReader loadOBOTask = (CyNetworkReader) factory.createTaskIterator(is, ontologyDagName).next();
final RegisterOntologyTask registerOntologyTask = new RegisterOntologyTask((CyNetworkReader) loadOBOTask, serviceRegistrar, ontologyDagName);
final GeneAssociationReader gaReader = new GeneAssociationReader(ontologyDagName, gaStream, gaTableName, serviceRegistrar);
final MapGeneAssociationTask mapAnnotationTask = new MapGeneAssociationTask(gaReader, serviceRegistrar);
final TaskIterator taskChain = new TaskIterator(loadOBOTask, registerOntologyTask, gaReader, mapAnnotationTask);
insertTasksAfterCurrentTask(taskChain);
}
use of org.cytoscape.io.read.CyNetworkReader in project cytoscape-impl by cytoscape.
the class LoadMultipleNetworksTask method run.
@Override
public void run(TaskMonitor taskMonitor) throws Exception {
this.taskMonitor = taskMonitor;
if (readers == null && readers.isEmpty())
throw new IllegalArgumentException("No network reader specified.");
taskMonitor.setTitle("Import Networks");
taskMonitor.setProgress(0.0);
final String rootNetName = rootNetwork != null ? rootNetwork.getRow(rootNetwork).get(CyRootNetwork.NAME, String.class) : null;
final String targetColumn = targetColumnList != null ? targetColumnList.getSelectedValue() : null;
final NetworkViewRenderer renderer = rendererList != null ? rendererList.getSelectedValue() : null;
final float total = readers.size();
int count = 1;
for (Entry<String, CyNetworkReader> entry : readers.entrySet()) {
if (cancelled)
return;
final CyNetworkReader r = entry.getValue();
if (r instanceof AbstractCyNetworkReader) {
AbstractCyNetworkReader ar = (AbstractCyNetworkReader) r;
if (rootNetName != null) {
ListSingleSelection<String> ls = new ListSingleSelection<>(Collections.singletonList(rootNetName));
ls.setSelectedValue(rootNetName);
ar.setRootNetworkList(ls);
} else {
// Force "create new collection"
ar.setRootNetworkList(new ListSingleSelection<>(Collections.emptyList()));
ar.setTargetColumnList(new ListSingleSelection<>(Collections.emptyList()));
}
if (targetColumn != null) {
ListSingleSelection<String> ls = new ListSingleSelection<>(Collections.singletonList(targetColumn));
ls.setSelectedValue(targetColumn);
ar.setTargetColumnList(ls);
}
if (renderer != null) {
ListSingleSelection<NetworkViewRenderer> ls = new ListSingleSelection<>(Collections.singletonList(renderer));
ls.setSelectedValue(renderer);
ar.setNetworkViewRendererList(ls);
}
}
name = entry.getKey();
loadNetwork(r);
taskMonitor.setProgress(count / total);
count++;
}
}
Aggregations