Last updated: 2021-10-28

Checks: 7 0

Knit directory: Multispectral HCC/

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(20210728) 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 182f85e. 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:    NMF_26ce5dfd0cab/
    Ignored:    analysis/.DS_Store
    Ignored:    code/
    Ignored:    data/
    Ignored:    old/
    Ignored:    output/.DS_Store
    Ignored:    output/tumor.hc.nmf.rank.1.rds
    Ignored:    output/tumor.hc.nmf.rank.10.rds
    Ignored:    output/tumor.hc.umap.rds

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/misty.Rmd) and HTML (docs/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 434cb0d Jovan Tanevski 2021-10-27 Build site.
html 668b155 Jovan Tanevski 2021-10-27 Build site.
Rmd e4ef937 Jovan Tanevski 2021-10-27 remove beta-cat from misty, update par
html 68cbc32 Jovan Tanevski 2021-10-08 Build site.
Rmd db035f5 Jovan Tanevski 2021-10-08 add misty analysis on tumor hepatocytes

Setup

library(mistyR)
library(future)
library(tidyverse)
library(skimr)

plan(multisession(workers = 6))
data <- read_csv("data/tumor_hepatocytes.csv", col_types = cols())

tumor.hc <- data %>%
  select(
    `Cytoplasm AGS (Opal 690) Mean (Normalized Counts, Total Weighting)`,
    `Cytoplasm BerEP4 (Opal 650) Mean (Normalized Counts, Total Weighting)`,
    `Cytoplasm CRP (Opal 540) Mean (Normalized Counts, Total Weighting)`,
    `Nucleus p-S6 (Opal 570) Mean (Normalized Counts, Total Weighting)`,
#    `Nucleus beta-cat. (Opal 520) Mean (Normalized Counts, Total Weighting)`
  ) %>%
  `colnames<-`(str_split(colnames(.), " ") %>%
    map_chr(~ .x[2]) %>%
    make.names())
skim(tumor.hc)
Data summary
Name tumor.hc
Number of rows 223846
Number of columns 4
_______________________
Column type frequency:
numeric 4
________________________
Group variables None

Variable type: numeric

skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist
AGS 0 1 0.27 0.41 0 0.07 0.12 0.25 5.23 ▇▁▁▁▁
BerEP4 0 1 1.09 2.19 0 0.21 0.32 0.58 24.08 ▇▁▁▁▁
CRP 0 1 2.51 3.08 0 0.55 1.00 3.50 35.80 ▇▁▁▁▁
p.S6 0 1 1.31 1.25 0 0.58 0.94 1.61 35.24 ▇▁▁▁▁

Run MISTy

data %>%
  select(`Sample Name`, `Cell X Position`, `Cell Y Position`) %>%
  `colnames<-`(c("Sample", "X", "Y")) %>%
  bind_cols(tumor.hc) %>%
  group_by(Sample) %>%
  group_walk(\(subset, key){
    patient <- str_extract(key %>% pull(Sample), "[0-9]+_[0-9]+")
    output.folder <- paste0("output/misty/", patient)

    if (file.exists(output.folder) | 
        file.exists(paste0(output.folder, "_failed"))) {
      return()
    }

    expr <- subset %>% 
      select(-c(X, Y)) %>%
      select(where(~!(sd(.x) == 0 | length(unique(.x)) < 3)))
    pos <- subset %>% select(X, Y)
    misty.views <- create_initial_view(expr) %>%
      add_juxtaview(pos, 25) %>%
      add_paraview(pos, 150, 25)

    tryCatch(
      run_misty(misty.views, output.folder, cv = 3),
      error = function(e) {
        file.rename(
          output.folder,
          paste0(output.folder, "_failed")
        )
      }
    )
  })

Collect and browse results

misty.results <- collect_results(list.dirs("output/misty")[-1])

Collecting improvements

Collecting contributions

Collecting importances

Aggregating
misty.results %>% 
  plot_improvement_stats("intra.R2") %>%
  plot_improvement_stats() %>% 
  plot_view_contributions()

Version Author Date
668b155 Jovan Tanevski 2021-10-27
68cbc32 Jovan Tanevski 2021-10-08

Version Author Date
668b155 Jovan Tanevski 2021-10-27
68cbc32 Jovan Tanevski 2021-10-08

Version Author Date
668b155 Jovan Tanevski 2021-10-27
68cbc32 Jovan Tanevski 2021-10-08
misty.results %>% 
  plot_interaction_heatmap("intra", 0) %>%
  plot_interaction_heatmap("juxta.25", 0) %>% 
  plot_interaction_heatmap("para.150", 0)

Version Author Date
668b155 Jovan Tanevski 2021-10-27
68cbc32 Jovan Tanevski 2021-10-08

Version Author Date
668b155 Jovan Tanevski 2021-10-27
68cbc32 Jovan Tanevski 2021-10-08

Version Author Date
668b155 Jovan Tanevski 2021-10-27
68cbc32 Jovan Tanevski 2021-10-08

Signature analysis

sig <- misty.results %>% 
  extract_signature("performance") %>% 
  mutate(sample = str_extract(sample, "[0-9]+_[0-9]+"))

sig.pca <- prcomp(sig %>% select(-sample))$x %>% 
  data.frame() %>% 
  bind_cols(sig %>% select(sample))

ggplot(sig.pca, aes(x = PC1, y = PC2, color = sample)) + 
  geom_point() + 
  theme_classic()

Version Author Date
668b155 Jovan Tanevski 2021-10-27
68cbc32 Jovan Tanevski 2021-10-08

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] skimr_2.1.3     forcats_0.5.1   stringr_1.4.0   dplyr_1.0.7    
 [5] purrr_0.3.4     readr_2.0.2     tidyr_1.1.4     tibble_3.1.5   
 [9] ggplot2_3.3.5   tidyverse_1.3.1 future_1.22.1   mistyR_1.1.14  
