Last updated: 2025-05-05

Checks: 7 0

Knit directory: Ulceration_paper_github/

This reproducible R Markdown analysis was created with workflowr (version 1.7.1). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.

Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.

The command set.seed(20250330) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.

Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.

Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.

The results in this page were generated with repository version 6cb2a25. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:


Ignored files:
    Ignored:    .Rproj.user/
    Ignored:    data/cibersort_res_ulc.rds
    Ignored:    data/cibersort_res_ulc_lf.rds
    Ignored:    omnipathr-log/
    Ignored:    output/ulceration_combined_panel.pdf

Untracked files:
    Untracked:  .Rhistory

Unstaged changes:
    Modified:   .gitignore

Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.


These are the previous versions of the repository in which changes were made to the R Markdown (analysis/figure2_DE.Rmd) and HTML (docs/figure2_DE.html) files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view the files as they were in that past version.

File Version Author Date Message
html 07d0307 Estef Vazquez 2025-04-04 Build site.
Rmd 90f2ad0 Estef Vazquez 2025-04-04 Add data download system and update gitignore
html 89c14cd Estef Vazquez 2025-04-04 Build site.
html c17335e Estef Vazquez 2025-04-04 Build site.
html 3148fdc Estef Vazquez 2025-04-04 Build site.
Rmd 248524c Estef Vazquez 2025-04-04 Update
Rmd 467227d Estef Vazquez 2025-04-04 wflow_rename("analysis/test_render_figure2.Rmd", "analysis/figure2_DE.Rmd")
html 467227d Estef Vazquez 2025-04-04 wflow_rename("analysis/test_render_figure2.Rmd", "analysis/figure2_DE.Rmd")

Differential expression analysis

This document incorporates differential expression analysis and PCA, in relation to ulceration status in acral melanoma samples. It generates PCA and volcano plots.

# Load required libraries
library(tidyverse)
library(DESeq2)
library(factoextra)
library(RColorBrewer) 
library(ggrepel) 
library(plotly)
library(here)
# Data Preparation - subset metadata 
exp_design <- metadata %>% dplyr::select(sample_id, batch_number, sex, age, ulceration)

# Load raw count data
cts <- readRDS("data/rawcounts_am.rds")

# Scale age 
exp_design$age_scaled <- scale(exp_design$age)

# Evaluate ulceration effect while accounting for batch, sex, and age 
dds <- DESeqDataSetFromMatrix(
  countData = cts,
  colData = exp_design, 
  design = ~ batch_number + age_scaled + sex + ulceration,
  tidy = FALSE
)

# Estimate size factors
dds <- estimateSizeFactors(dds)

# Pre-filtering 
keep <- rowSums( counts(dds, normalized = TRUE) >= 10 ) >=20
dds <- dds[keep,]

# Set reference level for ulceration
dds$ulceration <- relevel(dds$ulceration, ref = "0")

# Extract normalized counts 
normalized_counts_deseq <- counts(dds, normalized=TRUE)

# Run DE
dds_ulc <- DESeq(dds)
dim(dds_ulc)
[1] 19319    59
# Apply apeglm shrinkage 
resLFC <- lfcShrink(dds_ulc, coef="ulceration_1_vs_0", type="apeglm")

# Extract results with ulceration 1 vs 0 contrast
res <- results(dds_ulc, contrast = c("ulceration", "1", "0"), alpha = 0.05)


# Variance stabilizing transformation for visualization
vsd <- vst(dds_ulc, blind=FALSE) 

# Processing results - order by LFC 
resOrdered <- res[order(res$log2FoldChange),]
ranked_GSEA <- as.data.frame(resOrdered)  
#saveRDS(ranked_GSEA, "DE_results_ulceration_ranked.rds")

# Extract significant genes 
sig_genes <- subset(res, padj < 0.05)

# Order significant genes by fold change
LFC_ordered <-( sig_genes[ order( sig_genes$log2FoldChange ), ] )
LFC_ordered_df <- as.data.frame(LFC_ordered)

# Prepare results with gene IDs 
res_ids <- as.data.frame(res) %>% 
  rownames_to_column(var = "ENSEMBL_GENE_ID")

# Load gene annotation mapping
gene_ann <- readRDS("data/annotation.rds")

# Join results
res_final <- inner_join(res_ids, gene_ann, by="ENSEMBL_GENE_ID") %>% 
  relocate(external_gene_name, .after = ENSEMBL_GENE_ID) 

# Make unique rownames 
names <- make.unique(res_final$external_gene_name)
rownames(res_final) <- names

# Order complete results by LFC
res_final_ordered_LFC <- ( res_final[ order( res_final$log2FoldChange ), ] )

