Last updated: 2022-04-19

Checks: 7 0

Knit directory: Abatacept_scrnaseq_mi/

This reproducible R Markdown analysis was created with workflowr (version 1.7.0). 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(20220318) 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 6fc473c. 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:    .Rhistory
    Ignored:    .Rproj.user/

Untracked files:
    Untracked:  code/utils.R
    Untracked:  code/utils_nichenet.R
    Untracked:  data/Table_1_Common Transcriptomic Effects of Abatacept and Other DMARDs on Rheumatoid Arthritis Synovial Tissue.xlsx
    Untracked:  omnipathr-log/

Unstaged changes:
    Deleted:    analysis/7_Conclusions.Rmd
    Deleted:    analysis/7_summary.Rmd

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/5_pathway_analysis.Rmd) and HTML (docs/5_pathway_analysis.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 a71b19c Florian Wuennemann 2022-04-19 Build site.
Rmd 86ff3e7 Florian Wuennemann 2022-04-19 Main Update to code and adding NichenetR
html 6e3bb2f Florian Wuennemann 2022-03-25 Build site.
html 855945a Florian Wuennemann 2022-03-25 Build site.
Rmd 3796e51 Florian Wuennemann 2022-03-25 wflow_publish("analysis/5_pathway_analysis.Rmd")
html b47d7b0 Florian Wuennemann 2022-03-24 Build site.
Rmd 8591656 Florian Wuennemann 2022-03-24 wflow_publish(c("analysis/1_process_and_integrate_Seurat_Harmony.Rmd",
html 46f2db7 Florian Wuennemann 2022-03-23 First commit.

Aim

In this markdown, we will perform pathway enrichment analysis. We will first score all cells for different pathways and then perform differential pathway activity between cells from control and treatment samples, to identify interesting, differential pathways in response to Abatacept treatment.

Load data

seurat_object_filt <- readRDS(here("../data/2_annotated.seurat_object.rds"))

Hallmark gene sets

Let’s use Hallmark gene sets, as they are a small, well defined number of pathways, that can easily be run locally and quickly.

## Load gene sets
gene.sets <- getGeneSets(species = "Mus musculus", library = c("H"))

Now we score all cells for pathway activity.

## Only run analysis if it hasn't been computed yet
es_H_object_name <- here("../results/5_enrichment_H.results.rds")
if(file.exists(es_H_object_name)){ ## IF results have been computed, read the object
  ES <- readRDS(es_H_object_name)
}else{
  ES <- enrichIt(obj = seurat_object_filt, 
               gene.sets = gene.sets, 
               groups = 1000, cores = 2, 
               min.size = NULL)
  saveRDS(ES,
        file = es_H_object_name)
}

Finally, we add the pathway activity as metadata for each cell to the Seurat object.

seurat_ex <- AddMetaData(seurat_object_filt, ES)
colorblind_vector <- colorRampPalette(rev(c("#0D0887FF", "#47039FFF", 
              "#7301A8FF", "#9C179EFF", "#BD3786FF", "#D8576BFF",
              "#ED7953FF","#FA9E3BFF", "#FDC926FF", "#F0F921FF")))

Perform differential pathway analysis

Now, we will try to identify differential pathways between control and treatment cells for each cell type.

ES2 <- data.frame(seurat_ex[[]], Idents(seurat_ex))
all_ES <- data.frame()

for(this_celltype in unique(ES2$cell_type)){
  
  ES2_sub <- subset(ES2,cell_type == this_celltype)
  ES2_sub <- ES2_sub %>%
    select(starts_with("HALLMARK"),group)
  
  output <- getSignificance(ES2_sub, group = "group", fit = "T.test")
  output_form <- output %>%
    mutate("cell_type" = this_celltype,
           "pathway" = rownames(output))
  rownames(output_form) <- 1:nrow(output_form)
  
  all_ES <- rbind(all_ES,output_form)
}

all_ES_sig <- all_ES %>%
  arrange(FDR) %>%
  subset(FDR < 0.05)

Let’s add some more information to this table and save it.

all_ES <- all_ES %>%
  mutate("log2foldChange" = log2(median.treatment / median.control)) %>%
  mutate("direction" = if_else(log2foldChange > 0,"higher_in_control","higher_in_treatment"))
Warning in mask$eval_all_mutate(quo): NaNs produced
## Save table
write.table(all_ES,
            file = here("../results/pathway_enrichment.GSEA_Hallmark.all_res.tsv"),
            sep = "\t",
            col.names = TRUE,
            row.names = FALSE,
            quote = FALSE)

Table of enrichment results

Let’s look at a table of the differential pathway results.

## Show table of top differentially active pathways
reactable(all_ES_sig,
          resizable = TRUE, showPageSizeOptions = TRUE, searchable = TRUE,
          filterable = TRUE,
          onClick = "expand", highlight = TRUE)

Plot top hits

We can also plot the top hit using a violin plot across cells.

## Plot the top enriched pathway
splitEnrichment(ES2, x.axis = "cell_type", split = "group", 
                gene.set = all_ES_sig[1,]$pathway) +
  coord_flip()

Version Author Date
855945a Florian Wuennemann 2022-03-25
## Let's visualize the enrichment difference for Inflammatory response in activated fibroblasts between control and treatment samples
ES2_fibact <- subset(ES2,cell_type ="Fib_act")

splitEnrichment(ES2_fibact, split = "group", gene.set = all_ES_sig[1,]$pathway)

Version Author Date
855945a Florian Wuennemann 2022-03-25

Heatmap of top differentially regulated pathways by cell type

all_ES_wide <- all_ES %>%
  dplyr::select(pathway,cell_type,FDR) %>%
  pivot_wider(names_from = cell_type, values_from = FDR)

pathways <- all_ES_wide$pathway
all_ES_wide <- all_ES_wide %>%
  select(-pathway)

all_ES_wide <- as.matrix(-log10(all_ES_wide))
rownames(all_ES_wide) <- pathways

library(pheatmap)
ComplexHeatmap::pheatmap(all_ES_wide)

Version Author Date
a71b19c Florian Wuennemann 2022-04-19

sessionInfo()
R version 4.1.3 (2022-03-10)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.4 LTS

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

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

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

other attached packages:
 [1] pheatmap_1.0.12    here_1.0.1         reactable_0.2.3    forcats_0.5.1     
 [5] stringr_1.4.0      dplyr_1.0.8        purrr_0.3.4        readr_2.1.2       
 [9] tidyr_1.2.0        tibble_3.1.6       tidyverse_1.3.1    dittoSeq_1.7.0    
[13] ggplot2_3.3.5      escape_1.4.1       SeuratObject_4.0.4 Seurat_4.1.0      
[17] workflowr_1.7.0   

loaded via a namespace (and not attached):
  [1] scattermore_0.8             R.methodsS3_1.8.1          
  [3] bit64_4.0.5                 knitr_1.38                 
  [5] irlba_2.3.5                 DelayedArray_0.20.0        
  [7] R.utils_2.11.0              data.table_1.14.2          
  [9] rpart_4.1.16                doParallel_1.0.17          
 [11] KEGGREST_1.34.0             RCurl_1.98-1.6             
 [13] generics_0.1.2              BiocGenerics_0.40.0        
 [15] ScaledMatrix_1.2.0          callr_3.7.0                
 [17] cowplot_1.1.1               RSQLite_2.2.12             
 [19] RANN_2.6.1                  future_1.24.0              
 [21] bit_4.0.4                   tzdb_0.3.0                 
 [23] spatstat.data_2.1-4         xml2_1.3.3                 
 [25] lubridate_1.8.0             httpuv_1.6.5               
 [27] SummarizedExperiment_1.24.0 assertthat_0.2.1           
 [29] xfun_0.30                   hms_1.1.1                  
 [31] jquerylib_0.1.4             babelgene_22.3             
 [33] evaluate_0.15               promises_1.2.0.1           
 [35] fansi_1.0.3                 dbplyr_2.1.1               
 [37] readxl_1.4.0                igraph_1.3.0               
 [39] DBI_1.1.2                   htmlwidgets_1.5.4          
 [41] spatstat.geom_2.4-0         stats4_4.1.3               
 [43] ellipsis_0.3.2              crosstalk_1.2.0            
 [45] backports_1.4.1             annotate_1.72.0            
 [47] deldir_1.0-6                sparseMatrixStats_1.7.0    
 [49] MatrixGenerics_1.7.0        vctrs_0.4.1                
 [51] SingleCellExperiment_1.16.0 Biobase_2.54.0             
 [53] remotes_2.4.2               ROCR_1.0-11                
 [55] abind_1.4-5                 cachem_1.0.6               
 [57] withr_2.5.0                 sctransform_0.3.3          
 [59] goftest_1.2-3               cluster_2.1.3              
 [61] lazyeval_0.2.2              crayon_1.5.1               
 [63] labeling_0.4.2              pkgconfig_2.0.3            
 [65] GenomeInfoDb_1.30.1         nlme_3.1-157               
 [67] nnet_7.3-17                 rlang_1.0.2                
 [69] globals_0.14.0              lifecycle_1.0.1            
 [71] miniUI_0.1.1.1              modelr_0.1.8               
 [73] rsvd_1.0.5                  cellranger_1.1.0           
 [75] rprojroot_2.0.3             polyclip_1.10-0            
 [77] GSVA_1.42.0                 matrixStats_0.61.0         
 [79] lmtest_0.9-40               reactR_0.4.4               
 [81] graph_1.72.0                Matrix_1.4-1               
 [83] Rhdf5lib_1.16.0             zoo_1.8-9                  
 [85] reprex_2.0.1                GlobalOptions_0.1.2        
 [87] whisker_0.4                 ggridges_0.5.3             
 [89] processx_3.5.3              rjson_0.2.21               
 [91] png_0.1-7                   viridisLite_0.4.0          
 [93] bitops_1.0-7                getPass_0.2-2              
 [95] R.oo_1.24.0                 KernSmooth_2.23-20         
 [97] rhdf5filters_1.6.0          Biostrings_2.62.0          
 [99] blob_1.2.3                  DelayedMatrixStats_1.16.0  
[101] shape_1.4.6                 parallelly_1.31.0          
[103] spatstat.random_2.2-0       S4Vectors_0.32.4           
[105] beachmat_2.10.0             scales_1.2.0               
[107] memoise_2.0.1               GSEABase_1.56.0            
[109] magrittr_2.0.3              plyr_1.8.7                 
[111] ica_1.0-2                   zlibbioc_1.40.0            
[113] compiler_4.1.3              RColorBrewer_1.1-3         
[115] clue_0.3-60                 fitdistrplus_1.1-8         
[117] cli_3.2.0                   XVector_0.34.0             
[119] SeuratWrappers_0.3.0        listenv_0.8.0              
[121] patchwork_1.1.1             pbapply_1.5-0              
[123] ps_1.6.0                    MASS_7.3-56                
[125] mgcv_1.8-40                 tidyselect_1.1.2           
[127] stringi_1.7.6               highr_0.9                  
[129] yaml_2.3.5                  BiocSingular_1.10.0        
[131] ggrepel_0.9.1               grid_4.1.3                 
[133] sass_0.4.1                  tools_4.1.3                
[135] future.apply_1.8.1          parallel_4.1.3             
[137] circlize_0.4.14             rstudioapi_0.13            
[139] foreach_1.5.2               git2r_0.30.1               
[141] gridExtra_2.3               farver_2.1.0               
[143] Rtsne_0.15                  digest_0.6.29              
[145] BiocManager_1.30.16         shiny_1.7.1                
[147] Rcpp_1.0.8.3                GenomicRanges_1.46.1       
[149] broom_0.8.0                 later_1.3.0                
[151] RcppAnnoy_0.0.19            httr_1.4.2                 
[153] AnnotationDbi_1.56.2        ComplexHeatmap_2.10.0      
[155] colorspace_2.0-3            rvest_1.0.2                
[157] XML_3.99-0.9                fs_1.5.2                   
[159] tensor_1.5                  reticulate_1.24            
[161] IRanges_2.28.0              splines_4.1.3              
[163] uwot_0.1.11                 spatstat.utils_2.3-0       
[165] flexmix_2.3-17              plotly_4.10.0              
[167] xtable_1.8-4                jsonlite_1.8.0             
[169] modeltools_0.2-23           R6_2.5.1                   
[171] pillar_1.7.0                htmltools_0.5.2            
[173] mime_0.12                   glue_1.6.2                 
[175] fastmap_1.1.0               BiocParallel_1.28.3        
[177] codetools_0.2-18            utf8_1.2.2                 
[179] lattice_0.20-45             bslib_0.3.1                
[181] spatstat.sparse_2.1-0       leiden_0.3.9               
[183] survival_3.2-13             rmarkdown_2.13             
[185] munsell_0.5.0               GetoptLong_1.0.5           
[187] rhdf5_2.38.1                GenomeInfoDbData_1.2.7     
[189] iterators_1.0.14            UCell_1.3.1                
[191] HDF5Array_1.22.1            haven_2.4.3                
[193] reshape2_1.4.4              gtable_0.3.0               
[195] msigdbr_7.5.1               spatstat.core_2.4-2