Skip to content

Commit

Permalink
Merge pull request #25 from CRI-iAtlas/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
andrewelamb authored Mar 26, 2024
2 parents ff8b2e6 + 0a4fd74 commit ac244cc
Show file tree
Hide file tree
Showing 16 changed files with 639 additions and 1 deletion.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: iatlasGraphQLClient
Title: iatlas API Client
Type: Package
Version: 0.2.2
Version: 0.2.4
Author: Andrew Lamb
Maintainer: Andrew Lamb <[email protected]>
Description: This package is am R Client library for the iAtlas API.
Expand Down
38 changes: 38 additions & 0 deletions R/api_cell_stats_queries.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#' Query Cell Stats
#'
#' @param entrez A vector integers
#' @param paging A named list
#' @param ... Arguments to create_result_from_api_query
#' @export
query_cell_stats <- function(
entrez = NA,
paging = NA,
...
){
tbl <- create_result_from_cursor_paginated_api_query(
query_args = list(
"entrez" = entrez,
"paging" = paging,
"distinct" = F
),
query_file = "cell_stats.txt",
default_tbl = dplyr::tibble(
"type" = character(),
"count" = integer(),
"avg_expr" = double(),
"perc_expr" = double(),
"dataset_name" = character(),
"gene_entrez" = integer()
),
select_cols = c(
"type",
"count",
"avg_expr" = "avgExpr",
"perc_expr" = "percExpr",
"dataset_name" = "dataSet.name",
"gene_entrez" = "gene.entrez"
),
...
)
return(tbl)
}
140 changes: 140 additions & 0 deletions R/api_cells_queries.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
#' Query Cells
#'
#' @param cohort A vector of characters
#' @param cell A vector of characters
#' @param paging A named list
#' @param ... Arguments to create_result_from_api_query
#' @export
query_cells <- function(
cohort = NA,
cell = NA,
paging = NA,
...
){
tbl <- create_result_from_cursor_paginated_api_query(
query_args = list(
"cohort" = cohort,
"cell" = cell,
"paging" = paging,
"distinct" = F
),
query_file = "cells.txt",
default_tbl = dplyr::tibble(
"type" = character(),
"name" = character(),
),
select_cols = c(
"type",
"name"
),
...
)
return(tbl)
}

#' Query SingleCellSeq
#'
#' @param entrez A vector integers
#' @param cohort A vector of characters
#' @param cell A vector of characters
#' @param paging A named list
#' @param ... Arguments to create_result_from_api_query
#' @export
query_single_cell_seq <- function(
entrez = NA,
cohort = NA,
cell = NA,
paging = NA,
...
){
tbl <- create_result_from_cursor_paginated_api_query(
query_args = list(
"entrez" = entrez,
"cohort" = cohort,
"cell" = cell,
"paging" = paging,
"distinct" = F
),
query_file = "single_cell_seq.txt",
default_tbl = dplyr::tibble(
"cell_type" = character(),
"cell_name" = character(),
"gene_entrez" = integer(),
"gene_hgnc" = character(),
"gene_single_cell_seq" = double()
),
select_cols = c(
"cell_type" = "type",
"cell_name" = "name",
"genes"
),
...
)
if (nrow(tbl) == 0) return(tbl)
else {
tbl <- tbl %>%
tidyr::unnest(cols = "genes", keep_empty = T) %>%
dplyr::select(
"cell_type",
"cell_name",
"gene_entrez" = "entrez",
"gene_hgnc" = "hgnc",
"gene_single_cell_seq" = "singleCellSeq"
)
}
return(tbl)
}


#' Query SingleCellFeature
#'
#' @param feature A vector of characters
#' @param cohort A vector of characters
#' @param cell A vector of characters
#' @param paging A named list
#' @param ... Arguments to create_result_from_api_query
#' @export
query_single_cell_feature <- function(
feature = NA,
cohort = NA,
cell = NA,
paging = NA,
...
){
tbl <- create_result_from_cursor_paginated_api_query(
query_args = list(
"feature" = feature,
"cohort" = cohort,
"cell" = cell,
"paging" = paging,
"distinct" = F
),
query_file = "single_cell_feature.txt",
default_tbl = dplyr::tibble(
"cell_type" = character(),
"cell_name" = character(),
"feature_name" = character(),
"feature_display" = character(),
"feature_value" = double()
),
select_cols = c(
"cell_type" = "type",
"cell_name" = "name",
"features"
),
...
)
if (nrow(tbl) == 0) return(tbl)
else {
tbl <- tbl %>%
tidyr::unnest(cols = "features", keep_empty = T) %>%
dplyr::select(
"cell_type",
"cell_name",
"feature_name" = "name",
"feature_display" = "display",
"feature_value" = "value",
)
}
return(tbl)
}
58 changes: 58 additions & 0 deletions R/api_features_queries.R
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,64 @@ query_feature_values <- function(
}
}