# Process significant genes with gene symbols
significant_genes_ids <- LFC_ordered_df %>%
  rownames_to_column(var = "ENSEMBL_GENE_ID")

# Join with gene symbols
significant_genes_final <- inner_join(significant_genes_ids, gene_ann, by="ENSEMBL_GENE_ID") %>% 
  relocate(external_gene_name, .after = ENSEMBL_GENE_ID) 

# Make row names 
names <- make.unique(significant_genes_final$external_gene_name)
rownames(significant_genes_final) <- names

# write_csv(significant_genes_final, "DE_results_significant.csv")

2A - Principal Component Analysis

# PCA with top 1000 highly variable genes
pcaData <- plotPCA(vsd, intgroup=c("ulceration"), 
                   ntop=1000, 
                   returnData=TRUE)

# Extract variance percentages
percentVar <- round(100 * attr(pcaData, "percentVar"))

# Create plot
ggplot(pcaData, aes(x = PC1, y = PC2, color = group)) +
  geom_point(size = 3) + 
  theme_bw() +
  scale_color_manual(
    values = c("#730769", "#E8CC03"),
    name = "Ulceration Status",
    labels = c("No", "Yes")
  ) +  
  theme(
    legend.position = "right",
    panel.grid.minor = element_blank(),
    axis.title = element_text(size = 12, face = "bold"),
    legend.title = element_text(size = 11, face = "bold"),
    legend.text = element_text(size = 10)
  ) +
  ggtitle("PCA Plot of Gene Expression by Ulceration Status") +
  xlab(paste0("PC1 (", percentVar[1], "% variance)")) +
  ylab(paste0("PC2 (", percentVar[2], "% variance)"))

Version Author Date
3148fdc Estef Vazquez 2025-04-04

2B - Volcano Plot

# Theme 
theme_set(theme_classic(base_size = 20) +
  theme(
    axis.title.y = element_text(face = "bold", margin = margin(0, 20, 0, 0), size = rel(1.1), color = 'black'),
    axis.title.x = element_text(hjust = 0.5, face = "bold", margin = margin(20, 0, 0, 0), size = rel(1.1), color = 'black'),
    plot.title = element_text(hjust = 0.5)
  ))

# Create and save plot
create_volcano_plot <- function(data, 
                               fc_threshold = 1.5,
                               padj_threshold = 0.05,
                               ylim = c(0, 10),
                               xlim = c(-6, 6),
                               top_genes = 100,
                               output_file = NULL,
                               italic_labels = TRUE) {
  
  # Classify genes by expression
  data$diffexpressed <- "NO"
  data$diffexpressed[data$log2FoldChange > fc_threshold & data$padj < padj_threshold] <- "UP"
  data$diffexpressed[data$log2FoldChange < -fc_threshold & data$padj < padj_threshold] <- "DOWN"
  
  # Label top differentially expressed genes
  data$delabel <- ifelse(
    data$external_gene_name %in% head(data[order(data$padj), "external_gene_name"], top_genes),
    data$external_gene_name, 
    NA
  )

  plot <- ggplot(data = data, 
                aes(x = log2FoldChange, 
                    y = -log10(padj), 
                    col = diffexpressed, 
                    label = delabel)) +
    geom_vline(xintercept = c(-fc_threshold, fc_threshold), col = "gray", linetype = 'dashed') +
    geom_hline(yintercept = -log10(padj_threshold), col = "gray", linetype = 'dashed') + 
    geom_point(size = 2.5) + 
    scale_color_manual(
      values = c("#00AFBB", "grey", "#bb0c00"),
      labels = c("Downregulated", "Not significant", "Upregulated")
    ) +
    coord_cartesian(ylim = ylim, xlim = xlim) +
    labs(
      color = 'DE Genes',
      x = expression("log"[2]*"FC"), 
      y = expression("-log"[10]*"padj")
    ) + 
    scale_x_continuous(breaks = seq(-10, 10, 2)) +
    ggtitle('Ulcerated vs Non-ulcerated Acral Melanoma') +
    geom_text_repel(
      max.overlaps = Inf,
      fontface = if(italic_labels) "italic" else "plain"
    )
  
    if (!is.null(output_file)) {
    pdf(file = output_file, width = 13, height = 12)
    print(plot)
    dev.off()
  }
  
  return(plot)
}

# Generate final plot
volcanoplot <- create_volcano_plot(
  data = res_final_ordered_LFC,
  fc_threshold = 1.5,
  padj_threshold = 0.05,
  ylim = c(0, 10),
  xlim = c(-6, 6),
  top_genes = 100,
  italic_labels = TRUE,
  output_file = "volcanoplot.pdf"
)

volcanoplot

