Skip to content

Commit

Permalink
fix duplicate value bug
Browse files Browse the repository at this point in the history
  • Loading branch information
berntpopp committed Oct 9, 2023
1 parent fea7e7c commit 1c269b9
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions analyses/functions/descartes-functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ require(tidyverse)
#' Descartes Atlas, and returns the TPM expression values for the specified genes
#' in the given tissue as a tibble.
#'
#' Note: In cases where there are multiple entries for a single gene (e.g., ALG9),
#' only the first occurrence is returned to ensure uniqueness of gene entries.
#'
#' @param genes A character vector representing the gene names.
#' @param tissue A character string representing the tissue type.
#'
Expand All @@ -22,6 +25,10 @@ require(tidyverse)
#' expression_data <- get_descartes_tpm_expression(c("IGF2", "MALAT1", "H19"), "muscle")
#' print(expression_data)
#' }
#' \dontrun{
#' expression_data <- get_descartes_tpm_expression("ALG9", "liver")
#' print(expression_data) # Should show only one entry for ALG9
#' }
#'
#' @export
get_descartes_tpm_expression <- function(genes, tissue) {
Expand All @@ -36,9 +43,12 @@ get_descartes_tpm_expression <- function(genes, tissue) {
# Read the CSV file from the URL
expression_data <- read_csv(url, col_names = c("gene", "tpm"))

# Filter the expression data to include only the input genes
# Filter the expression data to include only the input genes and take the first row for each gene
filtered_expression_data <- expression_data %>%
filter(gene %in% genes)
filter(gene %in% genes) %>%
group_by(gene) %>%
slice_head(n = 1) %>%
ungroup()

# Create a base tibble with all input gene names
base_tibble <- tibble(gene = genes)
Expand Down Expand Up @@ -86,7 +96,7 @@ get_descartes_cell_percentage_expression <- function(genes, tissue) {
# Construct the URL based on the tissue input
url <- paste0(
"https://atlas.fredhutch.org/data/bbi/descartes/human_gtex/tables/tissue_percentage/",
tissue,
tissue,
".csv"
)

Expand Down

0 comments on commit 1c269b9

Please sign in to comment.