#' Query PseudoBulk Feature Values
#'
#' @param cohorts A vector of strings
#' @param features A vector of strings
#' @param paging A named list
#' @param ... Arguments to create_result_from_api_query
#' @export
#' @importFrom magrittr %>%
query_pseudobulk_feature_values <- function(
cohorts = NA,
features = NA,
paging = NA,
...
){
tbl <- create_result_from_cursor_paginated_api_query(
query_args = list(
"cohort" = cohorts,
"feature" = features,
"paging" = paging,
"distinct" = F
),
query_file = "pseudobulk_feature_values.txt",
default_tbl = dplyr::tibble(
"feature_name" = character(),
"feature_display" = character(),
"feature_order" = integer(),
"feature_class" = character(),
"cell_name" = character(),
"cell_type"= character(),
"value" = double()
),
select_cols = c(
"feature_name" = "name",
"feature_display" = "display",
"feature_order" = "order",
"feature_class" = "class",
"cellTypeSamples"
),
...
)
if (nrow(tbl) == 0) return(tbl)
else {
tbl %>%
tidyr::unnest(cols = "cellTypeSamples", keep_empty = T) %>%
dplyr::select(
"feature_name",
"feature_display",
"feature_order",
"feature_class",
"cell_name" = "name",
"cell_type" = "cellType",
"value"
)
}
}


#' Query Features Range
#'
#' @param cohorts A vector of strings
Expand Down
53 changes: 53 additions & 0 deletions R/api_genes_queries.R
Original file line number Diff line number Diff line change
Expand Up @@ -276,3 +276,56 @@ query_gene_nanostring_expression <- function(
)
}
}

#' Query Pseudobulk Expression
#'
#' @param cohorts A vector of strings
#' @param entrez A vector of integers
#' @param paging A named list
#' @param ... Arguments to create_result_from_api_query
#'
#' @export
#' @importFrom magrittr %>%
#' @importFrom rlang .data
query_pseudobulk_expression <- function(
cohorts = NA,
entrez = NA,
paging = NA,
...
){
tbl <- create_result_from_cursor_paginated_api_query(
query_args = list(
"cohort" = cohorts,
"entrez" = entrez,
"paging" = paging,
"distinct" = F
),
query_file = "pseudobulk_expression.txt",
default_tbl = dplyr::tibble(
"gene_entrez" = integer(),
"gene_hgnc" = character(),
"cell_name" = character(),
"cell_type" = character(),
"single_cell_seq_sum" = double()
),
select_cols = c(
"gene_entrez" = "entrez",
"gene_hgnc" = "hgnc",
"cellTypeSamples"
),
...
)
if (nrow(tbl) == 0) return(tbl)
else {
tbl %>%
tidyr::unnest(cols = "cellTypeSamples", keep_empty = T) %>%
dplyr::select(
"gene_entrez",
"gene_hgnc",
"cell_name" = "name",
"cell_type" = "cellType",
"single_cell_seq_sum" = "singleCellSeqSum"
)
}
}

32 changes: 32 additions & 0 deletions inst/queries/cell_stats.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
query CellStats(
$paging: PagingInput
$distinct:Boolean
$entrez: [Int!]
) {
cellStats(
paging: $paging
distinct: $distinct
entrez: $entrez
) {
items {
dataSet { name }
gene { entrez }
type
count
avgExpr
percExpr
}
paging {
type
pages
total
startCursor
endCursor
hasPreviousPage
hasNextPage
page
limit
}
error
}
}
30 changes: 30 additions & 0 deletions inst/queries/cells.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
query Cells(
$paging: PagingInput
$distinct:Boolean
$cohort: [String!]
$cell: [String!]
) {
cells(
paging: $paging
distinct: $distinct
cohort: $cohort
cell: $cell
) {
items {
name
type
}
paging {
type
pages
total
startCursor
endCursor
hasPreviousPage
hasNextPage
page
limit
}
error
}
}
Loading

0 comments on commit ac244cc

Please sign in to comment.