R

R

The R API is a script that allows access to your MOLGENIS data via the R-Project statistical package. It is available on every MOLGENIS on the URL http://molgenis.mydomain.example/molgenis.R.

NOTE: The MOLGENIS R-api client supports up to R-version 3.2.x

As an example, let's create a plot for publicly available ASE data available on https://molgenis56.target.rug.nl/. For a description of the data, take a look at http://molgenis.org/ase.

Start up the R environment.

In the shell type:

library('RCurl')
eval(expr = parse(text = getURL("https://molgenis56.target.rug.nl/molgenis.R")))

This loads the R API from the molgenis56 server. If you take a look in your workspace by typing

ls()

you should see that a couple functions have been added for you to use:

 [1] "molgenis.add"                  "molgenis.addAll"               "molgenis.addList"              "molgenis.delete"               "molgenis.env"                
 [6] "molgenis.get"                  "molgenis.getAttributeMetaData" "molgenis.getEntityMetaData"    "molgenis.login"                "molgenis.logout"              
[11] "molgenis.update"

Let's load some data from the server using molgenis.get:

molgenis.get("ASE")

This retrieves the top 1000 rows from the ASE entity.

Let's retrieve a specific SNP from the ASE entity:

This SNP has a mild but significant allele-specific expression, based on expression counts in 21 samples.

Let's retrieve the samples for this SNP:

There they are. Let's plot the expression counts in these samples in a scatter plot.

And add a line for the non-specific expression.

image

Query format

The query must be in fiql/rsql format.

Non-anonymous access

The ASE data from the previous example is publicly available. To access private data, you can log in using

This will create a molgenis token on the server and set it in the molgenis.token variable in your R workspace.

When you're done, you can log out using

Retrieving more rows

By default, molgenis.get will retrieve up to 1000 rows only.

If you need more rows, you can request up to 10000 rows by adding the num parameter:

will retrieve the top 2000 rows from the ASE entity.

Pagination

You can retrieve the data page-by-page.

will retrieve a first page of 5 rows and

will retrieve the second page of 5 rows.

Cross server scripting

By default, the MOLGENIS R API retrieves its data from the server you retrieved it from, so if you want to retrieve data from a different server, simply source the molgenis.R from that server.

But if you want to combine data from multiple server, you can specify a different REST API URL to use by setting molgenis.api.url in the molgenis.env environment. For example:

or

Last updated