Version Author Date
07d0307 Estef Vazquez 2025-04-04
89c14cd Estef Vazquez 2025-04-04
c17335e Estef Vazquez 2025-04-04
3148fdc Estef Vazquez 2025-04-04

Interactive Volcano

dat <- tibble(genename = (res_final$external_gene_name),
              x = res_final$log2FoldChange,
              y = -log10(res_final$padj),
              col = ifelse(res_final$padj < 0.05 & res_final$log2FoldChange > 1.5, "Upregulated",
                    ifelse(res_final$padj < 0.05 & res_final$log2FoldChange < -1.5, "Downregulated", "Non-significant")))

fig <- plot_ly(dat, x = ~x, y = ~y, 
               color = ~col,
               colors = c("Downregulated" = "#00AFBB", "Non-significant" = "grey", "Upregulated" = "#bb0c00"),
               text = ~genename, 
               hoverinfo = "text", 
               type = "scatter", 
               mode = "markers")

fig <- fig %>% 
  layout(plot_bgcolor = 'white',
         paper_bgcolor = 'white',
         xaxis = list(title = 'Log2 fold change',
                     range = c(-6, 6),
                     zeroline = FALSE),
         yaxis = list(title = '-Log10 Padj',
                     range = c(0, 10)),
         legend = list(title = list(text = '<b> Genes </b>'),
                      traceorder = "reversed")) 

fig <- fig %>% 
  layout(
    legend = list(
      title = list(text = '<b> Genes </b>'),
      traceorder = "normal"
    )
  )

fig
sessionInfo()
R version 4.4.0 (2024-04-24)
Platform: x86_64-pc-linux-gnu
Running under: Ubuntu 22.04.4 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.10.0 
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.10.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=es_MX.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=es_MX.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=es_MX.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=es_MX.UTF-8 LC_IDENTIFICATION=C       

time zone: America/Mexico_City
tzcode source: system (glibc)

attached base packages:
[1] stats4    stats     graphics  grDevices utils     datasets  methods  
[8] base     

other attached packages:
 [1] here_1.0.1                  plotly_4.10.4              
 [3] ggrepel_0.9.6               RColorBrewer_1.1-3         
 [5] factoextra_1.0.7            DESeq2_1.44.0              
 [7] SummarizedExperiment_1.34.0 Biobase_2.64.0             
 [9] MatrixGenerics_1.16.0       matrixStats_1.4.1          
[11] GenomicRanges_1.56.2        GenomeInfoDb_1.40.1        
[13] IRanges_2.38.1              S4Vectors_0.42.1           
[15] BiocGenerics_0.50.0         lubridate_1.9.4            
[17] forcats_1.0.0               stringr_1.5.1              
[19] dplyr_1.1.4                 purrr_1.0.2                
[21] readr_2.1.5                 tidyr_1.3.1                
[23] tibble_3.2.1                ggplot2_3.5.1              
[25] tidyverse_2.0.0             workflowr_1.7.1            

loaded via a namespace (and not attached):
 [1] rlang_1.1.4             magrittr_2.0.3          git2r_0.33.0           
 [4] compiler_4.4.0          getPass_0.2-4           callr_3.7.6            
 [7] vctrs_0.6.5             pkgconfig_2.0.3         crayon_1.5.3           
[10] fastmap_1.2.0           XVector_0.44.0          labeling_0.4.3         
[13] promises_1.3.2          rmarkdown_2.29          tzdb_0.4.0             
[16] UCSC.utils_1.0.0        ps_1.8.1                xfun_0.49              
[19] zlibbioc_1.50.0         cachem_1.1.0            jsonlite_1.8.9         
[22] later_1.4.1             DelayedArray_0.30.1     BiocParallel_1.38.0    
[25] parallel_4.4.0          R6_2.5.1                bslib_0.8.0            
[28] stringi_1.8.4           jquerylib_0.1.4         numDeriv_2016.8-1.1    
[31] Rcpp_1.0.13-1           knitr_1.49              httpuv_1.6.15          
[34] Matrix_1.6-5            timechange_0.3.0        tidyselect_1.2.1       
[37] rstudioapi_0.17.1       abind_1.4-5             yaml_2.3.10            
[40] codetools_0.2-19        processx_3.8.4          lattice_0.22-5         
[43] plyr_1.8.9              withr_3.0.2             coda_0.19-4.1          
[46] evaluate_1.0.1          pillar_1.10.0           whisker_0.4.1          
[49] generics_0.1.3          rprojroot_2.0.4         emdbook_1.3.13         
[52] hms_1.1.3               munsell_0.5.1           scales_1.3.0           
[55] glue_1.8.0              lazyeval_0.2.2          tools_4.4.0            
[58] apeglm_1.26.1           data.table_1.16.4       locfit_1.5-9.10        
[61] fs_1.6.5                mvtnorm_1.3-2           grid_4.4.0             
[64] bbmle_1.0.25.1          crosstalk_1.2.1         bdsmatrix_1.3-7        
[67] colorspace_2.1-1        GenomeInfoDbData_1.2.12 cli_3.6.3              
[70] S4Arrays_1.4.1          viridisLite_0.4.2       gtable_0.3.6           
[73] sass_0.4.9              digest_0.6.37           SparseArray_1.4.8      
[76] farver_2.1.2            htmlwidgets_1.6.4       htmltools_0.5.8.1      
[79] lifecycle_1.0.4         httr_1.4.7              MASS_7.3-60            

