Skip to content

Commit 3aa0fba

Browse files
committed
Adding genes(), traits(), updating search_gpmap()
1 parent ce74c5c commit 3aa0fba

File tree

10 files changed

+170
-22
lines changed

10 files changed

+170
-22
lines changed

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export(associations)
44
export(associations_api)
55
export(gene)
66
export(gene_api)
7+
export(genes)
78
export(genes_api)
89
export(get_all_gene_pleiotropies)
910
export(get_all_snp_pleiotropies)
@@ -22,6 +23,7 @@ export(search_variants_api)
2223
export(select_api)
2324
export(trait)
2425
export(trait_api)
26+
export(traits)
2527
export(traits_api)
2628
export(upload_gwas)
2729
export(variant)

R/genes.R

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
1+
#' @title Genes
2+
#' @description Get all genes from the API
3+
#' @return A dataframe containing all genes with the following columns:
4+
#' \itemize{
5+
#' \item id: the id of the gene
6+
#' \item gene: the name of the gene
7+
#' \item description: the description of the gene
8+
#' \item gene_biotype: the gene biotype
9+
#' \item chr: the chromosome of the gene
10+
#' \item start: the start position of the gene
11+
#' \item stop: the end position of the gene
12+
#' \item strand: the strand of the gene
13+
#' \item source: the source of the gene
14+
#' \item distinct_trait_categories: the number of trait categories that the gene is associated with via coloc groups
15+
#' \item distinct_protein_coding_genes: the number of genes that the gene is associated with via coloc groups
16+
#' \item num_study_extractions: the number of study extractions for this gene
17+
#' \item num_coloc_groups: the number of coloc groups for this gene
18+
#' \item num_coloc_studies: the number of studies that have coloc results for this gene
19+
#' \item num_rare_groups: the number of rare groups for this gene
20+
#' }
21+
#' @export
22+
genes <- function() {
23+
genes <- genes_api()
24+
return(genes$genes)
25+
}
26+
127
#' @title Gene
228
#' @description A collection of studies that are associated with a particular gene.
329
#' @param gene_id A numeric value specifying the gene id

R/pleiotropy.R

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,29 @@
11
#' @title Get All Gene Pleiotropies
22
#' @description Get gene pleiotropy from the API by gene id
33
#' @return A list containing the gene pleiotropy
4-
#' @inheritSection gene_pleiotropy_doc gene_pleiotropy_dataframe
4+
#' \itemize{
5+
#' \item gene_id: the id of the gene
6+
#' \item gene: the name of the gene
7+
#' \item distinct_trait_categories: the number of trait categories that the gene is associated with via coloc groups
8+
#' \item distinct_protein_coding_genes: the number of genes that the gene is associated with via coloc groups
9+
#' }
510
#' @export
611
get_all_gene_pleiotropies <- function() {
712
gene_pleiotropies <- gene_pleiotropies_api()
8-
return(gene_pleiotropies)
13+
return(gene_pleiotropies$genes)
914
}
1015

1116
#' @title Get All SNP Pleiotropies
1217
#' @description Get all SNP pleiotropies from the API
1318
#' @return A list containing the SNP pleiotropies
14-
#' @inheritSection snp_pleiotropy_doc snp_pleiotropy_dataframe
19+
#' \itemize{
20+
#' \item snp_id: the id of the SNP
21+
#' \item display_snp: the name of the SNP
22+
#' \item distinct_trait_categories: the number of trait categories that the SNP is associated with via coloc groups
23+
#' \item distinct_protein_coding_genes: the number of genes that the SNP is associated with via coloc groups
24+
#' }
1525
#' @export
1626
get_all_snp_pleiotropies <- function() {
1727
snp_pleiotropies <- snp_pleiotropies_api()
18-
return(snp_pleiotropies)
28+
return(snp_pleiotropies$snps)
1929
}

R/search.R

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,8 @@ search_gpmap <- function(search_text) {
114114
TRUE ~ NA_character_
115115
)
116116

117-
search_results$info <- paste0(
118-
ifelse(search_results$num_extractions > 0, paste0("Extractions: ", search_results$num_extractions, ", "), ""),
119-
"Colocalisation Groups: ", search_results$num_coloc_groups, ", ",
120-
"Colocalising Traits: ", search_results$num_coloc_studies, ", ",
121-
"Rare Results: ", search_results$num_rare_results,
122-
ifelse(search_results$type == "proxy_variant", paste0(", Rsquared: ", search_results$rsq), "")
123-
)
124-
search_results$rsq <- NULL
125-
126-
search_results <- dplyr::select(search_results, call, name, type, type_id, info)
117+
columns_to_remove <- c("rsq", "name_lower", "alt_name", "alt_name_lower")
118+
search_results <- dplyr::select(search_results, -dplyr::any_of(columns_to_remove))
127119
}
128120
return(search_results)
129121
}

