Sample collection timeline and treatment info for the 33 citeseq patients.
batch.subjects <- unique(subset(covid19.samples,!is.na(batch))$subject_id)
batch.samples <- subset(covid19.samples,material_type == "PBMC" & subject_id %in% batch.subjects)
batch.samples <- batch.samples[order(batch.samples$days_from_admission_to_sample_drawn),]
batch.samples$severity.outcome <- paste0(batch.samples$severity,"-",batch.samples$outcome)
severity.color <- ggsci::pal_jama()(length(unique(batch.samples$severity.outcome)))
names(severity.color) <- sort(unique(batch.samples$severity.outcome))
# plot timeline of all batch PBMC samples
patients.without.symptom.onset <- unique(subset(batch.samples,is.na(days_from_symptom_onset_to_sample_drawn))$subject_id)
# replace NA with 0
batch.samples[is.na(batch.samples$days_from_symptom_onset_to_sample_drawn),"days_from_symptom_onset_to_sample_drawn"] <-
batch.samples[is.na(batch.samples$days_from_symptom_onset_to_sample_drawn),"days_from_admission_to_sample_drawn"]
batch.samples[is.na(batch.samples$days_from_symptom_onset_to_hospitalization),"days_from_symptom_onset_to_hospitalization"] <- 0
batch.samples[is.na(batch.samples$number_of_days_hospitalized),"number_of_days_hospitalized"] <-
batch.samples[is.na(batch.samples$number_of_days_hospitalized),"days_from_hospitalization_to_death"]
batch.samples <- batch.samples[order(batch.samples$days_from_symptom_onset_to_hospitalization,decreasing = F),]
batch.subject.ordered.by.admission <- batch.samples[,c("subject_id","age","sex")]
batch.subject.ordered.by.admission <- batch.subject.ordered.by.admission[!duplicated(batch.subject.ordered.by.admission$subject_id),]
#batch.subject.ordered.by.admission$subject_id_alt <- paste0("Pt",sprintf("%02d",1:nrow(batch.subject.ordered.by.admission))," (",
# batch.subject.ordered.by.admission$age,batch.subject.ordered.by.admission$sex,")")
batch.subject.ordered.by.admission$subject_id_alt <- paste0(gsub("^HGR0000","P",batch.subject.ordered.by.admission$subject_id)," (",
batch.subject.ordered.by.admission$age,batch.subject.ordered.by.admission$sex,")")
rownames(batch.subject.ordered.by.admission) <- batch.subject.ordered.by.admission$subject_id
batch.subject.ordered.by.admission$subject_id_alt <- factor(batch.subject.ordered.by.admission$subject_id_alt,
levels = rev(batch.subject.ordered.by.admission$subject_id_alt))
batch.samples$subject_id_alt <- batch.subject.ordered.by.admission[batch.samples$subject_id,"subject_id_alt"]
# sample distribution
tso.dist <- hist(batch.samples$days_from_symptom_onset_to_sample_drawn,breaks = seq(0,51,3),plot = F)
ggplot(data.frame(x=tso.dist$mids,count=tso.dist$counts),aes(x,count)) +
geom_bar(stat="identity",fill="#00BFC4", color="white", alpha = 0.6) + xlab("days since symptom onset") + ylab("Sample Count") +
theme_classic() + theme(text=element_text(size=6))
# move T1 to T0 for those without T0
#batch.samples[batch.samples$subject_id %in% setdiff(batch.subjects,subset(batch.samples,visit == "T0")$subject_id),"visit"] <- "T0"
# subjects whose first sample was >= 30 days since symptom onset
late.subjects <- batch.samples[!duplicated(batch.samples$subject_id) & batch.samples$days_from_symptom_onset_to_sample_drawn >= 30,"subject_id_alt"]
ggplot(batch.samples,aes(subject_id_alt,days_from_symptom_onset_to_sample_drawn,label=visit)) +
geom_vline(xintercept = batch.subject.ordered.by.admission[patients.without.symptom.onset,"subject_id_alt"],size=4,color="#66a182",alpha=0.3) +
geom_vline(xintercept = late.subjects,size=4,color="grey90",alpha=0.75) +
geom_hline(yintercept = 0,linetype="dashed",color="red") +
geom_rect(size=2,alpha=0.5,fill="white",aes(color=severity.outcome,xmin=subject_id_alt,xmax=subject_id_alt,
ymin=days_from_symptom_onset_to_hospitalization,ymax=days_from_symptom_onset_to_hospitalization + number_of_days_hospitalized)) +
geom_label(data=subset(batch.samples,!is.na(batch)),size=1.5,fontface="bold",color="white",aes(fill=visit),label.padding = unit(.15,"lines")) +
geom_label(data=subset(batch.samples,is.na(batch)),size=1.5,fontface="bold",aes(fill=visit,alpha=.9),label.padding = unit(.15,"lines")) +
coord_flip() + theme_bw() + scale_fill_npg(name="Time Point",guide=guide_legend(title.position = "top")) +
scale_color_jama(name="Severity",guide=guide_legend(title.position = "top")) +
scale_alpha_continuous(name="QC",labels=c("Excluded"),range = c(.9,1),guide=guide_legend(title.position = "top")) +
ylab("Days since Symptom Onset") + xlab("") + #ggtitle("Sample Collection Timeline") +
theme(text=element_text(size=10),legend.position = "bottom",legend.box = "vertical",legend.text = element_text(size=6))
# treatment
selected.treatment <- subset(covid19.treatment,subject_id %in% batch.samples$subject_id)
# add earliest sample time points
selected.treatment <- merge(selected.treatment,batch.samples[!duplicated(batch.samples$subject_id),
c("subject_id","days_from_admission_to_sample_drawn","severity.outcome")],by="subject_id")
selected.treatment$days_between_admission_and_earliest_sample <- selected.treatment$days_from_admission_to_sample_drawn
# fill in missing values
selected.treatment$missing.dates <- is.na(selected.treatment$days_from_admission_to_treatment_start) |
is.na(selected.treatment$days_from_admission_to_treatment_end)
y.min <- as.numeric(min(c(-selected.treatment$days_from_symptom_onset_to_hospitalization,selected.treatment$days_from_admission_to_treatment_start),na.rm = T))
selected.treatment[is.na(selected.treatment$days_from_admission_to_treatment_start),"days_from_admission_to_treatment_start"] <- y.min
y.max <- as.numeric(max(c(selected.treatment$days_between_admission_and_earliest_sample,selected.treatment$days_from_admission_to_treatment_end),na.rm = T))
selected.treatment[is.na(selected.treatment$days_from_admission_to_treatment_end),"days_from_admission_to_treatment_end"] <- y.max
selected.treatment$treatment_id <- 1:nrow(selected.treatment)
selected.treatment <- reshape2::melt(selected.treatment,measure.vars = c("days_from_admission_to_treatment_start","days_from_admission_to_treatment_end"))
selected.treatment$subject_id_alt <- factor(batch.subject.ordered.by.admission[selected.treatment$subject_id,"subject_id_alt"],
levels=batch.subject.ordered.by.admission$subject_id_alt)
# convert rare categories to Others
selected.treatment[selected.treatment$treatment_category %in% c("Heart Medications","Neuro Drugs","Antifungal Therapy"),"treatment_category"] <- "Other"
selected.treatment$subject_id_alt <- as.character(selected.treatment$subject_id_alt)
selected.treatment <- unique(selected.treatment[,-grep("treatment_notes",colnames(selected.treatment))]) # avoid duplicates
selected.treatment <- selected.treatment[grep("Mask",selected.treatment$treatment_label,invert = T),]
selected.treatment$treatment_category <- factor(selected.treatment$treatment_category,
levels = c(sort(setdiff(unique(selected.treatment$treatment_category),"Other")),"Other"))
selected.treatment$treatment_category_label <- paste0(as.numeric(selected.treatment$treatment_category),": ",selected.treatment$treatment_label)
selected.treatment$treatment_category <- paste0(as.numeric(selected.treatment$treatment_category),". ",selected.treatment$treatment_category)
# color subjects by severity group
subject.color <- unique(selected.treatment[,c("subject_id_alt","severity.outcome")])
subject.color <- severity.color[subject.color$severity.outcome]
ggplot(selected.treatment,
aes(y=value,x=subject_id_alt,color=treatment_category_label,shape=outcome,fill=severity.outcome)) +
geom_hline(yintercept = 0,color="grey60",linetype="dotted") +
geom_line(data=subset(selected.treatment,missing.dates==T),alpha=0.5,position = position_dodge(width=0.75),size=1,linetype="dashed") +
geom_line(data=subset(selected.treatment,missing.dates==F),size=2,alpha=0.75,position = position_dodge(width=0.75)) +
geom_point(aes(y=days_between_admission_and_earliest_sample),color="black",pch=21,alpha=0.8,fill=NA) +
geom_point(aes(y=-days_from_symptom_onset_to_hospitalization),color="black",alpha=0.8) +
geom_point(aes(y=-days_from_symptom_onset_to_hospitalization),color="black",alpha=0.8,pch=16) + # just to cover the colors
facet_grid(~treatment_category) + theme_bw() + coord_flip() + ylab("Days from Admission") + xlab("") + ggtitle("Subject Treatment Timeline") +
scale_fill_manual(name="Severity",values=severity.color,guide=guide_legend(override.aes = list(fill=severity.color,shape=22,color="white",size=4))) +
scale_shape_manual(name="Time Point",values=c(16,21),labels=c("Symptom Onset","1st Sample")) +
theme(legend.position = "bottom",legend.box = "vertical",axis.text.y=element_text(color=subject.color),text=element_text(size=8)) +
scale_color_manual(name="",values=rep(ggsci::pal_d3()(10),5))
sessionInfo()
## R version 3.6.3 (2020-02-29)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows 10 x64 (build 17763)
##
## Matrix products: default
##
## locale:
## [1] LC_COLLATE=English_United States.1252
## [2] LC_CTYPE=English_United States.1252
## [3] LC_MONETARY=English_United States.1252
## [4] LC_NUMERIC=C
## [5] LC_TIME=English_United States.1252
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] plsRglm_1.2.5 GGally_2.0.0 Hmisc_4.4-1 Formula_1.2-3
## [5] survival_3.1-8 lattice_0.20-38 ggfortify_0.4.10 ggpubr_0.4.0
## [9] ggsci_2.9 ggplot2_3.3.2 knitr_1.30
##
## loaded via a namespace (and not attached):
## [1] nlme_3.1-144 RColorBrewer_1.1-2 tools_3.6.3
## [4] backports_1.1.10 R6_2.4.1 vegan_2.5-6
## [7] rpart_4.1-15 mgcv_1.8-31 colorspace_1.4-1
## [10] permute_0.9-5 nnet_7.3-12 withr_2.3.0
## [13] tidyselect_1.1.0 gridExtra_2.3 curl_4.3
## [16] compiler_3.6.3 htmlTable_2.1.0 network_1.16.0
## [19] labeling_0.3 scales_1.1.1 checkmate_2.0.0
## [22] mvtnorm_1.1-1 stringr_1.4.0 digest_0.6.25
## [25] foreign_0.8-75 rmarkdown_2.4 rio_0.5.16
## [28] base64enc_0.1-3 jpeg_0.1-8.1 pkgconfig_2.0.3
## [31] htmltools_0.5.0 highr_0.8 maps_3.3.0
## [34] htmlwidgets_1.5.1 rlang_0.4.7 readxl_1.3.1
## [37] rstudioapi_0.11 farver_2.0.3 generics_0.0.2
## [40] statnet.common_4.3.0 dplyr_1.0.2 zip_2.1.1
## [43] car_3.0-10 magrittr_1.5 dotCall64_1.0-0
## [46] bipartite_2.15 Matrix_1.2-18 Rcpp_1.0.5
## [49] munsell_0.5.0 abind_1.4-5 lifecycle_0.2.0
## [52] stringi_1.4.6 yaml_2.2.1 carData_3.0-4
## [55] MASS_7.3-51.5 plyr_1.8.6 grid_3.6.3
## [58] parallel_3.6.3 forcats_0.5.0 crayon_1.3.4
## [61] haven_2.3.1 splines_3.6.3 hms_0.5.3
## [64] sna_2.5 pillar_1.4.6 igraph_1.2.5
## [67] boot_1.3-24 ggsignif_0.6.0 reshape2_1.4.4
## [70] glue_1.4.2 evaluate_0.14 latticeExtra_0.6-29
## [73] data.table_1.13.0 png_0.1-7 vctrs_0.3.4
## [76] spam_2.5-1 cellranger_1.1.0 gtable_0.3.0
## [79] purrr_0.3.4 tidyr_1.1.2 reshape_0.8.8
## [82] xfun_0.17 openxlsx_4.2.2 broom_0.7.0
## [85] coda_0.19-3 rstatix_0.6.0 tibble_3.0.3
## [88] fields_11.4 cluster_2.1.0 ellipsis_0.3.1