added combined lineage plot

This commit is contained in:
Tanushree Tunstall 2022-08-09 19:33:49 +01:00
parent fe292e3717
commit 94454d6fba
10 changed files with 421 additions and 190 deletions

View file

@ -61,9 +61,6 @@ scaled_cols_stab_revised = c(scaled_cols_stab_revised, "foldx_scaled_signC")
#=================
# PREFORMATTING: for consistency
#=================
df2$sensitivity = ifelse(df2$dst_mode == 1, "R", "S")
table(df2$sensitivity)
cols_to_extract = colnames(df2)[colnames(df2)%in%c(common_cols
, outcome_cols_stability
, raw_cols_stability
@ -102,33 +99,56 @@ df2_plot["ens_stab_new_scaled"] = lapply(df2_plot["ens_stab_new"]
)})
min(df2_plot['ens_stab_new']); max(df2_plot['ens_stab_new'])
foo = df2_plot[c("cols2avg_new", "ens_stab_new_scaled")]
foo = df2_plot[c("cols2avg_new", "ens_stab_new_scaled"),]
min(df2_plot['ens_stab_new_scaled']); max(df2_plot['ens_stab_new_scaled'])
###########################################################
nrow(df2_plot)
table(df2_plot$lineage)
table(df2_plot$lineage_labels)
#===============
#Quick numbers checks
#===============
nsample_lin = df2_plot[df2_plot$lineage%in%c("L1", "L2", "L3", "L4"),]
if ( all(table(nsample_lin$sensitivity)== table(nsample_lin$mutation_info_labels)) ){
cat("\nTotal no. of samples belonging to L1-l4 for", gene,":", nrow(nsample_lin)
, "\nCounting R and S samples")
if( sum(table(nsample_lin$sensitivity)) == nrow(nsample_lin) ){
cat("\nPASSNumbers cross checked:")
print(table(nsample_lin$sensitivity))
}
}else{
stop("Abort: Numbers mismatch. Please check")
}
#====================
# Output Lineage plot
#====================
nsample_lin = merged_df2[merged_df2$lineage%in%c("L1", "L2", "L3", "L4"),]
cat("\nTotal no. of samples belonging to L1-l4 for", gene,":", nrow(nsample_lin) )
linD_ens_stabP = paste0(outdir_images
, tolower(gene)
,"_linD_ens_stabP.svg")
my_xlabel = paste0("Average stability ", "(", stability_suffix, ")"); my_xlabel
cat("\nOutput plot:", linD_ens_stabP)
svg(linD_ens_stabP, width = 10, height = 10)
# linD_ens_stabP = paste0(outdir_images
# , tolower(gene)
# ,"_linD_ens_stabP.svg")
#
# cat("\nOutput plot:", linD_ens_stabP)
# svg(linD_ens_stabP, width = 10, height = 10)
linP_dm_om = lineage_distP(df2_plot
, with_facet = F
, x_axis = "ens_stab_new_scaled"
, y_axis = "lineage_labels"
, x_lab = "Average stability"
, x_lab = my_xlabel
, use_lineages = c("L1", "L2", "L3", "L4")
#, fill_categ = "mutation_info_orig", fill_categ_cols = c("#E69F00", "#999999")
, fill_categ = "sensitivity"
, fill_categ_cols = c("red", "blue")
, label_categories = c("Resistant", "Sensitive")
, leg_label = ""
, leg_label = "Mutation group"
, my_ats = 22 # axis text size
, my_als = 22 # axis label size
, my_leg_ts = 22
@ -138,4 +158,29 @@ linP_dm_om = lineage_distP(df2_plot
)
linP_dm_om
dev.off()
#dev.off()
###########################################
my_label_size = 25
linPlots_combined = paste0(outdir_images
, tolower(gene)
,"_linP_combined.svg")
cat("\nOutput plot:", linPlots_combined)
svg(linPlots_combined, width = 18, height = 12)
cowplot::plot_grid(
cowplot::plot_grid(lin_countP, lin_diversityP
, nrow = 2
# , ncols = 2
, labels = "AUTO"
, label_size = my_label_size),
NULL,
linP_dm_om,
nrow = 1,
labels = c("", "", "C"),
label_size = my_label_size,
rel_widths = c(35, 3, 52)
)
dev.off()