Last updated: 2020-07-08

Checks: 7 0

Knit directory: cytomapper_publication/

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(20200602) 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 b0e748f. 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:    data/PancreasData/.DS_Store
    Ignored:    data/PancreasData/pancreas_images.rds
    Ignored:    data/PancreasData/pancreas_masks.rds
    Ignored:    data/PancreasData/pancreas_sce.rds

Unstaged changes:
    Modified:   .gitignore
    Modified:   analysis/_site.yml
    Deleted:    analysis/about.Rmd
    Deleted:    analysis/license.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/03-Figure_4.Rmd) and HTML (docs/03-Figure_4.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
Rmd cb92024 nilseling 2020-07-03 Finalized Figure 4

This script reproduces the analysis performed in Figure 4. Here, we will load the libraries and data for this figure:

library(cytomapper)
library(dplyr)

sce <- readRDS("data/PancreasData/pancreas_sce.rds")
images <- readRDS("data/PancreasData/pancreas_images.rds")

Similar to Figure 3, we will now order the images based on the mean intensity of all PIN positive pixels.

PIN_mean <- unlist(lapply(images,
                   function(x){
                     cur_x <- x[,,"PIN"]
                     mean(cur_x[cur_x > 0])
                   }))

Here, we will visualize the marker pro-insulin (PIN) across all images. Due to the progressive decline in beta cell function, we expect PIN expression to be reduced in Long-Duration patients. However, a similar analysis can be performed to visually detect image-to-image irregularities in background stain.

We will normalize across all images to keep the differences in staining intensity between images intact.

# Specify the image order
cur_order <- order(PIN_mean, decreasing = TRUE)

# Collect metadata for images
cur_meta <- as_tibble(colData(sce)) %>%
  group_by(ImageNumber) %>%
  summarise_at(vars("ImageName", "ImageFullName", "stage"), unique) %>%
  mutate(ImageFullName = gsub(".tiff", "", ImageFullName)) %>%
  as.data.frame()

rownames(cur_meta) <- cur_meta$ImageFullName
cur_meta <- cur_meta[names(PIN_mean)[cur_order],]

images <- normalize(images)
images <- normalize(images, inputRange = c(0, 0.2))

plotPixels(image = images[cur_order],
          colour_by = "PIN",
          scale_bar = list(length = 100,
                           label = "",
                           colour = "white"),
          colour = list(PIN = c("black", "yellow")),
          legend = list(margin = 100,
                        colour_by.title.cex = 8,
                        colour_by.labels.cex = 4),
          image_title = list(text = cur_meta$stage,
                             colour = "white",
                             cex = 3))

# Save plot
plotPixels(image = images[cur_order],
          colour_by = "PIN",
          scale_bar = list(length = 100,
                           label = "",
                           colour = "white"),
          colour = list(PIN = c("black", "yellow")),
          legend = list(margin = 100,
                        colour_by.title.cex = 8,
                        colour_by.labels.cex = 4),
          image_title = list(text = cur_meta$stage,
                             colour = "white",
                             cex = 3),
          save_plot = list(filename = "docs/final_figures/main/Fig_4.png"))

Here, we see the progressive decline in beta cell fractions. The images are ordered based on T1D stage: Non-diabetic, Onset and Long-Duration, as expected. We further see an increased morphological irregularity in Long-Duration islets.


sessionInfo()
R version 4.0.0 (2020-04-24)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.5

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRblas.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/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] parallel  stats4    stats     graphics  grDevices utils     datasets 
[8] methods   base     

other attached packages:
 [1] dplyr_1.0.0                 cytomapper_1.1.1           
 [3] SingleCellExperiment_1.10.1 SummarizedExperiment_1.18.1
 [5] DelayedArray_0.14.0         matrixStats_0.56.0         
 [7] Biobase_2.48.0              GenomicRanges_1.40.0       
 [9] GenomeInfoDb_1.24.2         IRanges_2.22.2             
[11] S4Vectors_0.26.1            BiocGenerics_0.34.0        
[13] EBImage_4.30.0              workflowr_1.6.2            

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.4.6           locfit_1.5-9.4         lattice_0.20-41       
 [4] fftwtools_0.9-8        png_0.1-7              rprojroot_1.3-2       
 [7] digest_0.6.25          R6_2.4.1               tiff_0.1-5            
[10] backports_1.1.7        evaluate_0.14          ggplot2_3.3.1         
[13] pillar_1.4.4           zlibbioc_1.34.0        rlang_0.4.6           
[16] whisker_0.4            raster_3.1-5           Matrix_1.2-18         
[19] rmarkdown_2.2          stringr_1.4.0          htmlwidgets_1.5.1     
[22] RCurl_1.98-1.2         munsell_0.5.0          compiler_4.0.0        
[25] httpuv_1.5.4           xfun_0.14              pkgconfig_2.0.3       
[28] htmltools_0.4.0        tidyselect_1.1.0       gridExtra_2.3         
[31] tibble_3.0.1           GenomeInfoDbData_1.2.3 codetools_0.2-16      
[34] viridisLite_0.3.0      crayon_1.3.4           later_1.1.0.1         
[37] bitops_1.0-6           grid_4.0.0             gtable_0.3.0          
[40] lifecycle_0.2.0        git2r_0.27.1           magrittr_1.5          
[43] scales_1.1.1           stringi_1.4.6          XVector_0.28.0        
[46] viridis_0.5.1          fs_1.4.1               promises_1.1.1        
[49] sp_1.4-2               generics_0.0.2         ellipsis_0.3.1        
[52] vctrs_0.3.1            RColorBrewer_1.1-2     tools_4.0.0           
[55] glue_1.4.1             purrr_0.3.4            jpeg_0.1-8.1          
[58] abind_1.4-5            yaml_2.2.1             colorspace_1.4-1      
[61] knitr_1.28