plot cell frequency of unsorted CITEseq data

Generate Figure 5A; Figure S2A, S2B, S2C

Take interested populations from statistical model test and plot together

set1 as days_since_onset, set2 as PC1class, set3 for heatmap

main_set1 = c("B_Mem_IgMneg", "B_CD71_gated",
              "CD8_Mem_Activated","NK","Mono_Classical", 
              "Mono_Classical_CD163hi", "Mono_NonClassical")
sup_set1 = c("Plasmablast_gated", "PB_Plasmablasts_MHCIhi", 
             "CD4_Mem_CM", "CD4_Mem_CD69pos", "Tfh_gated", "Treg_gated",
             "CD8_Mem_NKT", "CD8_Mem_EM.TE", "CD8_Naive_KLRG1pos ", "gammadeltaT", 
             "NK_CD56loCD16lo", "Mono", "cDC", "pDC", "Platelets")
main_set2 = c("CD4_Mem_CM", "CD8_Mem_CM.TM", 
              "gammadeltaT","MAIT","Mono_NonClassical", "pDC", "cDC", "Platelets")
sup_set2 = c( "B_Mem_CD11cpos", "B_CD71_gated", "Plasmablast_gated",
              "PB_Plasmablasts_MHCIhi","CD4_Mem", "CD4_Naive",
              "CD4_Mem_Activated.CD38.CD278hi", "Tfh_gated", "Treg_gated", 
              "CD8_Mem", "CD8_Mem_Activated", "gammadeltaT_CD158e1hi",
              "Mono_Classical_IgPos", "Mono_Classical_CD163hi")

# read final list data in
final_cell_freq_UnSort_mtx <- read.csv("input/final_full_cell_freq_UnSort_mtx.20200818.csv",
                                       header = TRUE, row.names = 1, check.names = FALSE)
colnames(final_cell_freq_UnSort_mtx) <- str_replace(colnames(final_cell_freq_UnSort_mtx), 
                                                    pattern = "_to_parent", replacement = "")
final_cell_freq_UnSort_mtx$PC1class <- factor(final_cell_freq_UnSort_mtx$PC1class, levels = c("HC","PC1_low","PC1_high"))
# remove technical controls
final_cell_freq_UnSort_mtx <- final_cell_freq_UnSort_mtx %>% filter(Subject != "CHI014")

set1 Fig5

final_cell_freq_UnSort_mtx_main_set1 <- select(final_cell_freq_UnSort_mtx, all_of(main_set1),
                                               colnames(final_cell_freq_UnSort_mtx)[1:10])
final_cell_freq_UnSort_main_set1 <- final_cell_freq_UnSort_mtx_main_set1 %>% 
  melt(id = c("Var1", "Timepoint", "sample_id", "Batch", "severity", 
              "days_since_symptoms_onset","PC1","PC1class","Subject","severity_outcome")) 

p <- plot5cat(final_cell_freq_UnSort_main_set1, "Fig5.main", "all.set1", width = 7.5, height = 5)
# plot timecourse here
p[[3]]

set2 Fig2S

final_cell_freq_UnSort_mtx_main_set2 <- select(final_cell_freq_UnSort_mtx, all_of(main_set2),
                                               colnames(final_cell_freq_UnSort_mtx)[1:10])
final_cell_freq_UnSort_main_set2 <- final_cell_freq_UnSort_mtx_main_set2 %>% 
  melt(id = c("Var1", "Timepoint", "sample_id", "Batch", "severity", 
              "days_since_symptoms_onset","PC1","PC1class","Subject","severity_outcome")) 

p <- plot5cat(final_cell_freq_UnSort_main_set2, "Fig2.main", "all.set2", width = 7, height = 5)
# plot PC1/DSM group here
p[[4]]

heatmap of cell subsets

# removed 3-"CD4_Mem_Activated.CD38.CD278hi", 34-"Tcell, 31-"DPT", 33 - "Granulocytes", 26 - "RBC" which are too small or batch specific
main_set3 = unique(c(main_set1, main_set2, "Mono_NonClassical", "B_Naive", "Mono_Classical",
                     "NK_CD16hi","B_Mem","gammadeltaT","NK_CD56loCD16lo","Treg",
                     "CD4_Mem","CD8_Mem","CD8_Naive","CD4_Naive","MAIT","pDC","cDC",
                     "TissueResMemT","Platelets","NK_CD56hiCD16lo","DNT",
                     "CD4", "CD8","CD19","NK","Mono","TCRVbeta13.1pos","Mono_Intermediate",
                     "B_CD71_gated", "Plasmablast_gated", "Tfh_gated", 
                     "Treg_gated", "B_Mem_CD11cpos"))
