Last updated: 2021-07-14

Checks: 6 1

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.


The R Markdown file has unstaged changes. To know which version of the R Markdown file created these results, you’ll want to first commit it to the Git repo. If you’re still working on the analysis, you can ignore this warning. When you’re finished, you can run wflow_publish to commit the R Markdown file and build the HTML.

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 35e2d92. 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:    output/.DS_Store
    Ignored:    output/HTAPP-213-SMP-6752/.DS_Store
    Ignored:    output/HTAPP-313-SMP-932/.DS_Store
    Ignored:    output/HTAPP-330-SMP-1082/.DS_Store
    Ignored:    output/HTAPP-364-SMP-1321/.DS_Store
    Ignored:    output/HTAPP-514-SMP-6760/.DS_Store
    Ignored:    output/HTAPP-853-SMP-4381/.DS_Store
    Ignored:    output/HTAPP-880-SMP-7179/.DS_Store
    Ignored:    output/HTAPP-895-SMP-7359/.DS_Store
    Ignored:    output/HTAPP-917-SMP-4531/.DS_Store
    Ignored:    output/HTAPP-944-SMP-7479/.DS_Store
    Ignored:    output/HTAPP-982-SMP-7629/.DS_Store
    Ignored:    output/HTAPP-997-SMP-7789/.DS_Store

Untracked files:
    Untracked:  analysis/cellcomm_misty.Rmd
    Untracked:  omnipathr-log/
    Untracked:  output/HTAPP-213-SMP-6752/HTAPP-213-SMP-6752_slide_seq_processed-1/
    Untracked:  output/HTAPP-213-SMP-6752/HTAPP-213-SMP-6752_slide_seq_processed-2/
    Untracked:  output/HTAPP-313-SMP-932/HTAPP-313-SMP-932_slide_seq_processed-1/
    Untracked:  output/HTAPP-313-SMP-932/HTAPP-313-SMP-932_slide_seq_processed-2/
    Untracked:  output/HTAPP-330-SMP-1082/HTAPP-330-SMP-1082_slide_seq_processed-2/
    Untracked:  output/HTAPP-514-SMP-6760/HTAPP-514-SMP-6760_slide_seq_processed-1/
    Untracked:  output/HTAPP-514-SMP-6760/HTAPP-514-SMP-6760_slide_seq_processed-2/
    Untracked:  output/HTAPP-783-SMP-4081/HTAPP-783-SMP-4081_slide_seq_processed-1/
    Untracked:  output/HTAPP-783-SMP-4081/HTAPP-783-SMP-4081_slide_seq_processed-2/
    Untracked:  output/HTAPP-812-SMP-8239/HTAPP-812-SMP-8239_slide_seq_processed-1/
    Untracked:  output/HTAPP-812-SMP-8239/HTAPP-812-SMP-8239_slide_seq_processed-2/
    Untracked:  output/HTAPP-853-SMP-4381/HTAPP-853-SMP-4381_slide_seq_processed-1/
    Untracked:  output/HTAPP-853-SMP-4381/HTAPP-853-SMP-4381_slide_seq_processed-2/
    Untracked:  output/HTAPP-878-SMP-7149/HTAPP-878-SMP-7149_slide_seq_processed-1/
    Untracked:  output/HTAPP-878-SMP-7149/HTAPP-878-SMP-7149_slide_seq_processed-2/
    Untracked:  output/HTAPP-880-SMP-7179/HTAPP-880-SMP-7179_slide_seq_processed-1/
    Untracked:  output/HTAPP-880-SMP-7179/HTAPP-880-SMP-7179_slide_seq_processed-2/
    Untracked:  output/HTAPP-895-SMP-7359/HTAPP-895-SMP-7359_slide_seq_processed-1/
    Untracked:  output/HTAPP-917-SMP-4531/HTAPP-917-SMP-4531_slide_seq_processed-2/
    Untracked:  output/HTAPP-944-SMP-7479/HTAPP-944-SMP-7479_slide_seq_processed-1/
    Untracked:  output/HTAPP-982-SMP-7629/HTAPP-982-SMP-7629_slide_seq_processed-1/
    Untracked:  output/HTAPP-997-SMP-7789/HTAPP-997-SMP-7789_slide_seq_processed-1/
    Untracked:  output/HTAPP-997-SMP-7789/HTAPP-997-SMP-7789_slide_seq_processed-2/

