cytoscape / RCy3

New version of RCy3, redesigned and collaboratively maintained by Cytoscape developer community
MIT License
49 stars 20 forks source link

no function to "Select Nodes connecetd by selected edges" #34

Closed risserlin closed 6 years ago

risserlin commented 6 years ago

Select -> Nodes -> Nodes connected by selected edges

risserlin commented 6 years ago

trying to get rid of nodes that have no edges.
Was going to use network analyzer and get rid of nodes that have degree = 0 but can't figure out how call network analyzer through rest of RCy3. instead was going to do: selectAllEdges SelectNodesConnectedtoSelectedEdges InvertNodeSelection

AlexanderPico commented 6 years ago

I'll look into adding this function for the next release. In the meantime, here's a trick for getting rid of nodes with no edges:

createSubnetwork(edges='all')
AlexanderPico commented 6 years ago

https://github.com/cytoscape/RCy3/commit/9192d956ef2ac001e2fb2b7e1e2c51b59d955cf6

AlexanderPico commented 6 years ago

Available in dev release and github. Here's the function:

# ------------------------------------------------------------------------------
#' @title Select Nodes Connected By Selected Edges
#'
#' @description Takes currently selected edges and extends the selection to
#' connected nodes, regardless of directionality.
#' @param network (optional) Name or SUID of the network. Default is the 
#' "current" network active in Cytoscape.
#' @param base.url (optional) Ignore unless you need to specify a custom domain,
#' port or version to connect to the CyREST API. Default is http://localhost:1234
#' and the latest version of the CyREST API supported by this version of RCy3.
#' @return Lists of SUIDs for currently selected nodes and edges
#' @examples \donttest{
#' selectNodesConnectedBySelectedEdges()
#' }
#' @export
selectNodesConnectedBySelectedEdges <-
    function(network = NULL, base.url = .defaultBaseUrl) {
        suid <- getNetworkSuid(network,base.url)
        clearSelection(type = 'nodes', suid, base.url)
        res <-
            commandsPOST(
                paste0(
                    'network select extendEdges="true" edgeList="selected network="',
                    suid,
                    '"'
                )
            )
        return(res)
    }