R/traits.R

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
1+
#' @title Traits
2+
#' @description Get all traits from the API
3+
#' @return A dataframe containing all traits with the following columns:
4+
#' \itemize{
5+
#' \item id: the id of the trait
6+
#' \item data_type: the data type of the trait
7+
#' \item trait: the internal string id of the trait
8+
#' \item trait_name: the name of the trait
9+
#' \item trait_category: the trait category of the trait
10+
#' \item variant_type: the type of variant
11+
#' \item sample_size: the sample size of the trait
12+
#' \item category: the category of the trait (continuous, categorical)
13+
#' \item ancestry: the ancestry of the trait
14+
#' \item heritability: the LDSC heritability score of the trait
15+
#' \item heritability_se: the standard error of the LDSC heritability score of the trait
16+
#' \item num_study_extractions: the number of study extractions for this trait
17+
#' \item num_coloc_groups: the number of coloc groups for this trait
18+
#' \item num_coloc_studies: the number of studies that have coloc results for this trait
19+
#' \item num_rare_results: the number of rare results for this trait
20+
#' }
21+
#' @export
22+
traits <- function() {
23+
traits <- traits_api()
24+
return(traits$traits)
25+
}
26+
127
#' @title Trait
228
#' @description A collection of studies that are associated with a particular phenotype.
329
#' A trait will include a common study and occasionally a rare study.
@@ -47,4 +73,5 @@ trait <- function(trait_id,
4773
if (include_associations) trait_info <- merge_associations(trait_info)
4874

4975
return(trait_info)
50-
}
76+
}
77+

man/genes.Rd

Lines changed: 31 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/get_all_gene_pleiotropies.Rd

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/get_all_snp_pleiotropies.Rd

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/traits.Rd

Lines changed: 31 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test_data_access_functions.R

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,15 @@ test_that("health() returns expected output", {
77
})
88

99
test_that("search_gpmap() returns expected output", {
10-
result <- search_gpmap("hemoglobin")
10+
result <- search_gpmap("haemoglobin")
1111
expect_type(result, "list")
12+
print(result)
1213
expect_true(nrow(result) > 0)
13-
expect_true(all(names(result) == c("call", "name", "type", "type_id", "info")))
14+
expected_names <- c(
15+
"call", "name", "type", "type_id", "num_coloc_groups",
16+
"num_coloc_studies", "num_rare_results", "num_study_extractions"
17+
)
18+
expect_true(all(expected_names %in% names(result)))
1419
})
1520

1621
test_that("trait() returns expected output", {
@@ -22,7 +27,7 @@ test_that("trait() returns expected output", {
2227
})
2328

2429
test_that("variant() returns expected output", {
25-
variant_id <- 5553693
30+
variant_id <- 5553693
2631
result <- variant(variant_id)
2732
expect_type(result, "list")
2833
expect_true(result$variant$id == variant_id)
@@ -48,12 +53,24 @@ test_that("associations() returns expected output", {
4853

4954
test_that("get_all_gene_pleiotropies() returns expected output", {
5055
result <- get_all_gene_pleiotropies()
51-
expect_type(result$genes, "list")
52-
expect_true(nrow(result$genes) > 0)
56+
expect_type(result, "list")
57+
expect_true(nrow(result) > 0)
5358
})
5459

5560
test_that("get_all_snp_pleiotropies() returns expected output", {
5661
result <- get_all_snp_pleiotropies()
57-
expect_type(result$snps, "list")
58-
expect_true(nrow(result$snps) > 0)
62+
expect_type(result, "list")
63+
expect_true(nrow(result) > 0)
64+
})
65+
66+
test_that("genes() returns expected output", {
67+
result <- genes()
68+
expect_type(result, "list")
69+
expect_true(nrow(result) > 0)
70+
})
71+
72+
test_that("traits() returns expected output", {
73+
result <- traits()
74+
expect_type(result, "list")
75+
expect_true(nrow(result) > 0)
5976
})

0 commit comments

Comments
 (0)