[13] workflowr_1.6.2

loaded via a namespace (and not attached):
 [1] fs_1.5.0           lubridate_1.8.0    bit64_4.0.5        RColorBrewer_1.1-2
 [5] httr_1.4.2         rprojroot_2.0.2    repr_1.1.3         tools_4.1.1       
 [9] backports_1.3.0    bslib_0.3.1        utf8_1.2.2         R6_2.5.1          
[13] DBI_1.1.1          colorspace_2.0-2   withr_2.4.2        tidyselect_1.1.1  
[17] bit_4.0.4          compiler_4.1.1     git2r_0.28.0       cli_3.0.1         
[21] rvest_1.0.2        xml2_1.3.2         labeling_0.4.2     sass_0.4.0        
[25] scales_1.1.1       digest_0.6.28      rmarkdown_2.11     R.utils_2.11.0    
[29] base64enc_0.1-3    pkgconfig_2.0.3    htmltools_0.5.2    parallelly_1.28.1 
[33] dbplyr_2.1.1       fastmap_1.1.0      highr_0.9          rlang_0.4.12      
[37] readxl_1.3.1       rstudioapi_0.13    jquerylib_0.1.4    generics_0.1.1    
[41] farver_2.1.0       jsonlite_1.7.2     vroom_1.5.5        R.oo_1.24.0       
[45] magrittr_2.0.1     Rcpp_1.0.7         munsell_0.5.0      fansi_0.5.0       
[49] lifecycle_1.0.1    R.methodsS3_1.8.1  furrr_0.2.3        stringi_1.7.5     
[53] whisker_0.4        yaml_2.2.1         grid_4.1.1         parallel_4.1.1    
[57] listenv_0.8.0      promises_1.2.0.1   crayon_1.4.1       haven_2.4.3       
[61] hms_1.1.1          knitr_1.36         pillar_1.6.4       codetools_0.2-18  
[65] reprex_2.0.1       glue_1.4.2         evaluate_0.14      modelr_0.1.8      
[69] vctrs_0.3.8        tzdb_0.1.2         httpuv_1.6.3       cellranger_1.1.0  
[73] gtable_0.3.0       assertthat_0.2.1   xfun_0.27          broom_0.7.9       
[77] later_1.3.0        globals_0.14.0     ellipsis_0.3.2