sessionInfo()
R version 4.4.0 (2024-04-24)
Platform: x86_64-pc-linux-gnu
Running under: Ubuntu 22.04.4 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.10.0 
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.10.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=es_MX.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=es_MX.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=es_MX.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=es_MX.UTF-8 LC_IDENTIFICATION=C       

time zone: America/Mexico_City
tzcode source: system (glibc)

attached base packages:
[1] stats4    stats     graphics  grDevices utils     datasets  methods  
[8] base     

other attached packages:
 [1] here_1.0.1                  plotly_4.10.4              
 [3] ggrepel_0.9.6               RColorBrewer_1.1-3         
 [5] factoextra_1.0.7            DESeq2_1.44.0              
 [7] SummarizedExperiment_1.34.0 Biobase_2.64.0             
 [9] MatrixGenerics_1.16.0       matrixStats_1.4.1          
[11] GenomicRanges_1.56.2        GenomeInfoDb_1.40.1        
[13] IRanges_2.38.1              S4Vectors_0.42.1           
[15] BiocGenerics_0.50.0         lubridate_1.9.4            
[17] forcats_1.0.0               stringr_1.5.1              
[19] dplyr_1.1.4                 purrr_1.0.2                
[21] readr_2.1.5                 tidyr_1.3.1                
[23] tibble_3.2.1                ggplot2_3.5.1              
[25] tidyverse_2.0.0             workflowr_1.7.1            

loaded via a namespace (and not attached):
 [1] rlang_1.1.4             magrittr_2.0.3          git2r_0.33.0           
 [4] compiler_4.4.0          getPass_0.2-4           callr_3.7.6            
 [7] vctrs_0.6.5             pkgconfig_2.0.3         crayon_1.5.3           
[10] fastmap_1.2.0           XVector_0.44.0          labeling_0.4.3         
[13] promises_1.3.2          rmarkdown_2.29          tzdb_0.4.0             
[16] UCSC.utils_1.0.0        ps_1.8.1                xfun_0.49              
[19] zlibbioc_1.50.0         cachem_1.1.0            jsonlite_1.8.9         
[22] later_1.4.1             DelayedArray_0.30.1     BiocParallel_1.38.0    
[25] parallel_4.4.0          R6_2.5.1                bslib_0.8.0            
[28] stringi_1.8.4           jquerylib_0.1.4         numDeriv_2016.8-1.1    
[31] Rcpp_1.0.13-1           knitr_1.49              httpuv_1.6.15          
[34] Matrix_1.6-5            timechange_0.3.0        tidyselect_1.2.1       
[37] rstudioapi_0.17.1       abind_1.4-5             yaml_2.3.10            
[40] codetools_0.2-19        processx_3.8.4          lattice_0.22-5         
[43] plyr_1.8.9              withr_3.0.2             coda_0.19-4.1          
[46] evaluate_1.0.1          pillar_1.10.0           whisker_0.4.1          
[49] generics_0.1.3          rprojroot_2.0.4         emdbook_1.3.13         
[52] hms_1.1.3               munsell_0.5.1           scales_1.3.0           
[55] glue_1.8.0              lazyeval_0.2.2          tools_4.4.0            
[58] apeglm_1.26.1           data.table_1.16.4       locfit_1.5-9.10        
[61] fs_1.6.5                mvtnorm_1.3-2           grid_4.4.0             
[64] bbmle_1.0.25.1          crosstalk_1.2.1         bdsmatrix_1.3-7        
[67] colorspace_2.1-1        GenomeInfoDbData_1.2.12 cli_3.6.3              
[70] S4Arrays_1.4.1          viridisLite_0.4.2       gtable_0.3.6           
[73] sass_0.4.9              digest_0.6.37           SparseArray_1.4.8      
[76] farver_2.1.2            htmlwidgets_1.6.4       htmltools_0.5.8.1      
[79] lifecycle_1.0.4         httr_1.4.7              MASS_7.3-60