Title: | R-Client for Interacting with the 'UCSF Data Library' |
---|---|
Description: | A client for interacting with 'magma', the data warehouse of the 'UCSF Data Library'. 'magmaR' includes functions for querying and downloading data from 'magma', in order to enable working with such data in R, as well as for uploading local data to 'magma'. |
Authors: | Daniel Bunis [aut, cre] |
Maintainer: | Daniel Bunis <[email protected]> |
License: | GPL-2 |
Version: | 1.0.3 |
Built: | 2024-11-20 03:20:31 UTC |
Source: | https://github.com/cran/magmaR |
Starting out and working with different Etna environments
Access to magma via magmaR is authenticated via 'token's which users can obtain from Janus.
A valid token must be provided to magmaR before any calls to magma can be successfully performed.
To provide this token, users should obtain their token from Janus, then provide it to magmaR functions using the magmaRset
function.
See the function's own documentation and other functions' examples for further details and usage code.
The code base relies on 2 different ecosystems of all of its components for purposes of "development" of new tools and features, and "production", the release version which most users see. We won't get into the details too much more here, but users with access to the development environment can access it magmaR.
To do so, users should provide the url
of their alternative version of magma to magmaR functions using the magmaRset
function.
If proxy or other curl-request settings need to be adjusted, users can provide these via the opts
input of this same magmaRset
function.
At a minimum, you will likely want to use opts = list(ssl_verifyhost = FALSE, ssl_verifypeer = FALSE)
.
Set up your magma environment and authentication
magmaRset( token = NULL, url = "https://magma.ucsf.edu", opts = list(followlocation = FALSE) )
magmaRset( token = NULL, url = "https://magma.ucsf.edu", opts = list(followlocation = FALSE) )
token |
Single string. Your personal token from https://janus.ucsf.edu. When not explicitly given, you will be prompted to input it via the console. |
url |
Single string. The url of the production, staging, or development version of magma that you you would like to target.
See |
opts |
A named list of curl options and the values to give them (ex: |
This function compiles a list, from the given inputs, of the information needed by other magmaR
functions
to properly route and authenticate a call to magma.
A list with three components: token, url, and opts.
if (interactive()) { # THE DEFAULT: # When run in this way, it will ask you to give your token. # And the resulting $url will be the standard, production, magma url. prod <- magmaRset() print(prod) # TARGET = staging: # Give the proper url. # Again, because we are not providing our token to the call, it will ask. stage <- magmaRset(url = "https://magma-stage.ucsf.edu") print(stage) # We can also give additional curl options to the 'opts' input: prod_opts <- magmaRset(token = prod$token, opts = list(proxyport = 1234)) print(prod_opts) # Now we can retrieve data with... retrieve( target = prod, projectName = "example", modelName = "rna_seq", recordNames = "all", attributeNames = "all", filter = "") }
if (interactive()) { # THE DEFAULT: # When run in this way, it will ask you to give your token. # And the resulting $url will be the standard, production, magma url. prod <- magmaRset() print(prod) # TARGET = staging: # Give the proper url. # Again, because we are not providing our token to the call, it will ask. stage <- magmaRset(url = "https://magma-stage.ucsf.edu") print(stage) # We can also give additional curl options to the 'opts' input: prod_opts <- magmaRset(token = prod$token, opts = list(proxyport = 1234)) print(prod_opts) # Now we can retrieve data with... retrieve( target = prod, projectName = "example", modelName = "rna_seq", recordNames = "all", attributeNames = "all", filter = "") }
Analogous to the '/query' function of magma.
query(target, projectName, queryTerms = list(), format = c("list", "df"), ...)
query(target, projectName, queryTerms = list(), format = c("list", "df"), ...)
target |
A list, which can be created using |
projectName |
Single string. The name of the project you would like to interact with. For options, see |
queryTerms |
A list of strings where list elements are query predicates and verbs. See https://mountetna.github.io/magma.html#query for details. |
format |
Either "list" or "df" (=dataframe). This sets the desired output format. The list option is the more raw form. |
... |
Additional parameters passed along to the internal '.retrieve()', '.query()', or '.update()' functions, for troubleshooting or advanced-user purposes only:
|
This function initially mimics the activity of the magma's /query functionality, which is documented here https://mountetna.github.io/magma.html#query.
Afterwards, the json list output of magma/query is converted into an R list, and then the format
input determines whether it should be wrangled further:
format = "list"
, default: R list output directly.
format = "df"
: R list converted into a dataframe where data comes from the list$answer and column names come from the list$format
A list, default, if format == "list"
,
OR A dataframe conversion if format = "df"
https://mountetna.github.io/magma.html#query for documentation of the underlying magma/query function.
retrieveProjects
for exploring options for the projectName
input.
retrieveModels
, retrieveIds
, and retrieveAttributes
and retrieveTemplate
for exploring the project structure and determining queryTerm
options.
if (interactive()) { # First, we use magmaRset to create an object which will tell other magmaR # functions our authentication token (as well as some other optional bits). # When run in this way, it will ask you to give your token. magma <- magmaRset() ### To obtain the 'group' attribute, from the subject-model, that are # associated with records of the rna_seq-model: # "Raw" output of query: query_list <- query( target = magma, projectName = "example", queryTerms = list('rna_seq', '::all', 'biospecimen', 'subject', 'group')) print(query_list) # Or instead re-formatted to a dataframe, which may be easier for # downstream applications in R: query_df <- query( target = magma, projectName = "example", queryTerms = list('rna_seq', '::all', 'biospecimen', 'subject', 'group'), format = 'df') print(query_df) }
if (interactive()) { # First, we use magmaRset to create an object which will tell other magmaR # functions our authentication token (as well as some other optional bits). # When run in this way, it will ask you to give your token. magma <- magmaRset() ### To obtain the 'group' attribute, from the subject-model, that are # associated with records of the rna_seq-model: # "Raw" output of query: query_list <- query( target = magma, projectName = "example", queryTerms = list('rna_seq', '::all', 'biospecimen', 'subject', 'group')) print(query_list) # Or instead re-formatted to a dataframe, which may be easier for # downstream applications in R: query_df <- query( target = magma, projectName = "example", queryTerms = list('rna_seq', '::all', 'biospecimen', 'subject', 'group'), format = 'df') print(query_df) }
Analogous to the '/retrieve' function of magma, with format = "tsv"
retrieve( target, projectName, modelName, recordNames = "all", attributeNames = "all", filter = "", page = NULL, pageSize = 10, showDisconnected = FALSE, ... )
retrieve( target, projectName, modelName, recordNames = "all", attributeNames = "all", filter = "", page = NULL, pageSize = 10, showDisconnected = FALSE, ... )
target |
A list, which can be created using |
projectName |
Single string. The name of the project you would like to interact with. For options, see |
modelName |
Single string. The name of the subset data structure within the project, which are referred to as 'model's in magma, to interact with.
For options, see |
recordNames |
Single string or string vector indicating which particular sample/tube/etc. records to target.
Options are "all" or any combination of individual record names. To retrieve individual options, see |
attributeNames |
Single string or string vector indicating which features of the data to target.
Options are "all" or any combination of individual attribute names. To retrieve individual options, see |
filter |
String. Potential filter(s) of the data. Example: "<targetAttributeName>~GYN" to filter to records where <targetAttributeName> contains "GYN". Refer to https://mountetna.github.io/magma.html#retrieve for more details about options and format. |
page |
Integer. For retrieving just a portion of the data, sets which slice to get. |
pageSize |
Integer. For retrieving just a portion of the data, sets slice/page size, which is equivalent to the a number of rows. |
showDisconnected |
Boolean. Set to true to access "disconnected" records, which are records that are missing an (upstream) parent linkage, and so do not connect up with the project's top-level project record. Generally, disconnected records are ones that were deemed low quality in some way, thus were purposefully disconnected from the rest of the dataset. But sometimes a record might just be disconnected because an upload went awry. |
... |
Additional parameters passed along to the internal '.retrieve()', '.query()', or '.update()' functions, for troubleshooting or advanced-user purposes only:
|
This function makes a curl get request to magma/retrieve, with properly reformatted versions of user inputs, plus format = "tsv"
.
Then, it converts the tsv-string output into a dataframe.
Note: When format = "tsv"
, magma/retrieve returns just an identifier for matrix-type attributes.
To retrieve underlying data for such attributes, use the specialized retrieveMatrix
function.
A dataframe
retrieveMatrix
for retrieving attributes of type matrix.
retrieveJSON
for similar functionality to retrieve
, but where the call to magma/retrieve is made with format = "json"
and the output is a list.
This output often contains more information, and can retrieve data for attribute types of type matrix, which are not returned by the current function.
But in most cases, the data returned by retrieve
and retrieveMatrix
will suffice.
https://mountetna.github.io/magma.html#retrieve for documentation of the underlying magma/retrieve function.
if (interactive()) { # First, we use magmaRset to create an object which will tell other magmaR # functions our authentication token (as well as some other optional bits). # When run in this way, it will ask you to give your token. magma <- magmaRset() # Now we can retrieve data with... retrieve( target = magma, projectName = "example", modelName = "rna_seq", recordNames = "all", attributeNames = "all", filter = "") }
if (interactive()) { # First, we use magmaRset to create an object which will tell other magmaR # functions our authentication token (as well as some other optional bits). # When run in this way, it will ask you to give your token. magma <- magmaRset() # Now we can retrieve data with... retrieve( target = magma, projectName = "example", modelName = "rna_seq", recordNames = "all", attributeNames = "all", filter = "") }
Helper functions that utilize special cases of magma /retrieve
retrieveTemplate(target, projectName, ...) retrieveModels(target, projectName, ...) retrieveIds(target, projectName, modelName, ...) retrieveAttributes(target, projectName, modelName, ...)
retrieveTemplate(target, projectName, ...) retrieveModels(target, projectName, ...) retrieveIds(target, projectName, modelName, ...) retrieveAttributes(target, projectName, modelName, ...)
target |
A list, which can be created using |
projectName |
Single string. The name of the project you would like to interact with. For options, see |
... |
Additional parameters passed along to the internal '.retrieve()', '.query()', or '.update()' functions, for troubleshooting or advanced-user purposes only:
|
modelName |
Single string. The name of the subset data structure within the project, which are referred to as 'model's in magma, to interact with.
For options, see |
These functions aim to help users determine acceptable inputs to other magmaR functions without needing to leave R.
They make properly crafted calls to retrieve
which target either the "template" or "identifier" special cases outlined in https://mountetna.github.io/magma.html#retrieve,
followed by directly returning the output (retrieveTemplate
and retrieveIds
),
by returning just a targeted portion of that output (retrieveModels
),
or by returning a targeted portion of a subsequent single-record call to retrieve
(retrieveAttributes
).
retrieveTemplate = a list conversion of the project's template json.
retrieveModels = a string vector of model names
retrieveIds = a string vector of record names/identifiers.
retrieveAttributes = a string vector of attribute names.
retrieveTemplate()
: Retrieve the template for a given project
retrieveModels()
: Retrieve the modelNames for a given project
retrieveIds()
: Retrieve all the identifiers/recordNames for a given project-model pair.
retrieveAttributes()
: Retrieve all the attribute options for a given project-model pair.
if (interactive()) { # First, we use magmaRset to create an object which will tell other magmaR # functions our authentication token (as well as some other optional bits). # When run in this way, it will ask you to give your token. magma <- magmaRset() template <- retrieveTemplate( target = magma, projectName = "example") str(template, max.level = 4) models <- retrieveModels( target = magma, projectName = "example") print(models) ids <- retrieveIds( target = magma, projectName = "example", modelName = "rna_seq") print(ids) atts <- retrieveAttributes( target = magma, projectName = "example", modelName = "subject") print(atts) }
if (interactive()) { # First, we use magmaRset to create an object which will tell other magmaR # functions our authentication token (as well as some other optional bits). # When run in this way, it will ask you to give your token. magma <- magmaRset() template <- retrieveTemplate( target = magma, projectName = "example") str(template, max.level = 4) models <- retrieveModels( target = magma, projectName = "example") print(models) ids <- retrieveIds( target = magma, projectName = "example", modelName = "rna_seq") print(ids) atts <- retrieveAttributes( target = magma, projectName = "example", modelName = "subject") print(atts) }
Analogous to the '/retrieve' function of magma, with format = "json"
retrieveJSON( target, projectName, modelName, recordNames = "all", attributeNames = "all", filter = "", page = NULL, pageSize = 10, showDisconnected = FALSE, hideTemplate = FALSE, ... )
retrieveJSON( target, projectName, modelName, recordNames = "all", attributeNames = "all", filter = "", page = NULL, pageSize = 10, showDisconnected = FALSE, hideTemplate = FALSE, ... )
target |
A list, which can be created using |
projectName |
Single string. The name of the project you would like to interact with. For options, see |
modelName |
Single string. The name of the subset data structure within the project, which are referred to as 'model's in magma, to interact with.
For options, see |
recordNames |
Single string or string vector indicating which particular sample/tube/etc. records to target.
Options are "all" or any combination of individual record names. To retrieve individual options, see |
attributeNames |
Single string or string vector indicating which features of the data to target.
Options are "all" or any combination of individual attribute names. To retrieve individual options, see |
filter |
String. Potential filter(s) of the data. Example: "<targetAttributeName>~GYN" to filter to records where <targetAttributeName> contains "GYN". Refer to https://mountetna.github.io/magma.html#retrieve for more details about options and format. |
page |
Integer. For retrieving just a portion of the data, sets which slice to get. |
pageSize |
Integer. For retrieving just a portion of the data, sets slice/page size, which is equivalent to the a number of rows. |
showDisconnected |
Boolean. Set to true to access "disconnected" records, which are records that are missing an (upstream) parent linkage, and so do not connect up with the project's top-level project record. Generally, disconnected records are ones that were deemed low quality in some way, thus were purposefully disconnected from the rest of the dataset. But sometimes a record might just be disconnected because an upload went awry. |
hideTemplate |
Logical. Allows to leave out the project template from the return. Often this does not matter much, but the template can be bulky. |
... |
Additional parameters passed along to the internal '.retrieve()', '.query()', or '.update()' functions, for troubleshooting or advanced-user purposes only:
|
This function makes a call to magma/retrieve with format = "json"
.
Then, it converts the json output into a list which is more compatible with R.
A list
retrieve
for similar functionality, but where the call to magma/retrieve will be made with format = "tsv"
and the output is a dataframe.
retrieveMatrix
for matrix data-targeted utilization of this current retreiveJSON
function, followed by automated restructuring of the return into a matrix format.
https://mountetna.github.io/magma.html#retrieve for documentation of the underlying magma/retrieve function.
if (interactive()) { # First, we use magmaRset to create an object which will tell other magmaR # functions our authentication token (as well as some other optional bits). # When run in this way, it will ask you to give your token. magma <- magmaRset() # Now we can retrieve data as json (->list) with... json_out <- retrieveJSON( target = magma, projectName = "example", modelName = "rna_seq", recordNames = "all", attributeNames = "all", filter = "") # The return will be a nested list with data in a 'documents' element and # some extra information about each attribute in a 'template' element. str(json_out, max.level = 4) # Often, the 'template' part is bulky but not needed, so its retrieval may # be turned off by giving hideTemplaate = TRUE' json_out <- retrieveJSON( target = magma, projectName = "example", modelName = "rna_seq", recordNames = "all", attributeNames = "all", filter = "", hideTemplate = TRUE) str(json_out, max.level = 4) }
if (interactive()) { # First, we use magmaRset to create an object which will tell other magmaR # functions our authentication token (as well as some other optional bits). # When run in this way, it will ask you to give your token. magma <- magmaRset() # Now we can retrieve data as json (->list) with... json_out <- retrieveJSON( target = magma, projectName = "example", modelName = "rna_seq", recordNames = "all", attributeNames = "all", filter = "") # The return will be a nested list with data in a 'documents' element and # some extra information about each attribute in a 'template' element. str(json_out, max.level = 4) # Often, the 'template' part is bulky but not needed, so its retrieval may # be turned off by giving hideTemplaate = TRUE' json_out <- retrieveJSON( target = magma, projectName = "example", modelName = "rna_seq", recordNames = "all", attributeNames = "all", filter = "", hideTemplate = TRUE) str(json_out, max.level = 4) }
Download data from magma that is stored as a matrix
retrieveMatrix( target, projectName, modelName, recordNames = "all", attributeNames, filter = "", page = NULL, pageSize = 10, ... )
retrieveMatrix( target, projectName, modelName, recordNames = "all", attributeNames, filter = "", page = NULL, pageSize = 10, ... )
target |
A list, which can be created using |
projectName |
Single string. The name of the project you would like to interact with. For options, see |
modelName |
Single string. The name of the subset data structure within the project, which are referred to as 'model's in magma, to interact with.
For options, see |
recordNames |
Single string or string vector indicating which particular sample/tube/etc. records to target.
Options are "all" or any combination of individual record names. To retrieve individual options, see |
attributeNames |
Single string or string vector indicating which features of the data to target.
Options are "all" or any combination of individual attribute names. To retrieve individual options, see |
filter |
String. Potential filter(s) of the data. Example: "<targetAttributeName>~GYN" to filter to records where <targetAttributeName> contains "GYN". Refer to https://mountetna.github.io/magma.html#retrieve for more details about options and format. |
page |
Integer. For retrieving just a portion of the data, sets which slice to get. |
pageSize |
Integer. For retrieving just a portion of the data, sets slice/page size, which is equivalent to the a number of rows. |
... |
Additional parameters passed along to the internal '.retrieve()', '.query()', or '.update()' functions, for troubleshooting or advanced-user purposes only:
|
a matrix
if (interactive()) { # First, we use magmaRset to create an object which will tell other magmaR # functions our authentication token (as well as some other optional bits). # When run in this way, it will ask you to give your token. magma <- magmaRset() retrieveMatrix( target = magma, projectName = "example", modelName = "rna_seq", recordNames = "all", attributeNames = "gene_counts") }
if (interactive()) { # First, we use magmaRset to create an object which will tell other magmaR # functions our authentication token (as well as some other optional bits). # When run in this way, it will ask you to give your token. magma <- magmaRset() retrieveMatrix( target = magma, projectName = "example", modelName = "rna_seq", recordNames = "all", attributeNames = "gene_counts") }
Retrieve data from one model ("meta") transformed into the shape of linked records of a different model ("target"). For example, one could get subject-level information for an RNAseq counts matrix with this function. The output would contain columns of subject-level attributes, and rows that are the RNAseq-model records.
retrieveMetadata( target, projectName, meta_modelName, meta_attributeNames = "all", target_modelName, target_recordNames = "all", ... )
retrieveMetadata( target, projectName, meta_modelName, meta_attributeNames = "all", target_modelName, target_recordNames = "all", ... )
target |
A list, which can be created using |
projectName |
Single string. The name of the project you would like to interact with. For options, see |
meta_modelName , meta_attributeNames
|
Strings which indicate the "meta"data to retrieve.
They work the same as inputs of other functions without the |
target_modelName , target_recordNames
|
Strings which indicate the "target" data that meta-data is desired to be reshaped into.
They work the same as inputs of other functions without the |
... |
Additional parameters passed along to the internal '.retrieve()', '.query()', or '.update()' functions, for troubleshooting or advanced-user purposes only:
|
This function retrieves data from one model (the "meta" model) transformed so that rows of the returned dataframe correspond to records of a different model (the "target" model).
Internally, it first determines the path, through child-parent model linkages, to navigate from the meta_model to the target_model.
Then, it performs calls to query
in order to retrieve identifier linkage along that path.
The identifier linkage is turned into a dataframe of identifier traces.
Next, it performs a call to retrieve
to obtain the wanted metadata as a dataframe.
(If linkage paths would create any 1:many mappings of target data records to metadata records, data of extra records are shifted "rightwards" into columns appended with "_#" in their names. This is a reliable, though imperfect, method so we hope to implement alternatives in the future.)
Finally, the dataframe of linkage path identifiers is merged with the metadata dataframe, reshaping the metadata to properly have one row per requested target_recordName
.
A dataframe with rows = target_recordNames
and columns = model identifiers and either meta_attributeNames
or repeats of meta_attributeNames_#
when there are 1:many mappings of target data records to metadata records.
retrieve
and retrieveMatrix
which will likely be useful for retrieving associated "target" data.
if (interactive()) { # First, we use magmaRset to create an object which will tell other magmaR # functions our authentication token (as well as some other optional bits). # When run in this way, it will ask you to give your token. magma <- magmaRset() # Running like this will ask for input of your janus token one time. retrieveMetadata( target = magma, projectName = "example", meta_modelName = "subject", meta_attributeNames = "group", target_modelName = "rna_seq", target_recordNames = "all") }
if (interactive()) { # First, we use magmaRset to create an object which will tell other magmaR # functions our authentication token (as well as some other optional bits). # When run in this way, it will ask you to give your token. magma <- magmaRset() # Running like this will ask for input of your janus token one time. retrieveMetadata( target = magma, projectName = "example", meta_modelName = "subject", meta_attributeNames = "group", target_modelName = "rna_seq", target_recordNames = "all") }
Helper function that retrieves all the projectName options which a user has access to, from janus.
retrieveProjects(target, verbose = FALSE)
retrieveProjects(target, verbose = FALSE)
target |
A list, which can be created using |
verbose |
Logical. Sets whether to report the status of the '/projects' curl request sent to janus. |
This function takes in the user's target
containing their authorization token, and a url targeting either magma or janus.
It then converts the given url to target janus, and makes a curl request to <janus-url>/projects in order to return which projects a user can access.
A data.frame where elements of the 'project_name' column reflect what can be given to projectName
inputs of other magmaR functions.
if (interactive()) { retrieveProjects(target = magmaRset()) }
if (interactive()) { retrieveProjects(target = magmaRset()) }
updateValues
A wrapper of updateValues
which takes in updates in the form of a dataframe, csv, tsv, with rows = records and columns = attributes.
updateFromDF( target, projectName, modelName, df, autolink = FALSE, dryRun = FALSE, separator = ",", auto.proceed = FALSE, revisions.only = FALSE, ... )
updateFromDF( target, projectName, modelName, df, autolink = FALSE, dryRun = FALSE, separator = ",", auto.proceed = FALSE, revisions.only = FALSE, ... )
target |
A list, which can be created using |
projectName |
Single string. The name of the project you would like to interact with. For options, see |
modelName |
Single string. The name of the subset data structure within the project, which are referred to as 'model's in magma, to interact with.
For options, see |
df |
A dataframe, containing the data to upload to magma. Alternatively, a String specifying the file path of a file containing such data. See below for additional formatting details. |
autolink |
Logical. FALSE by default for safety, but often you will want to set it to TRUE. Passed through to magma, this parameter controls whether the system will attempt to connect all targeted records up with the project's root. Specifically, this means the system will 1) determine parent records of all targeted records if it can, based on the project's gnomon grammar, 2) continue parent determination for those parent records, repeating this process until reaching the project's root (the project record), then 3) creates any of these records that don't currently exist, and finally 4) creates all the assumed parent-child linkages |
dryRun |
Logical. FALSE by default. Passed through to magma, this parameter controls whether the system will only test whether the update is valid without making changes to the database. |
separator |
String indicating the field separator to use if providing |
auto.proceed |
Logical. When set to TRUE, the function does not ask before proceeding forward with the 'magma/update'. |
revisions.only |
Logical. For troubleshooting purposes, when set to |
... |
Additional parameters passed along to the internal '.retrieve()', '.query()', or '.update()' functions, for troubleshooting or advanced-user purposes only:
|
This function provides a simple method for updating multiple attributes of multiple magma records provided as a rectangular dataframe, or equivalent file structure. It utilizes the magma/query function, documented here https://mountetna.github.io/magma.html#update, to upload data after converting to the format required by that function.
Upload targets the df
's row-indicated records and column-indicated attributes of the modelName
model of projectName
project.
df
data are provided either as a dataframe, or file path which points toward such data.
If given as a file path, the separator
input can be used to adjust for whether the file is a csv (the default, separator = ","
), or tsv, separator = "\t"
, or other format.
The data structure:
Rows = records, with the first column indicating the record identifiers.
Columns = represent the data desired to be given for each attribute.
Column Names (or the top row when providing a file) = attribute names.
Except for the first column (ignored as this column's data are used as identifiers), all column names must be valid attribute names of the target modelName
.
This data is read in, presented to the user for inspection, then transformed to the necessary format and passed along to updateValues
.
The updateValues()
function will then summarize records to be updated and allow the user to double-check this information before proceeding.
This user-prompt step can be bypassed (useful when running in a non-interactive way) by setting auto.proceed = TRUE
, but NOTE:
It is a good idea to always check carefully before proceeding, if possible.
Data can be overwritten with NAs or zeros or the like, but improperly named records cannot be easily removed.
None directly.
The function sends data to magma, and the only outputs are information reported via the console.
To do so, provide a file or dataframe where 1) The first column, named something random Iits name will be ignored.), contains current identifiers; 2) Some other column, named as the attribute which is treated as the identifier for the model, contains the new identifiers
To determine the identifier attribute's name, you can use retrieveTemplate
:
retrieveTemplate(<target>, <projectName>)$models$<modelName>$template$identifier
.
updateMatrix
for uploading matrix data
updateValues
for a more direct replica of magma/update
which is more flexible, though a bit more complicated to use.
https://mountetna.github.io/magma.html#update for documentation of the underlying magma/update
function.
if (interactive()) { # First, we use magmaRset to create an object which will tell other magmaR # functions our authentication token (as well as some other optional bits). # When run in this way, it will ask you to give your token. magma <- magmaRset() ### Note that you likely do not have write-permissions for the 'example' # project, so this code can be expected to give an authorization error. ### Retrieve some data from magma, which will be in the proper format. df <- retrieve( magma, projectName = "example", modelName = "rna_seq", recordNames = "all", attributeNames = c("tube_name", "biospecimen", "cell_number") ) df updateFromDF( target = magma, projectName = "example", modelName = "rna_seq", df = df) }
if (interactive()) { # First, we use magmaRset to create an object which will tell other magmaR # functions our authentication token (as well as some other optional bits). # When run in this way, it will ask you to give your token. magma <- magmaRset() ### Note that you likely do not have write-permissions for the 'example' # project, so this code can be expected to give an authorization error. ### Retrieve some data from magma, which will be in the proper format. df <- retrieve( magma, projectName = "example", modelName = "rna_seq", recordNames = "all", attributeNames = c("tube_name", "biospecimen", "cell_number") ) df updateFromDF( target = magma, projectName = "example", modelName = "rna_seq", df = df) }
updateValues
A matrix-specific wrapper of updateValues
which can take in a matrix, data.frame, or file path, directly.
updateMatrix( target, projectName, modelName, attributeName, matrix, autolink = FALSE, dryRun = FALSE, separator = ",", auto.proceed = FALSE, revisions.only = FALSE, ... )
updateMatrix( target, projectName, modelName, attributeName, matrix, autolink = FALSE, dryRun = FALSE, separator = ",", auto.proceed = FALSE, revisions.only = FALSE, ... )
target |
A list, which can be created using |
projectName |
Single string. The name of the project you would like to interact with. For options, see |
modelName |
Single string. The name of the subset data structure within the project, which are referred to as 'model's in magma, to interact with.
For options, see |
attributeName |
String naming the matrix attribute for which to upload data. |
matrix |
A matrix or dataframe containing the data to upload to magma. Alternatively, a String specifying the file path of a file containing such data. No matter the provision method, colnames must be record identifiers, and rownames should match the values of 'options' associated with the target 'attribute'. Check the 'See Also' section below for how to determine the needed 'options'. |
autolink |
Logical. FALSE by default for safety, but often you will want to set it to TRUE. Passed through to magma, this parameter controls whether the system will attempt to connect all targeted records up with the project's root. Specifically, this means the system will 1) determine parent records of all targeted records if it can, based on the project's gnomon grammar, 2) continue parent determination for those parent records, repeating this process until reaching the project's root (the project record), then 3) creates any of these records that don't currently exist, and finally 4) creates all the assumed parent-child linkages |
dryRun |
Logical. FALSE by default. Passed through to magma, this parameter controls whether the system will only test whether the update is valid without making changes to the database. |
separator |
String indicating the field separator to use if providing |
auto.proceed |
Logical. When set to TRUE, the function does not ask before proceeding forward with the 'magma/update'. |
revisions.only |
Logical. For troubleshooting purposes, when set to |
... |
Additional parameters passed along to the internal '.retrieve()', '.query()', or '.update()' functions, for troubleshooting or advanced-user purposes only:
|
This function utilizes the magma/query function, documented here https://mountetna.github.io/magma.html#update,
to upload data to a matrix attribute (named attributeName
) of the modelName
model of projectName
project.
matrix
data are provided either as a matrix, dataframe, or file path which points toward such data.
If given as a file path, the separator
input can be used to adjust for whether the file is a csv (the default, separator = ","
), or tsv, separator = "\t"
, or other format.
Data is then validated by ensuring that all row names are among the valid 'options' of the target attribute (See the See Also section below for a note on how to explore these options yourself.). Rows are reordered to be in the same order as these 'options'.
For any missing 'options', rows of NAs are added.
The data is then transformed and passed along to updateValues
.
The updateValues()
function will summarize records to be updated and allow the user to double-check this information before proceeding.
This user-prompt step can be bypassed (useful when running in a non-interactive way) by setting auto.proceed = TRUE
, but NOTE:
It is a good idea to always check carefully before proceeding, if possible.
Data can be overwritten with NAs or zeros or the like, but improperly named records cannot be easily removed.
None directly.
The function sends data to magma, and the only outputs are information reported via the console.
updateFromDF
for a more flexible function for uploading multiple attributes-worth of (non-matrix) data at a time.
updateValues
for the more direct replica of magma/update
which is more even more flexible that updateFromDF
, though a bit more complicated to use.
retrieveTemplate
, then check the <output>$models$<modelName>$template$attributes$<attributeName>$options
to explore the rownames that your matrix should have.
https://mountetna.github.io/magma.html#update for documentation of the underlying magma/update
function.
if (interactive()) { # First, we use magmaRset to create an object which will tell other magmaR # functions our authentication token (as well as some other optional bits). # When run in this way, it will ask you to give your token. magma <- magmaRset() ### Note that you likely do not have write-permissions for the 'example' # project, so this code can be expected to give an authorization error. ### Retrieve some data from magma, then update that same data. mat <- retrieveMatrix(magma, "example", "rna_seq", "all", "gene_tpm") updateMatrix( target = magma, projectName = "example", modelName = "rna_seq", attributeName = "gene_tpm", matrix = mat) }
if (interactive()) { # First, we use magmaRset to create an object which will tell other magmaR # functions our authentication token (as well as some other optional bits). # When run in this way, it will ask you to give your token. magma <- magmaRset() ### Note that you likely do not have write-permissions for the 'example' # project, so this code can be expected to give an authorization error. ### Retrieve some data from magma, then update that same data. mat <- retrieveMatrix(magma, "example", "rna_seq", "all", "gene_tpm") updateMatrix( target = magma, projectName = "example", modelName = "rna_seq", attributeName = "gene_tpm", matrix = mat) }
Analogous to the '/update' function of magma, allows data to be sent to magma (by users with at least "editor" authorization).
updateValues( target, projectName, revisions = list(), auto.proceed = FALSE, autolink = FALSE, dryRun = FALSE, ... )
updateValues( target, projectName, revisions = list(), auto.proceed = FALSE, autolink = FALSE, dryRun = FALSE, ... )
target |
A list, which can be created using |
projectName |
Single string. The name of the project you would like to interact with. For options, see |
revisions |
A list of named lists containing the data to be updated. List structure:
See https://mountetna.github.io/magma.html#update for additional formatting details. |
auto.proceed |
Logical. When set to TRUE, the function does not ask before proceeding forward with the 'magma/update'. |
autolink |
Logical. FALSE by default for safety, but often you will want to set it to TRUE. Passed through to magma, this parameter controls whether the system will attempt to connect all targeted records up with the project's root. Specifically, this means the system will 1) determine parent records of all targeted records if it can, based on the project's gnomon grammar, 2) continue parent determination for those parent records, repeating this process until reaching the project's root (the project record), then 3) creates any of these records that don't currently exist, and finally 4) creates all the assumed parent-child linkages |
dryRun |
Logical. FALSE by default. Passed through to magma, this parameter controls whether the system will only test whether the update is valid without making changes to the database. |
... |
Additional parameters passed along to the internal '.retrieve()', '.query()', or '.update()' functions, for troubleshooting or advanced-user purposes only:
|
This function mimics the activity of the magma/update function, documented here https://mountetna.github.io/magma.html#update,
with the main difference being that the revisions
input should be in nested list format rather than nested hash (because R does not support hash structures).
Internally, the function:
1. Summarizes records of each model that will be targeted for updating.
2. Prompts the user before proceeding (unless auto.proceed
is set to TRUE
)
3. Directly passes its inputs along to magma/update via a curl request.
None directly.
The function sends data to magma, and the only outputs are information reported via the console.
https://mountetna.github.io/magma.html#update for documentation of the underlying magma/update function.
updateMatrix
for a matrix-dedicated version of this function which can be provided a matrix, or matrix's file location, directly.
if (interactive()) { # First, we use magmaRset to create an object which will tell other magmaR # functions our authentication token (as well as some other optional bits). # When run in this way, it will ask you to give your token. magma <- magmaRset() # Note that you likely do not have write-permissions for the 'example' # project, so this code can be expected to give an authorization error. updateValues( target = magma, projectName = "example", autolink = TRUE, dryRun = FALSE, revisions = list( # model 'rna_seq' = list( # record 'EXAMPLE-HS1-WB1-RSQ1' = list( # attribute 'fraction' = list( # value(s) "Tcells" ) ) ) ) ) }
if (interactive()) { # First, we use magmaRset to create an object which will tell other magmaR # functions our authentication token (as well as some other optional bits). # When run in this way, it will ask you to give your token. magma <- magmaRset() # Note that you likely do not have write-permissions for the 'example' # project, so this code can be expected to give an authorization error. updateValues( target = magma, projectName = "example", autolink = TRUE, dryRun = FALSE, revisions = list( # model 'rna_seq' = list( # record 'EXAMPLE-HS1-WB1-RSQ1' = list( # attribute 'fraction' = list( # value(s) "Tcells" ) ) ) ) ) }