fixed cmd running script problem for logo plots

This commit is contained in:
Tanushree Tunstall 2021-06-24 12:12:36 +01:00
parent 552c5e77aa
commit ca2315523d
14 changed files with 206 additions and 748 deletions

66
scripts/plotting/logo_combined.R Normal file → Executable file
View file

@ -16,8 +16,32 @@ source("../functions/combining_dfs_plotting.R")
###########################################################
# command line args
#********************
drug = 'streptomycin'
gene = 'gid'
#drug = 'streptomycin'
#gene = 'gid'
#********************
# !!!FUTURE TODO!!!
# Can pass additional params of output/plot dir by user.
# Not strictly required for my workflow since it is optimised
# to have a streamlined input/output flow without filename worries.
#********************
spec = matrix(c(
"drug" , "d", 1, "character",
"gene" , "g", 1, "character",
"data_file1" , "fa", 2, "character",
"data_file2" , "fb", 2, "character"
), byrow = TRUE, ncol = 4)
opt = getopt(spec)
#FIXME: detect if script running from cmd, then set these
drug = opt$drug
gene = opt$gene
infile_params = opt$data_file1
infile_metadata = opt$data_file2
if(is.null(drug)|is.null(gene)) {
stop("Missing arguments: --drug and --gene must both be specified (case-sensitive)")
}
#===========
# input
@ -25,13 +49,13 @@ gene = 'gid'
#---------------------
# call: import_dirs()
#---------------------
import_dirs(drug, gene)
import_dirs(drug_name = drug, gene_name = gene)
#---------------------------
# call: plotting_data()
#---------------------------
if (!exists("infile_params") && exists("gene")){
#if (!is.character(infile_params) && exists("gene")){
#if (!exists("infile_params") && exists("gene")){
if (!is.character(infile_params) && exists("gene")){ # when running as cmd
#in_filename_params = paste0(tolower(gene), "_all_params.csv")
in_filename_params = paste0(tolower(gene), "_comb_afor.csv") # part combined for gid
infile_params = paste0(outdir, "/", in_filename_params)
@ -39,21 +63,23 @@ if (!exists("infile_params") && exists("gene")){
}
# Input 1: read <gene>_comb_afor.csv
pd_df = plotting_data(infile_params)
my_df_u = pd_df[[1]] # this forms one of the input for combining_dfs_plotting()
cat("\nReading mcsm combined data file: ", infile_params)
mcsm_df = read.csv(infile_params, header = T)
pd_df = plotting_data(mcsm_df)
my_df_u = pd_df[[2]]
#--------------------------------
# call: combining_dfs_plotting()
#--------------------------------
if (!exists("infile_metadata") && exists("gene")){
#if (!is.character(infile_params) && exists("gene")){{
#if (!exists("infile_metadata") && exists("gene")){
if (!is.character(infile_metadata) && exists("gene")){ # when running as cmd
in_filename_metadata = paste0(tolower(gene), "_metadata.csv") # part combined for gid
infile_metadata = paste0(outdir, "/", in_filename_metadata)
cat("\nInput file for gene metadata not specified, assuming filename: ", infile_metadata, "\n")
}
# Input 2: read <gene>_meta data.csv
cat("\nReading meta data file:", infile_metadata)
cat("\nReading meta data file: ", infile_metadata)
gene_metadata <- read.csv(infile_metadata
, stringsAsFactors = F
@ -64,12 +90,8 @@ all_plot_dfs = combining_dfs_plotting(my_df_u
, lig_dist_colname = 'ligand_distance'
, lig_dist_cutoff = 10)
#merged_df2 = all_plot_dfs[[1]]
merged_df3 = all_plot_dfs[[2]]
#merged_df2_comp = all_plot_dfs[[3]]
#merged_df3_comp = all_plot_dfs[[4]]
#merged_df2_lig = all_plot_dfs[[5]]
#merged_df3_lig = all_plot_dfs[[6]]
merged_df3 = all_plot_dfs[[2]]
#===========
# output
#===========
@ -157,7 +179,7 @@ p0 = ggseqlogo(tab_mt
, limits = c(0, max_mult_mut))
p0
#p0
# further customisation
p1 = p0 + theme(axis.text.x = element_text(size = 16
@ -167,7 +189,7 @@ p1 = p0 + theme(axis.text.x = element_text(size = 16
, axis.text.y = element_blank()
, legend.position = "none")
#, axis.text.y = element_text(size = 20))
p1
#p1
#==============
# matrix for wild type
@ -204,7 +226,7 @@ p2 = ggseqlogo(tab_wt
#theme_logo() +
scale_x_discrete(breaks = 1:ncol(tab_wt)
, labels = colnames(tab_wt))
p2
#p2
# further customise
p3 = p2 +
@ -219,7 +241,7 @@ p3 = p2 +
labs(x= "Wild-type Position")
p3
#p3
#======================================================================
# logo with OR
#=======================================================================
@ -302,7 +324,7 @@ logo_or = ggseqlogo(wide_df_or, method="custom", seq_type="aa") + ylab("my custo
xlab("Position") +
ylab("Odds Ratio")
logo_or
#logo_or
########################################################################
#=============================
@ -321,4 +343,4 @@ OutPlot2 = cowplot::plot_grid(logo_or, p1, p3
, label_size = 25)
print(OutPlot2)
dev.off()
#dev.off()