fig2_cells <- select(final_cell_freq_UnSort_mtx, colnames(final_cell_freq_UnSort_mtx)[1:10],
                     intersect(main_set3, colnames(final_cell_freq_UnSort_mtx)))

fig2_cells_PC1 <- fig2_cells %>% filter(!is.na(PC1class), Timepoint %in% c("HC","T0"))
fig2_cells_PC1_mtx <- fig2_cells_PC1 %>% 
 mutate(PC1class = factor(PC1class, levels = c("HC", "PC1_low", "PC1_high"))) %>%
 arrange(PC1class, PC1) %>%
 select(-c("TCRVbeta13.1pos", "Treg"))

# change column names -- set HC
fig2_cells_PC1_mtx_hm <- t(fig2_cells_PC1_mtx[,c(11:ncol(fig2_cells_PC1_mtx))])
colnames(fig2_cells_PC1_mtx_hm) <- replace(as.character(fig2_cells_PC1_mtx$Subject), 
                                           fig2_cells_PC1_mtx$Timepoint == "HC" & fig2_cells_PC1_mtx$Subject != "CHI014", paste("HC", seq_along(1:13), sep = ""))
fig2_cells_PC1_mtx$colgroup = as.character(fig2_cells_PC1_mtx$PC1class)

fig2_cells_PC1_mtx$colgroup = factor(fig2_cells_PC1_mtx$colgroup, levels = c("HC", "PC1_low", "PC1_high"))

# use complexheatmap
severity.color <- c("Critical_Alive"="#374E55FF","Critical_Deceased"="#DF8F44FF","Moderate_Alive"="#00A1D5FF","Severe_Alive"="#B24745FF","HC_HC" = "#79AF97FF")
PC1.color <- colorRamp2(c(-3, 3.6), c("white", "#e97171"))
PC1class.color <- c("HC"="#00BA38", "PC1_low"="#619CFF", "PC1_high"="#F8766D")

ha = HeatmapAnnotation(
  PC1class = fig2_cells_PC1_mtx$PC1class,
  PC1 = fig2_cells_PC1_mtx$PC1, 
  severity_outcome = factor(fig2_cells_PC1_mtx$severity_outcome, 
                            levels = c("HC_HC", "Moderate_Alive", "Severe_Alive", "Critical_Alive", "Critical_Deceased")),
  col = list(PC1 = PC1.color,
             PC1class = PC1class.color,
             severity_outcome = severity.color)
)


# pdf("output/Fig2.celltypecor.cluster.pdf", width = 10, height = 6.5)
Heatmap(pheatmap:::scale_rows(fig2_cells_PC1_mtx_hm), name = "cell_freq_zscore", 
        show_column_names = TRUE, column_names_rot = 45,
        top_annotation = ha, cluster_columns = FALSE,
        column_split = fig2_cells_PC1_mtx$colgroup,
        column_gap = unit(1.5, "mm"),
        row_names_gp = gpar(fontsize = 10.5),
        column_names_gp = gpar(fontsize = 8)
)

