readCX: Read CX from file, parse the JSON and convert it to an RCX...

View source: R/Json-fromJson.R

readCXR Documentation

Read CX from file, parse the JSON and convert it to an RCX object

Description

The readCX function combines three sub-task:

  • read the JSON from file

  • parse the JSON

  • process the contained aspects to create an RCX object

Usage

readCX(file, verbose = FALSE, aspectClasses = getAspectClasses())

readJSON(file, verbose = FALSE)

parseJSON(json, verbose = FALSE)

processCX(aspectList, verbose = FALSE, aspectClasses = getAspectClasses())

Arguments

file

character; the name of the file which the data are to be read from

verbose

logical; whether to print what is happening

aspectClasses

named character; accession names and aspect classes aspectClasses

json

character; raw JSON data

aspectList

list; list containing the aspect data (parsed JSON)

Details

If any errors occur during this process, the single steps can be performed individually. This also allows to skip certain steps, for example if the JSON data is already availabe as text, there is no need to save it as file and read it again.

Read the JSON from file

The readJSON function only read the content of a text file and returns it as a simple character vector.

Parse the JSON

The parseJSON function uses the jsonlite package, to parse JSON text:

jsonlite::fromJSON(cx, simplifyVector = FALSE)

The result is a list containing the aspect data as elements. If, for some reason, the JSON is not valid, the jsonlite package raises an error.

Process the contained aspects to create an RCX object

With the processCX function, the single elements from the previous list will be processed with the jsonToRCX functions, which creating objects for the single aspects. The standard CX aspects are processed by generic functions named by the aspect names of the CX data structure, e.g. jsonToRCX.nodeAttributes for the samely named CX aspect the corresponding NodeAttributesAspect in RCX (see also vignette("02. The RCX and CX Data Model") or NDEx documentation: https://home.ndexbio.org/data-model/).

The CX network may contain additional aspects besides the officially defined ones. This includes self defined or deprecated aspects, that sill can be found in the networks at the NDEx platform. By default, those aspects are simply omitted. In those cases, the setting verbose to TRUE is a good idea to see, which aspects cannot be processed this package.

Those not processable aspects can be handled individually, but it is advisable to extend the jsonToRCX functions by implementing own versions for those aspects. Additionally, the update functions have to be implemented to add the newly generated aspect objects to RCX object (see e.g. updateNodes or updateEdges). Therefore, the function also have to be named "update<aspect-name>, where aspect-name is the capitalized version of the name used in the CX. (see also vignette("03. Extending the RCX Data Model")

Value

RCX object

Functions

  • readJSON: Reads the CX/JSON from file and returns the content as text

  • parseJSON: Parses the JSON text and returns a list with the aspect data

  • processCX: Processes the list of aspect data and creates an RCX

See Also

jsonToRCX, writeCX

Examples

cxFile = system.file(
  "extdata", 
  "Imatinib-Inhibition-of-BCR-ABL-66a902f5-2022-11e9-bb6a-0ac135e8bacf.cx", 
  package = "RCX"
)

rcx = readCX(cxFile)

## OR:

json = readJSON(cxFile)
aspectList = parseJSON(json)
rcx = processCX(aspectList)

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