-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds new end-points and improves to existing ones (#5)
* adds new end-points and impv to previous ones * adds pkgdown html links * linting correction * R-cmd-check in every push and PR * minor correction to title * updates doc * chnages to snakecase for team_id and base_url * error message() -> stop() which will exit with message. * minor corrections * local build and check * --no-build-vignettes added for R-CMD-Check as it require api-key to build * Attempt to fix tests (respect --no-build) * Attempt to address #5 (comment) * syntax fix in YAML * vignette oved to README * cleaning * no else based on @cgpu 's review Co-authored-by: cgpu <38183826+cgpu@users.noreply.github.com>
- Loading branch information
Showing
46 changed files
with
13,746 additions
and
4,425 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,5 @@ | |
^docs$ | ||
^pkgdown$ | ||
^local* | ||
README* | ||
^check$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
.Rproj.user | ||
.Rhistory | ||
.RData | ||
local* | ||
local* | ||
inst/doc | ||
check* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
export(create_cohort) | ||
export(extract_genotypic_data) | ||
export(extract_participants) | ||
export(list_cohorts) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#' @title Create Cohort | ||
#' | ||
#' @description Creates a new Cohort | ||
#' | ||
#' @param base_url Base URL of the CloudOS server. (Required) | ||
#' @param auth An authentication method. (Required) | ||
#' Example - Bearer token or API key. | ||
#' @param team_id Team ID in CloudOS account. (Required) | ||
#' @param cohort_name New cohort name to be created. (Required) | ||
#' @param cohort_desc New cohort description to be created. (Required) | ||
#' @param filters WIP - details will be added. | ||
#' | ||
#' @return A dataframe. | ||
#' | ||
#' @examples | ||
#' \dontrun{ | ||
#' create_cohort(base_url= "https://cloudos.lifebit.ai", | ||
#' auth = "Bearer ***token***", | ||
#' team_id = "***team_id***", | ||
#' cohort_name = "my cohort", | ||
#' cohort_desc = "my cohort description") | ||
#' } | ||
#' @export | ||
create_cohort <- function(base_url, auth, team_id, | ||
cohort_name, cohort_desc, filters = "") { | ||
url <- paste(base_url, "api/v1/cohort/", sep = "/") | ||
r <- httr::POST(url, | ||
httr::add_headers(.headers = c("Authorization" = auth, | ||
"accept" = "application/json, text/plain, */*", | ||
"content-type" = "application/json;charset=UTF-8")), | ||
query = list("teamId" = team_id), | ||
body = list("name" = cohort_name, | ||
"description" = cohort_desc, | ||
"moreFilters" = filters), | ||
encode = "json" | ||
) | ||
if (!r$status_code == 200) { | ||
stop("Something went wrong. Not able to create a cohort") | ||
} | ||
# parse the content | ||
message("Cohort named ", cohort_name, " created successfully. Bellow are the details") | ||
res <- httr::content(r) | ||
# into a dataframe | ||
res_df <- do.call(rbind, res) | ||
colnames(res_df) <- "details" | ||
return(res_df) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#' @title Extract Genotypic Data | ||
#' | ||
#' @description Extract Genotypic Data with filter. | ||
#' | ||
#' @param base_url Base URL of the CloudOS server. (Required) | ||
#' @param auth An authentication method. (Required) | ||
#' Example - Bearer token or API key. | ||
#' @param team_id Team ID in CloudOS account. (Required) | ||
#' @param page_number Number of page. (Optional) Default - 0 | ||
#' @param page_size Number of entries in a page. (Optional) Default - 10 | ||
#' @param filters WIP - details will be added. | ||
#' | ||
#' @return A dataframe. | ||
#' | ||
#' @examples | ||
#' \dontrun{ | ||
#' extract_genotypic_data(base_url= "https://cloudos.lifebit.ai", | ||
#' auth = "Bearer ***token***", | ||
#' team_id = "***team_id***") | ||
#' } | ||
#' @export | ||
extract_genotypic_data <- function(base_url, auth, team_id, | ||
page_number = 0, | ||
page_size = 10, | ||
filters = "") { | ||
url <- paste(base_url, "api/v1/cohort/genotypic-data", sep = "/") | ||
r <- httr::POST(url, | ||
httr::add_headers(.headers = c("Authorization" = auth, | ||
"accept" = "application/json, text/plain, */*", | ||
"content-type" = "application/json;charset=UTF-8")), | ||
query = list("teamId" = team_id), | ||
body = list("pageNumber" = page_number, | ||
"pageSize" = page_size, | ||
"filters" = filters), | ||
encode = "json" | ||
) | ||
if (!r$status_code == 200) { | ||
stop("Something went wrong.") | ||
} | ||
# parse the content | ||
res <- httr::content(r) | ||
return(res$participants) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,57 @@ | ||
#' @title Limited Cohort Data Extractor | ||
#' @title List cohorts | ||
#' | ||
#' @description Extracts the data frame with limited cohort data columns. | ||
#' | ||
#' @param baseurl Base URL of the CloudOS server. (Required) | ||
#' @param base_url Base URL of the CloudOS server. (Required) | ||
#' @param auth An authentication method. (Required) | ||
#' Example - Bearer token or API key. | ||
#' @param teamid Team ID in CloudOS account. (Required) | ||
#' @param team_id Team ID in CloudOS account. (Required) | ||
#' @param page_number Number of page. (Optional) Default - 0 | ||
#' @param page_size Number of entries in a page. (Optional) Default - 10 | ||
#' | ||
#' @return A data frame with available cohorts. | ||
#' | ||
#' @examples | ||
#' \dontrun{ | ||
#' list_cohorts(baseurl= "https://cloudos.lifebit.ai", | ||
#' list_cohorts(base_url= "https://cloudos.lifebit.ai", | ||
#' auth = "Bearer ***token***", | ||
#' teamid = "***teamid***") | ||
#' team_id = "***team_id***") | ||
#' } | ||
#' @export | ||
list_cohorts <- function(baseurl, | ||
list_cohorts <- function(base_url, | ||
auth, | ||
teamid, | ||
team_id, | ||
page_number = 0, | ||
page_size = 10) { | ||
url <- paste(baseurl, "api/v1/cohort", sep = "/") | ||
url <- paste(base_url, "api/v1/cohort", sep = "/") | ||
r <- httr::GET(url, | ||
httr::add_headers("Authorization" = auth), | ||
query = list("teamId" = teamid, | ||
query = list("teamId" = team_id, | ||
"pageNumber" = page_number, | ||
"pageSize" = page_size)) | ||
if (!r$status_code == 200) { | ||
stop("No cohorts found. Or not able to connect with server.") | ||
} | ||
# parse the content | ||
res <- httr::content(r) | ||
if(length(res) == 0){ | ||
message("No cohorts found. Or not able to connect with server.") | ||
} else { | ||
message("Total number of cohorts found - ", res$total) | ||
cohorts <- res$cohort | ||
# make in to a list | ||
cohorts_list <- list() | ||
for(n in 1:res$total){ | ||
dta <- data.frame(id = cohorts[[n]]$`_id`, | ||
name = cohorts[[n]]$`name`, | ||
description = cohorts[[n]]$`description`, | ||
number_of_participants = cohorts[[n]]$`numberOfParticipants`, | ||
number_of_filters = cohorts[[n]]$`numberOfFilters`, | ||
created_at = cohorts[[n]]$`createdAt`, | ||
updated_at = cohorts[[n]]$`updatedAt`) | ||
cohorts_list[[n]] <- dta | ||
# filter | ||
# cohorts[[1]]$`filters` | ||
} | ||
# make in to a dataframe | ||
cohorts_df = do.call(rbind, cohorts_list) | ||
return(cohorts_df) | ||
message("Total number of cohorts found-", res$total, | ||
". But here is 10. For more, change 'page_number' and 'page_size'") | ||
cohorts <- res$cohorts | ||
# make in to a list | ||
cohorts_list <- list() | ||
for (n in 1:page_size) { | ||
dta <- data.frame(id = cohorts[[n]]$`_id`, | ||
name = cohorts[[n]]$`name`, | ||
description = cohorts[[n]]$`description`, | ||
number_of_participants = cohorts[[n]]$`numberOfParticipants`, | ||
number_of_filters = cohorts[[n]]$`numberOfFilters`, | ||
created_at = cohorts[[n]]$`createdAt`, | ||
updated_at = cohorts[[n]]$`updatedAt`) | ||
cohorts_list[[n]] <- dta | ||
# filter | ||
# cohorts[[1]]$`filters` | ||
} | ||
# make in to a dataframe | ||
cohorts_df <- do.call(rbind, cohorts_list) | ||
return(cohorts_df) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
--- | ||
output: github_document | ||
--- | ||
|
||
<!-- README.md is generated from README.Rmd. Please edit that file --> | ||
|
||
```{r setup, include = FALSE} | ||
knitr::opts_chunk$set( | ||
collapse = TRUE, | ||
comment = "#>", | ||
fig.path = "man/figures/README-", | ||
out.width = "100%" | ||
) | ||
``` | ||
|
||
# cloudos | ||
|
||
<!-- badges: start --> | ||
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental) | ||
[![R build status](https://github.com/lifebit-ai/cloudos/workflows/R-CMD-check/badge.svg)](https://github.com/lifebit-ai/cloudos/actions) | ||
<!-- badges: end --> | ||
|
||
The 'CloudOS' client library for R makes it easy to interact with CloudOS <https://cloudos.lifebit.ai/> in the R environment for analysis. | ||
|
||
## Installation | ||
|
||
You can install the released version of cloudos from [GitHub](https://github.com/lifebit-ai/cloudos/) at this moment. (Will be listed on [CRAN](https://CRAN.R-project.org) as well) | ||
|
||
```{r, eval=FALSE} | ||
if (!require(remotes)) { install.packages("remotes") } | ||
remotes::install_github("lifebit-ai/cloudos") | ||
``` | ||
|
||
## Usage | ||
|
||
### Load the cloudos R-client library | ||
|
||
```{r} | ||
library(cloudos) | ||
``` | ||
|
||
### Setup essentials | ||
|
||
```{r} | ||
cb_base_url <- "http://cohort-browser-766010452.eu-west-1.elb.amazonaws.com" | ||
my_auth <- "*************************" | ||
my_team_id <- "***************************" | ||
``` | ||
|
||
```{r secrets, echo=FALSE} | ||
my_auth <- Sys.getenv("cloudos_Bearer_token") | ||
my_team_id <- Sys.getenv("cloudos_team_id") | ||
``` | ||
|
||
### Create a cohort | ||
|
||
```{r} | ||
cloudos::create_cohort(base_url = cb_base_url, | ||
auth = my_auth, | ||
team_id = my_team_id, | ||
cohort_name = "Cohort-R", | ||
cohort_desc = "This cohort is for testing purpose, created from R.") | ||
``` | ||
|
||
### List Cohorts | ||
|
||
List available cohorts in a workspace. | ||
|
||
```{r} | ||
cohorts <- cloudos::list_cohorts(base_url = cb_base_url, | ||
auth = my_auth, | ||
team_id = my_team_id) | ||
kableExtra::kable(cohorts) | ||
``` | ||
|
||
### Extract participants | ||
|
||
Create a RAW data string. This usually generates after selecting participants on UI. (more information will be added how to create this in R) | ||
|
||
```{r} | ||
new_raw_data <- '{"columns":[{"id":34,"instance":0,"array":{"type":"exact","value":0}},{"id":31,"instance":0,"array":{"type":"exact","value":0}},{"id":52,"instance":0,"array":{"type":"exact","value":0}},{"id":5984,"instance":0,"array":{"type":"avg"}},{"id":5984,"instance":0,"array":{"type":"min"}},{"id":5984,"instance":0,"array":{"type":"max"}},{"id":20001,"instance":0,"array":{"type":"exact","value":0}}],"ids":["5f185b92bf92ed4d3be9637d","5edbdd689d700db709af0c2f","5f185b91bf92ed4d3be9587e","5f185b91bf92ed4d3be95984","5edbdd689d700db709af0c3e","5edbdd689d700db709af0c2b","5edbdd689d700db709af0c2d","5f185b93bf92ed4d3be982e9","5edbdd689d700db709af0c2a","5edbdd689d700db709af0c4d"],"type":"csv","base_url":"http://cohort-browser-766010452.eu-west-1.elb.amazonaws.com"}' | ||
``` | ||
|
||
Using this above raw data lets extract selected participants. | ||
|
||
```{r} | ||
df <- cloudos::extract_participants(base_url= cb_base_url, | ||
auth = my_auth, | ||
raw_data = new_raw_data) | ||
kableExtra::kable(df) | ||
``` | ||
|
Oops, something went wrong.