Last updated: 2024-03-21

Checks: 7 0

Knit directory: Celina/

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(20231207) 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.

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:


Untracked files:
    Untracked:  .Rprofile
    Untracked:  .gitattributes
    Untracked:  .gitignore
    Untracked:  Celina.Rproj
    Untracked:  README.md
    Untracked:  _workflowr.yml
    Untracked:  analysis/
    Untracked:  code/
    Untracked:  data/
    Untracked:  output/

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.


There are no past versions. Publish this analysis with wflow_publish() to start tracking its development.


Load in data

The processed example data can be downloaded from here.

# load in data
load(paste0("./data/scRNA_data_RCC_PD47171in_tumor_interface.RData"))
# single cell reference data
load(paste0("./data/data_RCC_PD47171in_tumor_interface.RData"))
# 10x visium spatial transcriptomics data
names(sc_section)
names(data_section)

Create Celina object

# filter genes: 
# 1. remove mt genes:
mito_genes = unique(c(grep("^MT-", rownames(data_section$count)), grep("^mt-", rownames(data_section$count))))
# 2. remove genes expressed in less than 20 locations
low_genes = which(rowSums(data_section$count>0)<20)
remove_genes = unique(c(mito_genes, low_genes))
if(length(remove_genes)>0){
    data_expr_in = data_section$count[-remove_genes,]
}else{
    data_expr_in = data_section$count
}

library(CELINA)

Obj = Create_Celina_Object(celltype_mat = t(data_section$celltype_proportion), 
                              gene_expression_mat = as.matrix(data_expr_in), 
                              location = as.matrix(data_section$location_coord),
                              covariates = NULL,
                              project = "Kidney Cancer")

Preprocess data

In this step, we preprocess the gene expression matrix by normalizing the counts and filtering genes.

# if you want to further filter cell types based on their total proportion across spots, or you only want to test a subset of cell types, you can select the cell types here:
filtered_cell_types = colnames(data_section$celltype_proportion)[which(colSums(data_section$celltype_proportion) > (dim(data_section$celltype_proportion)[1]*0.01))]
filtered_cell_types

Obj = preprocess_input(Obj, 
                       # Celina object
                       cell_types_to_test = filtered_cell_types,  
                       # a vector of cell types to be used for testing 
                       scRNA_count = as.matrix(sc_section$count), 
                       # a gene x cell expression matrix of reference scRNA-seq data
                       sc_cell_type_labels = sc_section$meta$broad_type,
                       # a vector of cell type labels for each cell in scRNA_count
                       threshold = 5e-5)
print(names(Obj@genes_list))

Calculate the kernel matrix

Obj = Calculate_Kernel(Obj, approximation = FALSE)
# this RCC tumor interface data is small with only 2048 spots, so we didn't select the approximation option.

Test genes

Here we choose RCC from filtered_cell_types as an example, because RCC represents renal cell carcinoma cell which is a type of cancer cell and is of our interest. Or you can also input celltype_to_test=filtered_cell_types, to test all genes and cell type pairs.

Obj = Testing_interaction_all(Obj,method = "MM",celltype_to_test = "RCC", num_cores=20)

sessionInfo()
R version 4.3.3 (2024-02-29)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.6 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/liblapack.so.3;  LAPACK version 3.9.0

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

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

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

loaded via a namespace (and not attached):
 [1] vctrs_0.6.5       cli_3.6.2         knitr_1.45        rlang_1.1.2      
 [5] xfun_0.41         stringi_1.8.3     promises_1.2.1    jsonlite_1.8.8   
 [9] workflowr_1.7.1   glue_1.7.0        rprojroot_2.0.4   git2r_0.33.0     
[13] htmltools_0.5.7   httpuv_1.6.13     sass_0.4.8        fansi_1.0.5      
[17] rmarkdown_2.25    jquerylib_0.1.4   evaluate_0.23     tibble_3.2.1     
[21] fastmap_1.1.1     yaml_2.3.8        lifecycle_1.0.4   stringr_1.5.1    
[25] compiler_4.3.3    fs_1.6.3          Rcpp_1.0.12       pkgconfig_2.0.3  
[29] rstudioapi_0.15.0 later_1.3.2       digest_0.6.33     R6_2.5.1         
[33] utf8_1.2.4        pillar_1.9.0      magrittr_2.0.3    bslib_0.6.1      
[37] tools_4.3.3       cachem_1.0.8