updateCyNetworkRelations: Update Cytoscape network relations

View source: R/RCX-Cytoscape-NetworkRelations.R

updateCyNetworkRelationsR Documentation

Update Cytoscape network relations

Description

This functions add network relations in the form of a CyNetworkRelations object to an other CyNetworkRelations or an RCX object.

Usage

updateCyNetworkRelations(
  x,
  cyNetworkRelations,
  replace = TRUE,
  stopOnDuplicates = FALSE,
  ...
)

## S3 method for class 'CyNetworkRelationsAspect'
updateCyNetworkRelations(
  x,
  cyNetworkRelations,
  replace = TRUE,
  stopOnDuplicates = FALSE,
  ...
)

## S3 method for class 'RCX'
updateCyNetworkRelations(
  x,
  cyNetworkRelations,
  replace = TRUE,
  stopOnDuplicates = FALSE,
  checkReferences = TRUE,
  ...
)

Arguments

x

RCX or CySubNetworks object; (to which the new network relations will be added)

cyNetworkRelations

CySubNetworks object; (the network relations, that will be added)

replace

logical; if existing values are updated (or ignored)

stopOnDuplicates

logical; whether to stop, if duplicates in the child column are found

...

additional parameters

checkReferences

logical; whether to check if references to other aspects are present in the RCX object

Details

Cytoscape subnetworks allow to group a set of nodes and corresponding edges together, and network relations define the relations between those networks. CyNetworkRelations objects can be added to an RCX or an other CyNetworkRelations object.

When network relations are added to a CyNetworkRelations or a RCX object some conflicts may rise, since the aspects might use the same child IDs. If the aspects do not share any child IDs, the two aspects are simply combined, otherwise, the properties of the child are updated. If that is not wanted, the updating can be prevented by setting replace to FALSE. Furthermore, if duplicated properties are considered as a preventable mistake, an error can be raised by setting stopOnDuplicates to TRUE. This forces the function to stop and raise an error, if duplicated child IDs are present.

Value

CyNetworkRelations or RCX object with added network relations

Examples

## For CyNetworkRelationsAspects: 
## prepare some aspects:
cyNetworkRelations1 = createCyNetworkRelations(
  child = c(1,2),
  parent = c(NA,1),
  name = c("Network A",
           "View A"),
  isView = c(FALSE, TRUE)
)

cyNetworkRelations2 = createCyNetworkRelations(
  child = 2,
  name = "View B",
  isView = TRUE
)

## update the duplicated child
cyNetworkRelations3 = updateCyNetworkRelations(cyNetworkRelations1, 
                                               cyNetworkRelations2)

## keep old child values
cyNetworkRelations3 = updateCyNetworkRelations(cyNetworkRelations1, 
                                               cyNetworkRelations2,
                                               replace=FALSE)

## Raise an error if duplicate keys are present
try(updateCyNetworkRelations(cyNetworkRelations1, 
                             cyNetworkRelations2,
                             stopOnDuplicates=TRUE))
## =>ERROR: 
## Elements of "child" (in updateCyNetworkRelations) 
## must not contain duplicates!

## For RCX
## prepare RCX object:
nodes = createNodes(name = c("a","b","c","d","e","f"))
edges = createEdges(source=c(1,2,0,0,0,2), 
                    target=c(2,3,1,2,5,4))
rcx = createRCX(nodes, edges)
cySubNetworks = createCySubNetworks(
  id = c(1,2),
  nodes = list("all", c(1,2,3)),
  edges = list("all", c(0,2))                    
)
rcx = updateCySubNetworks(rcx, cySubNetworks)

## add a network relation
rcx = updateCyNetworkRelations(rcx, cyNetworkRelations1)

## add an additional relation (View A is replaced by B)
rcx = updateCyNetworkRelations(rcx, cyNetworkRelations2)

## create a relation with a not existing subnetwork...
cyNetworkRelations3 = createCyNetworkRelations(
  child = 9
)

## ...and try to add them
try(updateCyNetworkRelations(rcx, cyNetworkRelations3))
## =>ERROR: 
## Provided IDs of "additionalNetworkRelations$child" (in addCyNetworkRelations) 
## don't exist in "rcx$cySubNetworks$id"

## create a relation with a not existing parent subnetwork...
cyNetworkRelations4 = createCyNetworkRelations(
  child = 1,
  parent = 9
)

## ...and try to add them
try(updateCyNetworkRelations(rcx, cyNetworkRelations4))
## =>ERROR: 
## Provided IDs of "additionalNetworkRelations$parent" (in addCyNetworkRelations) 
## don't exist in "rcx$cySubNetworks$id"

frankkramer-lab/RCX documentation built on Feb. 4, 2023, 5:12 p.m.