View source: R/Json-fromJson.R
readCX | R Documentation |
The readCX
function combines three sub-task:
read the JSON from file
parse the JSON
process the contained aspects to create an RCX object
readCX(file, verbose = FALSE, aspectClasses = getAspectClasses()) readJSON(file, verbose = FALSE) parseJSON(json, verbose = FALSE) processCX(aspectList, verbose = FALSE, aspectClasses = getAspectClasses())
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) |
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.
The readJSON
function only read the content of a text file and returns it as a simple character vector.
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.
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")
RCX object
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
jsonToRCX, writeCX
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.