diff --git a/scripts/plotting/basic_barplots_LIG.R b/scripts/plotting/basic_barplots_LIG.R index b235e3a..9b15944 100755 --- a/scripts/plotting/basic_barplots_LIG.R +++ b/scripts/plotting/basic_barplots_LIG.R @@ -3,25 +3,96 @@ # TASK: producing barplots # basic barplots with count of mutations # basic barplots with frequency of count of mutations + +# Depends on +## plotting_globals.R (previously dir.R) +## plotting_data.R ######################################################### -#======================================================================= -# working dir and loading libraries +# working dir getwd() setwd("~/git/LSHTM_analysis/scripts/plotting") getwd() +# load libraries #source("Header_TT.R") library(ggplot2) library(data.table) library(dplyr) -source("plotting_data.R") +require("getopt", quietly = TRUE) # cmd parse arguments -# should return the following dfs and directories +# load functions +source("plotting_globals.R") +source("plotting_data.R") +######################################################### +# command line args +#******************** +# !!!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" ,"f", 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 = opt$data + +# hardcoding when not using cmd +#drug = "streptomycin" +#gene = "gid" + +if(is.null(drug)|is.null(gene)) { + stop("Missing arguments: --drug and --gene must both be specified (case-sensitive)") +} +######################################################### +# call functions with relevant args + +#------------------------------------------ +# import_dirs() +# should return the follwoing variables: +# datadir +# indir +# outdir +# plotdir +# dr_muts_col +# other_muts_col +# resistance_col +#-------------------------------------------- +import_dirs(drug, gene) +#--------------------------------------------- +# plotting_data() +# should return the following dfs: # my_df # my_df_u # my_df_u_lig - # dup_muts +# dup_muts +#---------------------------------------------- +#infile = "/home/tanu/git/Data/streptomycin/output/gid_comb_stab_struc_params.csv" +#infile = "" +#if (!exists("infile") && exists("gene")){ +if (!is.character(infile) && exists("gene")){ + #in_filename_params = paste0(tolower(gene), "_all_params.csv") + in_filename_params = paste0(tolower(gene), "_comb_stab_struc_params.csv") # part combined for gid + infile = paste0(outdir, "/", in_filename_params) + cat("\nInput file not specified, assuming filename: ", infile, "\n") +} + +# Get the DFs out of plotting_data() +pd_df = plotting_data(infile) +my_df = pd_df[[1]] +my_df_u = pd_df[[2]] +my_df_u_lig = pd_df[[3]] +dup_muts = pd_df[[4]] + +######################################################### cat(paste0("Directories imported:" , "\ndatadir:", datadir , "\nindir:", indir @@ -30,24 +101,20 @@ cat(paste0("Directories imported:" cat(paste0("Variables imported:" , "\ndrug:", drug - , "\ngene:", gene - , "\ngene_match:", gene_match - , "\nLength of upos:", length(upos) - , "\nAngstrom symbol:", angstroms_symbol)) - -# clear excess variable -rm(my_df, upos, dup_muts, my_df_u) - + , "\ngene:", gene)) + #, "\ngene_match:", gene_match + #, "\nLength of upos:", length(upos) + #, "\nAngstrom symbol:", angstroms_symbol)) #======================================================================= #======= # output #======= # plot 1 -basic_bp_ligand = "basic_barplot_LIG.svg" +basic_bp_ligand = paste0(tolower(gene), "_basic_barplot_LIG.svg") plot_basic_bp_ligand = paste0(plotdir,"/", basic_bp_ligand) # plot 2 -pos_count_ligand = "position_count_LIG.svg" +pos_count_ligand = paste0(tolower(gene), "_position_count_LIG.svg") plot_pos_count_ligand = paste0(plotdir, "/", pos_count_ligand) #======================================================================= @@ -56,13 +123,12 @@ plot_pos_count_ligand = paste0(plotdir, "/", pos_count_ligand) #================ # REASSIGNMENT as necessary df = my_df_u_lig -rm(my_df_u, my_df, upos, dup_muts) # sanity checks str(df) #===================================================================== #**************** -# Plot 1:Count of stabilising and destabilsing muts +# Plot 1: Count of stabilising and destabilsing muts #**************** #svg("basic_barplots_LIG.svg") @@ -189,5 +255,4 @@ print(OutPlot_lig_pos_count) dev.off() ######################################################################## # end of LIG barplots -######################################################################## - +######################################################################## \ No newline at end of file diff --git a/scripts/plotting/basic_barplots_foldx.R b/scripts/plotting/basic_barplots_foldx.R index e3119c6..0200cce 100755 --- a/scripts/plotting/basic_barplots_foldx.R +++ b/scripts/plotting/basic_barplots_foldx.R @@ -110,7 +110,7 @@ cat(paste0("Directories imported:" # output #======= # plot 1 -basic_bp_foldx = "basic_barplot_foldx.svg" +basic_bp_foldx = paste0(tolower(gene), "_basic_barplot_foldx.svg") plot_basic_bp_foldx = paste0(plotdir,"/", basic_bp_foldx) #======================================================================= #================ diff --git a/scripts/plotting/running_plotting_scripts.txt b/scripts/plotting/running_plotting_scripts.txt index c15fdf0..949b7c6 100644 --- a/scripts/plotting/running_plotting_scripts.txt +++ b/scripts/plotting/running_plotting_scripts.txt @@ -26,4 +26,14 @@ resolving_ambiguous_muts.R:source("dirs.R") sources: ## plotting_globals.R (previously dir.R) ## plotting_data.R + +#======== +# basic_barplots_LIG.R: +#======== +./basic_barplots_LIG.R -d streptomycin -g gid +# picks default file name, or you can specify by the -f flag + +sources: + ## plotting_globals.R (previously dir.R) + ## plotting_data.R