-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds new end-points and improves to existing ones #5
Changes from 6 commits
713210b
a151daa
c9d15ea
66f1c2b
600b0f2
168682f
9ae5782
753055a
01bd553
1667fee
a9476a9
6bafcf7
55b6ebb
4e883e3
78b494f
1e1ec00
5b218e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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) |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,47 @@ | ||||||||||||||||||||||||||||||||||||||
#' @title Create Cohort | ||||||||||||||||||||||||||||||||||||||
#' | ||||||||||||||||||||||||||||||||||||||
#' @description Creates a new Cohort | ||||||||||||||||||||||||||||||||||||||
#' | ||||||||||||||||||||||||||||||||||||||
#' @param baseurl 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 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(baseurl= "https://cloudos.lifebit.ai", | ||||||||||||||||||||||||||||||||||||||
#' auth = "Bearer ***token***", | ||||||||||||||||||||||||||||||||||||||
#' teamid = "***teamid***", | ||||||||||||||||||||||||||||||||||||||
#' cohort_name = "my cohort", | ||||||||||||||||||||||||||||||||||||||
#' cohort_desc = "my cohort description") | ||||||||||||||||||||||||||||||||||||||
#' } | ||||||||||||||||||||||||||||||||||||||
#' @export | ||||||||||||||||||||||||||||||||||||||
create_cohort <- function(baseurl, auth, teamid, | ||||||||||||||||||||||||||||||||||||||
cohort_name, cohort_desc, filters = "") { | ||||||||||||||||||||||||||||||||||||||
url <- paste(baseurl, "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" = teamid), | ||||||||||||||||||||||||||||||||||||||
body = list("name" = cohort_name, | ||||||||||||||||||||||||||||||||||||||
"description" = cohort_desc, | ||||||||||||||||||||||||||||||||||||||
"moreFilters" = filters), | ||||||||||||||||||||||||||||||||||||||
encode = "json" | ||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||
if (!r$status_code == 200) { | ||||||||||||||||||||||||||||||||||||||
message("Something went wrong. Not able to create a cohort") | ||||||||||||||||||||||||||||||||||||||
}else{ | ||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
on this, I generally think This is also Jenny Bryan approved, see here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a legit point 👍 This will make the code even more readable as well. Let me do that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sk-sahu thanks for being on the Jenny Bryan side of life 😄 ! One note, after checking the code: Lines 36 to 43 in c7d081e
Once you remove else, the idea is to replace it with the explicit So in principle as an example the following snippet, when Lines 37 to 46 in 1e1ec00
if (!r$status_code == 200) {
stop("Something went wrong. Not able to create a cohort")
}
if (r$status_code == 200){
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)
} |
||||||||||||||||||||||||||||||||||||||
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) | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
} |
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 baseurl 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 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(baseurl= "https://cloudos.lifebit.ai", | ||
#' auth = "Bearer ***token***", | ||
#' teamid = "***teamid***") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you make everythang snakecase eg in all occurrences? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
#' } | ||
#' @export | ||
extract_genotypic_data <- function(baseurl, auth, teamid, | ||
page_number = 0, | ||
page_size = 10, | ||
filters = "") { | ||
url <- paste(baseurl, "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" = teamid), | ||
body = list("pageNumber" = page_number, | ||
"pageSize" = page_size, | ||
"filters" = filters), | ||
encode = "json" | ||
) | ||
if (!r$status_code == 200) { | ||
message("Something went wrong.") | ||
}else{ | ||
res <- httr::content(r) | ||
return(res$participants) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#' @title Limited Cohort Data Extractor | ||
#' @title List cohorts | ||
#' | ||
#' @description Extracts the data frame with limited cohort data columns. | ||
#' | ||
|
@@ -29,15 +29,15 @@ list_cohorts <- function(baseurl, | |
query = list("teamId" = teamid, | ||
"pageNumber" = page_number, | ||
"pageSize" = page_size)) | ||
res <- httr::content(r) | ||
if(length(res) == 0){ | ||
if (!r$status_code == 200) { | ||
message("No cohorts found. Or not able to connect with server.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here why There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good suggestion. There is |
||
} else { | ||
res <- httr::content(r) | ||
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){ | ||
for (n in 1:res$total) { | ||
dta <- data.frame(id = cohorts[[n]]$`_id`, | ||
name = cohorts[[n]]$`name`, | ||
description = cohorts[[n]]$`description`, | ||
|
@@ -50,7 +50,7 @@ list_cohorts <- function(baseurl, | |
# cohorts[[1]]$`filters` | ||
} | ||
# make in to a dataframe | ||
cohorts_df = do.call(rbind, cohorts_list) | ||
cohorts_df <- do.call(rbind, cohorts_list) | ||
return(cohorts_df) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
url: https://lifebit-ai.github.io/cloudos/ | ||
authors: | ||
Lifebit: | ||
href: https://lifebit.ai | ||
development: | ||
mode: auto |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check all the things sounds good to me!