Unstaged changes:
    Modified:   analysis/index.Rmd
    Modified:   analysis/simple_misty.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/simple_misty.Rmd) and HTML (docs/simple_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 913535e Jovan Tanevski 2021-06-17 Build site.
html 1b68c27 Jovan Tanevski 2021-06-15 Build site.
Rmd 43913a8 Jovan Tanevski 2021-06-15 auto publish date
Rmd 34b1d9e Jovan Tanevski 2021-06-15 explicit codex, merfish and exseq
html e445e6f Jovan Tanevski 2021-06-11 Build site.
Rmd abca833 Jovan Tanevski 2021-06-11 temporarily parametrize simple_misty
Rmd f532a05 Jovan Tanevski 2021-06-10 generalize analysis
html 56bbb48 Jovan Tanevski 2021-06-10 Build site.
Rmd 7c0f47e Jovan Tanevski 2021-06-10 wflow_publish(all = TRUE)
Rmd eb056ff Jovan Tanevski 2021-06-10 add simple misty analysis

Setup

library(reticulate)
library(mistyR)
library(future)
library(purrr)
library(stringr)

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

Extract counts and geometry

Requires python3 and anndata installed (pip install anndata).

import anndata

def read_and_extract(datapath):
  adata = anndata.read(datapath)
  counts = adata.obsm["counts"]
  geom = adata.obs[["x_orig", "y_orig"]]
  markers = adata.uns["counts_var"]
  return counts, geom, markers

Run misty

Define standard view composition and run MISTy on all h5ad files for modalities CODEX, MERFISH and ExSeq.

(list.files("data", ".h5ad", recursive = TRUE, full.names = TRUE) %>%
  keep(~ str_detect(.x, "(codex|merfish|exseq)_processed"))) %>%
  walk(function(datapath) {
    data <- py$read_and_extract(datapath)
    expr <- as.data.frame(as.matrix(data[[1]]))
    colnames(expr) <- make.names(data[[3]])
    pos <- data[[2]]

    unique(str_extract(rownames(pos), "-\\d$")) %>% walk(function(replicate) {
      output.folder <- paste0(
        str_replace(
          str_remove(datapath, ".h5ad"),
          "data", "output"
        ), replicate
      )
      
      output.folder.failed <- paste0(output.folder,"_failed")
      
      if(!(dir.exists(output.folder) | dir.exists(output.folder.failed))){
        ind <- str_which(rownames(pos), paste0(replicate, "$"))
        misty.views <- create_initial_view(expr[ind, ]) %>%
          add_juxtaview(pos[ind, ]) %>%
          add_paraview(pos[ind, ],100)
  
        tryCatch(
          run_misty(misty.views, results.folder = output.folder),
          error = function(e) file.rename(output.folder, output.folder.failed)
        )
      }
    })
  })

sessionInfo()
R version 4.1.0 (2021-05-18)
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.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] stringr_1.4.0   purrr_0.3.4     future_1.21.0   mistyR_1.1.2   
[5] reticulate_1.20 workflowr_1.6.2

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.7        pillar_1.6.1      compiler_4.1.0    bslib_0.2.5.1    
 [5] later_1.2.0       jquerylib_0.1.4   git2r_0.28.0      tools_4.1.0      
 [9] digest_0.6.27     jsonlite_1.7.2    evaluate_0.14     lifecycle_1.0.0  
[13] tibble_3.1.2      lattice_0.20-44   png_0.1-7         pkgconfig_2.0.3  
[17] rlang_0.4.11      Matrix_1.3-4      DBI_1.1.1         parallel_4.1.0   
[21] yaml_2.2.1        xfun_0.24         dplyr_1.0.7       knitr_1.33       
[25] globals_0.14.0    generics_0.1.0    fs_1.5.0          vctrs_0.3.8      
[29] sass_0.4.0        tidyselect_1.1.1  rprojroot_2.0.2   grid_4.1.0       
[33] glue_1.4.2        listenv_0.8.0     R6_2.5.0          parallelly_1.26.1
[37] fansi_0.5.0       rmarkdown_2.9     magrittr_2.0.1    whisker_0.4      
[41] codetools_0.2-18  promises_1.2.0.1  ellipsis_0.3.2    htmltools_0.5.1.1
[45] assertthat_0.2.1  httpuv_1.6.1      utf8_1.2.1        stringi_1.6.2    
[49] crayon_1.4.1