Search in sources :

Example 1 with CyNetworkReader

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;
}
Also used : CyNetworkReader(org.cytoscape.io.read.CyNetworkReader) CyNode(org.cytoscape.model.CyNode) Node(org.cytoscape.io.internal.util.session.model.Node) CyNetwork(org.cytoscape.model.CyNetwork) CyRow(org.cytoscape.model.CyRow) CyTable(org.cytoscape.model.CyTable) SessionXGMMLNetworkReader(org.cytoscape.io.internal.read.xgmml.SessionXGMMLNetworkReader) Edge(org.cytoscape.io.internal.util.session.model.Edge) CyEdge(org.cytoscape.model.CyEdge) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork)

Example 2 with CyNetworkReader

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);
    }
}
Also used : SessionXGMMLNetworkViewReader(org.cytoscape.io.internal.read.xgmml.SessionXGMMLNetworkViewReader) CyNetworkReader(org.cytoscape.io.read.CyNetworkReader) Matcher(java.util.regex.Matcher) CyNetwork(org.cytoscape.model.CyNetwork) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Example 3 with CyNetworkReader

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);
}
Also used : CyNetworkReader(org.cytoscape.io.read.CyNetworkReader) CyNetworkReaderManager(org.cytoscape.io.read.CyNetworkReaderManager)

Example 4 with CyNetworkReader

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);
}
Also used : TaskIterator(org.cytoscape.work.TaskIterator) CyNetworkReader(org.cytoscape.io.read.CyNetworkReader) GeneAssociationReader(org.cytoscape.tableimport.internal.reader.ontology.GeneAssociationReader)

Example 5 with CyNetworkReader

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++;
    }
}
Also used : AbstractCyNetworkReader(org.cytoscape.io.read.AbstractCyNetworkReader) CyNetworkReader(org.cytoscape.io.read.CyNetworkReader) ListSingleSelection(org.cytoscape.work.util.ListSingleSelection) AbstractCyNetworkReader(org.cytoscape.io.read.AbstractCyNetworkReader) NetworkViewRenderer(org.cytoscape.application.NetworkViewRenderer)

Aggregations

CyNetworkReader (org.cytoscape.io.read.CyNetworkReader)7 CyNetwork (org.cytoscape.model.CyNetwork)3 CyNetworkView (org.cytoscape.view.model.CyNetworkView)2 TaskIterator (org.cytoscape.work.TaskIterator)2 URISyntaxException (java.net.URISyntaxException)1 Matcher (java.util.regex.Matcher)1 NetworkViewRenderer (org.cytoscape.application.NetworkViewRenderer)1 SessionXGMMLNetworkReader (org.cytoscape.io.internal.read.xgmml.SessionXGMMLNetworkReader)1 SessionXGMMLNetworkViewReader (org.cytoscape.io.internal.read.xgmml.SessionXGMMLNetworkViewReader)1 Edge (org.cytoscape.io.internal.util.session.model.Edge)1 Node (org.cytoscape.io.internal.util.session.model.Node)1 AbstractCyNetworkReader (org.cytoscape.io.read.AbstractCyNetworkReader)1 CyNetworkReaderManager (org.cytoscape.io.read.CyNetworkReaderManager)1 CyEdge (org.cytoscape.model.CyEdge)1 CyNode (org.cytoscape.model.CyNode)1 CyRow (org.cytoscape.model.CyRow)1 CyTable (org.cytoscape.model.CyTable)1 CyRootNetwork (org.cytoscape.model.subnetwork.CyRootNetwork)1 CyRootNetworkManager (org.cytoscape.model.subnetwork.CyRootNetworkManager)1 CySubNetwork (org.cytoscape.model.subnetwork.CySubNetwork)1