# dev.off()
sI <- sessionInfo()
utils:::print.sessionInfo(sI[-c(10,11)])
## R version 3.6.2 (2019-12-12)
## Platform: x86_64-apple-darwin15.6.0 (64-bit)
## Running under: macOS Mojave 10.14.6
## 
## Matrix products: default
## 
## 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] grid      stats     graphics  grDevices utils     datasets  methods  
## [8] base     
## 
## other attached packages:
##  [1] circlize_0.4.8       ComplexHeatmap_2.2.0 reshape2_1.4.3      
##  [4] openxlsx_4.1.4       forcats_0.4.0        stringr_1.4.0       
##  [7] dplyr_0.8.4          purrr_0.3.3          readr_1.3.1         
## [10] tidyr_1.0.2          tibble_3.0.3         ggplot2_3.3.2       
## [13] tidyverse_1.3.0      plyr_1.8.5           matrixStats_0.55.0  
## [16] Seurat_3.1.4        
## 
## loaded via a namespace (and not attached):
##   [1] readxl_1.3.1        backports_1.1.5     sn_1.5-5           
##   [4] igraph_1.2.4.2      lazyeval_0.2.2      splines_3.6.2      
##   [7] listenv_0.8.0       TH.data_1.0-10      digest_0.6.25      
##  [10] htmltools_0.4.0     gdata_2.18.0        fansi_0.4.1        
##  [13] magrittr_1.5        cluster_2.1.0       ROCR_1.0-7         
##  [16] globals_0.12.5      modelr_0.1.6        RcppParallel_4.4.4 
##  [19] sandwich_2.5-1      colorspace_1.4-1    rvest_0.3.5        
##  [22] ggrepel_0.8.1       haven_2.2.0         xfun_0.12          
##  [25] crayon_1.3.4        jsonlite_1.6.1      survival_3.1-8     
##  [28] zoo_1.8-7           ape_5.3             glue_1.3.1         
##  [31] gtable_0.3.0        leiden_0.3.3        GetoptLong_0.1.8   
##  [34] shape_1.4.4         future.apply_1.4.0  BiocGenerics_0.32.0
##  [37] scales_1.1.0        pheatmap_1.0.12     mvtnorm_1.1-0      
##  [40] DBI_1.1.0           bibtex_0.4.2.2      Rcpp_1.0.3         
##  [43] metap_1.3           plotrix_3.7-7       viridisLite_0.3.0  
##  [46] clue_0.3-57         reticulate_1.14     rsvd_1.0.3         
##  [49] stats4_3.6.2        tsne_0.1-3          htmlwidgets_1.5.1  
##  [52] httr_1.4.1          gplots_3.0.3        RColorBrewer_1.1-2 
##  [55] TFisher_0.2.0       ellipsis_0.3.0      ica_1.0-2          
##  [58] farver_2.0.3        pkgconfig_2.0.3     uwot_0.1.5         
##  [61] dbplyr_1.4.2        labeling_0.3        tidyselect_1.0.0   
##  [64] rlang_0.4.7         munsell_0.5.0       cellranger_1.1.0   
##  [67] tools_3.6.2         cli_2.0.2           generics_0.0.2     
##  [70] broom_0.7.0         ggridges_0.5.2      evaluate_0.14      
##  [73] yaml_2.2.1          npsurv_0.4-0        knitr_1.28         
##  [76] fs_1.3.1            fitdistrplus_1.0-14 zip_2.0.4          
##  [79] caTools_1.18.0      RANN_2.6.1          pbapply_1.4-2      
##  [82] future_1.16.0       nlme_3.1-144        xml2_1.2.2         
##  [85] compiler_3.6.2      rstudioapi_0.11     plotly_4.9.2       
##  [88] png_0.1-7           lsei_1.2-0          reprex_0.3.0       
##  [91] stringi_1.4.6       lattice_0.20-40     Matrix_1.2-18      
##  [94] multtest_2.42.0     vctrs_0.3.4         mutoss_0.1-12      
##  [97] pillar_1.4.3        lifecycle_0.2.0     Rdpack_0.11-1      
## [100] lmtest_0.9-37       GlobalOptions_0.1.1 RcppAnnoy_0.0.15   
## [103] data.table_1.12.8   cowplot_1.0.0       bitops_1.0-6       
## [106] irlba_2.3.3         gbRd_0.4-11         patchwork_1.0.0    
## [109] R6_2.4.1            KernSmooth_2.23-16  gridExtra_2.3      
## [112] codetools_0.2-16    MASS_7.3-51.5       gtools_3.8.1       
## [115] assertthat_0.2.1    rjson_0.2.20        withr_2.1.2        
## [118] sctransform_0.2.1   mnormt_1.5-6        multcomp_1.4-12    
## [121] mgcv_1.8-31         parallel_3.6.2      hms_0.5.3          
## [124] rmarkdown_2.1       Rtsne_0.15          numDeriv_2016.8-1.1
## [127] Biobase_2.46.0      lubridate_1.7.4