The MOLGENIS R API client allows you to retrieve, create, update and delete entities from within the R environment.
Just add
Copy source("http://molgenis.mydomain.example/molgenis.R")
at the top of your script and you can connect to a MOLGENIS server. Typically the first thing you do is login and the last thing is logout.
NOTE: For https connections use
Copy eval(expr = parse(text = getURL("https://molgenis.mydomain.example/molgenis.R?molgenis-token=${molgenisToken}")))
NOTE: The MOLGENIS R-api client supports up to R-version 3.2.x
Overview example
Copy source("http://molgenis.mydomain.example/molgenis.R")
molgenis.login("admin", "admin")
df <- molgenis.get("celiacsprue",
q = "celiac_weight>80 and celiac_height>180",
num = 1000,
attributes = c("celiac_weight", "celiac_height", "celiac_gender"))
plot(df$Celiac_Height ~ df$Celiac_Weight, col=df$Celiac_Gender)
molgenis.logout()
login
Copy molgenis.login(username,password)
Login to the MOLGENIS REST API
logout
Logout from the MOLGENIS REST API and destroy the session.
get
Copy molgenis.get (entity, q = NULL, start = 0, num = 1000, attributes = NULL)
Retrieves entities and returns the result in a dataframe.
Supported RSQL/FIQL query operators (see https://github.com/jirutka/rsql-parser )
Argument can be a single value, or multiple values in parenthesis separated by comma. Value that doesn’t contain any reserved character or a white space can be unquoted, other arguments must be enclosed in single or double quotes.
Examples
Copy molgenis.get("celiacsprue")
molgenis.get("celiacsprue", num = 100000, start = 1000)
molgenis.get("celiacsprue", attributes = c("Individual", "celiac_gender"))
molgenis.get("celiacsprue", q = "(celiac_weight>=80 and celiac_height<180) or (celiac_gender==Female)")
molgenis.get("celiacsprue", q = "(celiac_weight>=80;celiac_height<180),(celiac_gender==Female)")
add
Copy molgenis.add(entity, ...)
Creates a new instance of an entity (i.e. a new row of the entity data table) and returns the id.
Example
Copy id <- molgenis.add(entity = "Person", firstName = "Piet", lastName = "Paulusma")
addAll
Copy molgenis.addAll(entity, rows)
Creates new instances of an entity (i.e. adds new rows to the entity data table) and returns the ids.
Example
Copy firstName <- c("Piet", "Paulusma")
lastName <- c("Klaas", "de Vries")
df <- data.frame(firstName, lastName)
molgenis.addAll("Person", df)
update
Copy molgenis.update(entity, id, ...)
Updates un existing entity
Example
Copy molgenis.update(entity = "Person", id = 8, firstName = "Pietje", lastName = "Paulusma")
delete
Copy molgenis.delete(entity, id)
Deletes an entity.
Example
Copy molgenis.delete(entity = "Person", id = 8)
deleteList
Copy molgenis.deleteList(entity, c("id1", "id2"))
Deletes a list of entities in an entityType.
Example
Copy molgenis.deleteList(entity = "Person", rows = c("1", "2", "3"))
getEntityMetaData
Copy molgenis.getEntityMetaData(entity)
Gets the entity metadata as list.
Example
Copy meta <- molgenis.getEntityMetaData("celiacsprue")
meta$label
getAttributeMetaData
Copy molgenis.getAttributeMetaData(entity, attribute)
Gets attribute metadata as list.
Example
Copy attr <- molgenis.getAttributeMetaData(entity = "celiacsprue", attribute = "celiac_gender")
attr$fieldType