Skip to content

Commit

Permalink
remove some examples
Browse files Browse the repository at this point in the history
  • Loading branch information
lgatto committed Oct 12, 2023
1 parent f86675d commit c012517
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 67 deletions.
7 changes: 3 additions & 4 deletions R/CT_correlated_genes.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#'
#' @examples
#' CT_correlated_genes(gene = "MAGEA3")
#' CT_correlated_genes("TDRD1", 0.3)
CT_correlated_genes <- function(gene, corr_thr = 0.5,
return = FALSE) {
suppressMessages({
Expand All @@ -42,10 +41,10 @@ CT_correlated_genes <- function(gene, corr_thr = 0.5,
CCLE_data <- CTdata::CCLE_data()
})

stopifnot("Gene name be specified!" = !missing(gene))
stopifnot("Not a CT gene" = gene %in% CT_genes$external_gene_name)
stopifnot("Gene name be specified!" = !missing(gene))
stopifnot("Not a CT gene" = gene %in% CT_genes$external_gene_name)

## Need the ensembl_id
## Need the ensembl_id
tested_ref <- rownames(CCLE_data[rowData(CCLE_data)$external_gene_name ==
gene, ])
tmp <- data.frame(
Expand Down
1 change: 0 additions & 1 deletion R/TCGA_expression.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#' TCGA_expression(
#' tumor = "LUAD", genes = c("MAGEA1", "MAGEA3"),
#' units = "log_TPM")
#' TCGA_expression(tumor = "all", units = "log_TPM")
TCGA_expression <- function(tumor = "all", genes = NULL,
units = "TPM", return = FALSE) {
suppressMessages({
Expand Down
43 changes: 20 additions & 23 deletions R/TCGA_methylation_expression_correlation.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#' Plots the correlation between methylation and expression values of
#' a Cancer-Testis (CT) gene in TCGA samples.
#'
#' @param gene `character` selected gene.
#' @param gene `character` selected gene.
#'
#' @param tumor `character` defining the TCGA tumor type. Can be one
#' of "SKCM", "LUAD", "LUSC", "COAD", "ESCA", "BRCA", "HNSC", or
Expand All @@ -19,13 +19,13 @@
#' @param nt_down `numeric(1)` indicating the number of nucleotides
#' downstream the TSS to define the promoter region (200 by
#' default)
#'
#' @param min_probe_number `numeric(1)` indicating the minimum
#' number of probes (with methylation values) within the selected region
#'
#' @param min_probe_number `numeric(1)` indicating the minimum
#' number of probes (with methylation values) within the selected region
#' to calculate its mean methylation level. Default is 3.
#'
#' @param include_normal_tissues `logical(1)`. If `TRUE`,
#' the function will include normal peritumoral tissues in addition to
#'
#' @param include_normal_tissues `logical(1)`. If `TRUE`,
#' the function will include normal peritumoral tissues in addition to
#' tumoral samples. Default is `FALSE`.
#'
#' @param return `logical(1)`. If `TRUE`, the function will return the
Expand All @@ -36,11 +36,11 @@
#' are found in promoter regions or if less than 1% of tumors are
#' positive (TPM >= 1) for the gene.
#'
#' @return A scatter plot representing for each TCGA sample, gene expression
#' and mean methylation values of probe(s) located in its promoter region
#' @return A scatter plot representing for each TCGA sample, gene expression
#' and mean methylation values of probe(s) located in its promoter region
#' (defined as 1000 nucleotides upstream TSS and 200 nucleotides downstream
#' TSS by default). If return = TRUE, methylation and expression values
#' are returned in a tibble instead.
#' TSS by default). If return = TRUE, methylation and expression values
#' are returned in a tibble instead.
#'
#' @export
#'
Expand All @@ -51,8 +51,6 @@
#'
#' @examples
#' TCGA_methylation_expression_correlation("LUAD", gene = "TDRD1")
#' TCGA_methylation_expression_correlation("all", gene = "MAGEA1",
#' min_probe_number = 1, return = FALSE)
TCGA_methylation_expression_correlation <- function(
tumor = "all",
gene = NULL,
Expand All @@ -63,31 +61,31 @@ TCGA_methylation_expression_correlation <- function(
return = FALSE) {

methylation_expression <- prepare_TCGA_methylation_expression(
tumor = tumor,
tumor = tumor,
gene = gene,
nt_up = nt_up,
nt_down = nt_down,
include_normal_tissues = include_normal_tissues)

methylation_expression <- methylation_expression[
methylation_expression$probe_number >= min_probe_number, ]
methylation_expression <- methylation_expression[
!is.na(methylation_expression$met), ]
if (nrow(methylation_expression) == 0) stop("less than ",
min_probe_number,

if (nrow(methylation_expression) == 0) stop("less than ",
min_probe_number,
" probes in selected region")
## Evaluate correlation only if the gene is expressed (TPM >= 1)

## Evaluate correlation only if the gene is expressed (TPM >= 1)
## in at least 1% of the samples
if (quantile(methylation_expression$TPM, 0.99) < 1) {
message("Too few positive samples to estimate a correlation for ", gene)
cor <- NA
}

if (!is.na(cor)) cor <- cor.test(methylation_expression$met,
log1p(methylation_expression$TPM))$estimate

p <- ggplot(
as_tibble(methylation_expression[order(methylation_expression$type,
decreasing = TRUE), ]),
Expand All @@ -104,4 +102,3 @@ TCGA_methylation_expression_correlation <- function(

return(p)
}

1 change: 0 additions & 1 deletion R/testis_expression.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
#'
#' testis_expression(cells = "germ_cells",
#' genes = c("MAGEA1", "MAGEA3", "MAGEA4"))
#' testis_expression(cells = "all", scale_lims = c(0, 4))
testis_expression <- function(cells = "all", genes = NULL,
scale_lims = NULL, return = FALSE) {
suppressMessages({
Expand Down
63 changes: 32 additions & 31 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,19 @@ check_names <- function(variable, valid_vector) {
#'
#' Check the presence of the genes in the database then subsets the database
#' to only keep these genes' data.
#'
#'
#' @param variable `character()` containing the names genes to keep in the
#' data
#'
#' @param data `Summarized Experiment` or `SingleCellExperiment` object
#' with valid variable names.
#'
#' @return A `Summarized Experiment` or `SingleCellExperiment` object with
#' @return A `Summarized Experiment` or `SingleCellExperiment` object with
#' only the variables data
#'
#' @examples
#' CTexploreR:::subset_database(variable = "MAGEA1", data = CTdata::GTEX_data())
#'
#' CTexploreR:::subset_database(variable = "MAGEA1", data = CTdata::GTEX_data())
subset_database <- function(variable = NULL, data) {
if (is.null(variable)) variable <- CTdata::CT_genes()$external_gene_name
valid_gene_names <- unique(rowData(data)$external_gene_name)
Expand All @@ -68,7 +69,7 @@ subset_database <- function(variable = NULL, data) {
#' a gene (mean methylation of probes located in its promoter) and the
#' expression level of the gene (TPM value).
#'
#' @param gene `character` selected CT gene.
#' @param gene `character` selected CT gene.
#'
#' @param tumor `character` defining the TCGA tumor type. Can be one
#' of "SKCM", "LUAD", "LUSC", "COAD", "ESCA", "BRCA", "HNSC", or
Expand All @@ -82,10 +83,10 @@ subset_database <- function(variable = NULL, data) {
#' downstream the TSS to define the promoter region (200 by
#' default)
#'
#' @param include_normal_tissues `logical(1)`. If `TRUE`,
#' the function will include normal peritumoral tissues in addition
#' @param include_normal_tissues `logical(1)`. If `TRUE`,
#' the function will include normal peritumoral tissues in addition
#' to tumoral samples. Default is `FALSE`.
#'
#'
#' @return a Dataframe giving for each TCGA sample, the methylation level of
#' a gene (mean methylation of probes located in its promoter) and the
#' expression level of the gene (TPM value). The number of probes used to
Expand All @@ -100,7 +101,9 @@ subset_database <- function(variable = NULL, data) {
#' @importFrom rlang .data
#'
#' @examples
#' CTexploreR:::prepare_TCGA_methylation_expression("LUAD", gene = "TDRD1")
#' \dontrun{
#' CTexploreR:::prepare_TCGA_methylation_expression("LUAD", gene = "TDRD1")
#' }
prepare_TCGA_methylation_expression <- function(tumor = "all",
gene = NULL,
nt_up = NULL,
Expand All @@ -111,7 +114,7 @@ prepare_TCGA_methylation_expression <- function(tumor = "all",
TPM <- CTdata::TCGA_TPM()
met <- CTdata::TCGA_CT_methylation()
})

TPM$type <- sub("TCGA-", "", TPM$project_id)
met$type <- sub("TCGA-", "", met$project_id)
valid_tumor <- c(unique(TPM$type), "all")
Expand All @@ -121,27 +124,27 @@ prepare_TCGA_methylation_expression <- function(tumor = "all",
TPM <- TPM[, TPM$type %in% type]
met <- met[, met$type %in% type]
}

valid_gene_names <- CT_genes$external_gene_name
valid_gene_names <- valid_gene_names[valid_gene_names %in%
rowData(TPM)$external_gene_name]
gene <- check_names(gene, valid_gene_names)
stopifnot("No valid gene name" = length(gene) == 1)
TPM <- TPM[rowData(TPM)$external_gene_name %in% gene, ]

## Rm duplicated samples
TPM <- TPM[, !duplicated(TPM$sample)]
met <- met[, !duplicated(met$sample)]

## keep tumors for which expression and methylation data are available
samples <- intersect(TPM$sample, met$sample)
TPM <- TPM[, TPM$sample %in% samples]
met <- met[, met$sample %in% samples]

if (is.null(nt_up)) nt_up <- 1000
if (is.null(nt_down)) nt_down <- 200
## Create a Grange corresponding to promoter region

## Create a Grange corresponding to promoter region
## Calculates mean methylation value of promoter probe(s) in each sample
gene_promoter_gr <- makeGRangesFromDataFrame(
CT_genes |>
Expand All @@ -166,35 +169,35 @@ prepare_TCGA_methylation_expression <- function(tumor = "all",
seqnames.field = "chr",
start.field = "start",
end.field = "stop")

met_roi <- subsetByOverlaps(met, gene_promoter_gr)
met_mean <- colMeans(assay(met_roi), na.rm = TRUE)
probe_number <- colSums(!is.na(assay(met_roi)))
probe_number <- colSums(!is.na(assay(met_roi)))

## Keep prefix of TCGA sample names (TCGA-XX-XXXX-XXX) to join
## expression and methylation data
names(met_mean) <- substr(names(met_mean), 1, 16)
colnames(TPM) <- substr(colnames(TPM), 1, 16)

methylation_expression <-
suppressMessages(left_join(
tibble(sample = names(met_mean),
met = met_mean,
tibble(sample = names(met_mean),
met = met_mean,
probe_number = probe_number),
tibble(sample = colnames(TPM),
tibble(sample = colnames(TPM),
tissue = ifelse(TPM$shortLetterCode == "NT",
"Peritumoral", "Tumor"),
type = TPM$type,
TPM = as.vector(assay(TPM)))))
if (!include_normal_tissues) methylation_expression <-

if (!include_normal_tissues) methylation_expression <-
methylation_expression[methylation_expression$tissue != "Peritumoral", ]
methylation_expression <- dplyr::select(methylation_expression, "sample",
"tissue", "type", "probe_number",


methylation_expression <- dplyr::select(methylation_expression, "sample",
"tissue", "type", "probe_number",
"met", "TPM")

}


Expand Down Expand Up @@ -330,5 +333,3 @@ cell_type_colors <- c(
"Mesenchymal_cells" = "peachpuff",
"Pigment_cells" = "palegreen2", "Myoid" = "gray54",
"Specialized_epithelial_cells" = "indianred1")


1 change: 0 additions & 1 deletion man/CT_correlated_genes.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/TCGA_expression.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions man/TCGA_methylation_expression_correlation.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion man/prepare_TCGA_methylation_expression.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/subset_database.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/testis_expression.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c012517

Please sign in to comment.