Last updated: 2021-09-09

Checks: 7 0

Knit directory: mistyMBC/

This reproducible R Markdown analysis was created with workflowr (version 1.6.2). 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(42) 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 3de951e. 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:    .DS_Store
    Ignored:    .Rhistory
    Ignored:    .Rproj.user/
    Ignored:    analysis/.DS_Store
    Ignored:    analysis/.Rhistory
    Ignored:    code/
    Ignored:    data/
    Ignored:    omnipathr-log/
    Ignored:    output/.DS_Store
    Ignored:    output/HTAPP-213-SMP-6752/.DS_Store
    Ignored:    output/HTAPP-213-SMP-6752/HTAPP-213-SMP-6752_slide_seq_processed-1/.DS_Store
    Ignored:    output/HTAPP-213-SMP-6752/HTAPP-213-SMP-6752_slide_seq_processed-2/.DS_Store
    Ignored:    output/HTAPP-313-SMP-932/.DS_Store
    Ignored:    output/HTAPP-313-SMP-932/HTAPP-313-SMP-932_slide_seq_processed-1/.DS_Store
    Ignored:    output/HTAPP-313-SMP-932/HTAPP-313-SMP-932_slide_seq_processed-2/.DS_Store
    Ignored:    output/HTAPP-330-SMP-1082/.DS_Store
    Ignored:    output/HTAPP-330-SMP-1082/HTAPP-330-SMP-1082_slide_seq_processed-2/.DS_Store
    Ignored:    output/HTAPP-364-SMP-1321/.DS_Store
    Ignored:    output/HTAPP-514-SMP-6760/.DS_Store
    Ignored:    output/HTAPP-514-SMP-6760/HTAPP-514-SMP-6760_slide_seq_processed-1/.DS_Store
    Ignored:    output/HTAPP-514-SMP-6760/HTAPP-514-SMP-6760_slide_seq_processed-2/.DS_Store
    Ignored:    output/HTAPP-783-SMP-4081/.DS_Store
    Ignored:    output/HTAPP-783-SMP-4081/HTAPP-783-SMP-4081_slide_seq_processed-1/.DS_Store
    Ignored:    output/HTAPP-783-SMP-4081/HTAPP-783-SMP-4081_slide_seq_processed-2/.DS_Store
    Ignored:    output/HTAPP-812-SMP-8239/.DS_Store
    Ignored:    output/HTAPP-812-SMP-8239/HTAPP-812-SMP-8239_slide_seq_processed-1/.DS_Store
    Ignored:    output/HTAPP-812-SMP-8239/HTAPP-812-SMP-8239_slide_seq_processed-2/.DS_Store
    Ignored:    output/HTAPP-853-SMP-4381/.DS_Store
    Ignored:    output/HTAPP-853-SMP-4381/HTAPP-853-SMP-4381_slide_seq_processed-1/.DS_Store
    Ignored:    output/HTAPP-853-SMP-4381/HTAPP-853-SMP-4381_slide_seq_processed-2/.DS_Store
    Ignored:    output/HTAPP-878-SMP-7149/.DS_Store
    Ignored:    output/HTAPP-878-SMP-7149/HTAPP-878-SMP-7149_slide_seq_processed-1/.DS_Store
    Ignored:    output/HTAPP-878-SMP-7149/HTAPP-878-SMP-7149_slide_seq_processed-2/.DS_Store
    Ignored:    output/HTAPP-880-SMP-7179/.DS_Store
    Ignored:    output/HTAPP-880-SMP-7179/HTAPP-880-SMP-7179_slide_seq_processed-1/.DS_Store
    Ignored:    output/HTAPP-880-SMP-7179/HTAPP-880-SMP-7179_slide_seq_processed-2/.DS_Store
    Ignored:    output/HTAPP-895-SMP-7359/.DS_Store
    Ignored:    output/HTAPP-895-SMP-7359/HTAPP-895-SMP-7359_slide_seq_processed-1/.DS_Store
    Ignored:    output/HTAPP-917-SMP-4531/.DS_Store
    Ignored:    output/HTAPP-917-SMP-4531/HTAPP-917-SMP-4531_slide_seq_processed-2/.DS_Store
    Ignored:    output/HTAPP-944-SMP-7479/.DS_Store
    Ignored:    output/HTAPP-944-SMP-7479/HTAPP-944-SMP-7479_slide_seq_processed-1/.DS_Store
    Ignored:    output/HTAPP-982-SMP-7629/.DS_Store
    Ignored:    output/HTAPP-982-SMP-7629/HTAPP-982-SMP-7629_slide_seq_processed-1/.DS_Store
    Ignored:    output/HTAPP-997-SMP-7789/.DS_Store
    Ignored:    output/HTAPP-997-SMP-7789/HTAPP-997-SMP-7789_slide_seq_processed-1/.DS_Store
    Ignored:    output/HTAPP-997-SMP-7789/HTAPP-997-SMP-7789_slide_seq_processed-2/.DS_Store

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/cellcomm_misty.Rmd) and HTML (docs/cellcomm_misty.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 aa6ca6b Jovan Tanevski 2021-09-09 Build site.
html 2438eb2 Jovan Tanevski 2021-09-09 Build site.
html e0c1952 Jovan Tanevski 2021-07-22 Build site.
Rmd 3e63dcc Jovan Tanevski 2021-07-22 use normalized hvg, add ligand-pathway pipeline
html 4dd6a02 Jovan Tanevski 2021-07-14 Build site.
Rmd 125da67 Jovan Tanevski 2021-07-14 add slideseq cellcomm pipeline and outputs
html 125da67 Jovan Tanevski 2021-07-14 add slideseq cellcomm pipeline and outputs

Setup

library(reticulate)
library(mistyR)
library(future)
library(dplyr)
library(purrr)
library(OmnipathR)
library(stringr)
library(progeny)

use_python("/usr/local/bin/python3")
plan(multisession)

Create ligand-receptor oriented mistyR pipeline

Get ligand and receptor symbols from Omnipath

extract_symbols <- function(op.source) {
  proteins <- op.source %>%
    filter(entity_type == "protein") %>%
    pull(genesymbol)
  complexes <- op.source %>%
    filter(entity_type == "complex") %>%
    pull(genesymbol) %>%
    str_remove("COMPLEX:") %>%
    str_split("_") %>%
    unlist()
  return(union(proteins, complexes) %>% make.names())
}

op.ligands <- import_omnipath_intercell(
  categories = "ligand",
  secreted = TRUE,
  consensus_percentile = 50
)

ligands <- extract_symbols(op.ligands)

op.receptors <- import_omnipath_intercell(
  categories = "receptor",
  secreted = FALSE,
  consensus_percentile = 50
)

receptors <- extract_symbols(op.receptors)

Define and run ligand receptor and ligand pathway oriented mistyR pipelines for MBC cells in SlideSeq data. Relate expression of genes annotated as ligands in the neighborhood of each MBC cell to its intracellular receptor expression or estimated pathway activities.

# 364 is a tricky sample
(list.files("data", ".h5ad", recursive = TRUE, full.names = TRUE) %>%
  keep(~ str_detect(.x, "slide_seq")))[-4] %>%
  walk(function(datapath) {
    data <- py$read_and_extract(datapath)
    mbs <- which(data[[1]][, which(str_detect(colnames(data[[1]]), "MBC"))] >= 0.9)
    expr <- as.data.frame((data[[2]])) %>%
      slice(mbs) %>%
      `colnames<-`(make.names(data[[4]]))
    pos <- data[[3]] %>% slice(mbs)

    unique(str_extract(rownames(pos), "-\\d$")) %>% walk(function(replicate) {
      output.folder <- paste0(
        str_replace(
          str_remove(datapath, ".h5ad"),
          "data", "output"
        ), replicate
      )

      if (!dir.exists(output.folder)) dir.create(output.folder)

      ind <- str_which(rownames(pos), paste0(replicate, "$"))

      if (length(list.files(output.folder)) < 2) {
        ligand.views <- create_initial_view(expr[ind, ] %>%
          select(-names(which(apply(., 2, var) == 0))) %>%
          select(any_of(ligands))) %>%
          add_paraview(pos[ind, ], 100)
      }

      if (!(dir.exists(paste0(output.folder, "/ligrcp")) |
        dir.exists(paste0(output.folder, "/ligrcp_failed")))) {
        
        misty.views.ligrcp <- create_initial_view(expr[ind, ] %>%
          select(-names(which(apply(., 2, var) == 0))) %>%
          select(any_of(receptors))) %>%
          add_views(list(ligand.views[["paraview.100"]]))

        tryCatch(
          run_misty(misty.views.ligrcp, results.folder = paste0(output.folder, "/ligrcp")),
          error = function(e) {
            file.rename(
              paste0(output.folder, "/ligrcp"),
              paste0(output.folder, "/ligrcp_failed")
            )
          }
        )
      }
      if (!(dir.exists(paste0(output.folder, "/ligpath")) |
        dir.exists(paste0(output.folder, "/ligpath_failed")))) {
        path.activity <- progeny(expr = t(expr[ind, ]), top = 500, scale = TRUE) %>%
          as_tibble(.name_repair = make.names)

        misty.views.ligpath <- create_initial_view(as_tibble(path.activity)) %>%
          add_views(list(ligand.views[["paraview.100"]]))

        tryCatch(
          run_misty(misty.views.ligpath, results.folder = paste0(output.folder, "/ligpath")),
          error = function(e) {
            file.rename(
              paste0(output.folder, "/ligpath"),
              paste0(output.folder, "/ligpath_failed")
            )
          }
        )
      }
    })
  })

sessionInfo()
R version 4.1.1 (2021-08-10)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur 10.16

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
[1] progeny_1.14.0  stringr_1.4.0   OmnipathR_3.0.4 purrr_0.3.4    
[5] dplyr_1.0.7     future_1.22.1   mistyR_1.1.9    reticulate_1.20
[9] workflowr_1.6.2

loaded via a namespace (and not attached):
 [1] httr_1.4.2        sass_0.4.0        tidyr_1.1.3       bit64_4.0.5      
 [5] vroom_1.5.4       jsonlite_1.7.2    bslib_0.3.0       assertthat_0.2.1 
 [9] cellranger_1.1.0  yaml_2.2.1        progress_1.2.2    ggrepel_0.9.1    
[13] globals_0.14.0    pillar_1.6.2      backports_1.2.1   lattice_0.20-44  
[17] glue_1.4.2        digest_0.6.27     promises_1.2.0.1  checkmate_2.0.0  
[21] colorspace_2.0-2  htmltools_0.5.2   httpuv_1.6.2      Matrix_1.3-4     
[25] pkgconfig_2.0.3   logger_0.2.1      listenv_0.8.0     scales_1.1.1     
[29] whisker_0.4       later_1.3.0       tzdb_0.1.2        git2r_0.28.0     
[33] tibble_3.1.4      generics_0.1.0    ggplot2_3.3.5     ellipsis_0.3.2   
[37] magrittr_2.0.1    crayon_1.4.1      readxl_1.3.1      evaluate_0.14    
[41] fs_1.5.0          fansi_0.5.0       parallelly_1.27.0 xml2_1.3.2       
[45] tools_4.1.1       prettyunits_1.1.1 hms_1.1.0         lifecycle_1.0.0  
[49] munsell_0.5.0     compiler_4.1.1    jquerylib_0.1.4   rlang_0.4.11     
[53] grid_4.1.1        rappdirs_0.3.3    igraph_1.2.6      rmarkdown_2.10   
[57] gtable_0.3.0      codetools_0.2-18  DBI_1.1.1         curl_4.3.2       
[61] R6_2.5.1          gridExtra_2.3     knitr_1.33        bit_4.0.4        
[65] fastmap_1.1.0     utf8_1.2.2        rprojroot_2.0.2   readr_2.0.1      
[69] stringi_1.7.4     parallel_4.1.1    Rcpp_1.0.7        vctrs_0.3.8      
[73] png_0.1-7         tidyselect_1.1.1  xfun_0.25