adpated combining_dfs.py and plotting.R for gid and attempting to make it generic
This commit is contained in:
parent
2c5c704d0b
commit
a1fef205da
3 changed files with 91 additions and 81 deletions
|
@ -57,10 +57,10 @@ from combining_FIXME import detect_common_cols
|
||||||
from reference_dict import oneletter_aa_dict # CHECK DIR STRUC THERE!
|
from reference_dict import oneletter_aa_dict # CHECK DIR STRUC THERE!
|
||||||
from reference_dict import low_3letter_dict # CHECK DIR STRUC THERE!
|
from reference_dict import low_3letter_dict # CHECK DIR STRUC THERE!
|
||||||
#=======================================================================
|
#=======================================================================
|
||||||
#%% command line args
|
#%% command line args: case sensitive
|
||||||
arg_parser = argparse.ArgumentParser()
|
arg_parser = argparse.ArgumentParser()
|
||||||
arg_parser.add_argument('-d', '--drug', help='drug name', default = 'pyrazinamide')
|
arg_parser.add_argument('-d', '--drug', help='drug name', default = '')
|
||||||
arg_parser.add_argument('-g', '--gene', help='gene name', default = 'pncA') # case sensitive
|
arg_parser.add_argument('-g', '--gene', help='gene name', default = '')
|
||||||
|
|
||||||
arg_parser.add_argument('--datadir', help = 'Data Directory. By default, it assmumes homedir + git/Data')
|
arg_parser.add_argument('--datadir', help = 'Data Directory. By default, it assmumes homedir + git/Data')
|
||||||
arg_parser.add_argument('-i', '--input_dir', help = 'Input dir containing pdb files. By default, it assmumes homedir + <drug> + input')
|
arg_parser.add_argument('-i', '--input_dir', help = 'Input dir containing pdb files. By default, it assmumes homedir + <drug> + input')
|
||||||
|
@ -99,32 +99,37 @@ print('position regex:', pos_regex)
|
||||||
# directories
|
# directories
|
||||||
#==============
|
#==============
|
||||||
if not datadir:
|
if not datadir:
|
||||||
datadir = homedir + '/' + 'git/Data'
|
datadir = homedir + '/git/Data/'
|
||||||
|
|
||||||
if not indir:
|
if not indir:
|
||||||
indir = datadir + '/' + drug + '/input'
|
indir = datadir + drug + '/input/'
|
||||||
|
|
||||||
if not outdir:
|
if not outdir:
|
||||||
outdir = datadir + '/' + drug + '/output'
|
outdir = datadir + drug + '/output/'
|
||||||
|
|
||||||
#=======
|
#=======
|
||||||
# input
|
# input
|
||||||
#=======
|
#=======
|
||||||
in_filename_mcsm = gene.lower() + '_complex_mcsm_norm.csv'
|
#in_filename_mcsm = gene.lower() + '_complex_mcsm_norm.csv'
|
||||||
|
in_filename_mcsm = gene.lower() + '_complex_mcsm_norm_SAM.csv' # gidb
|
||||||
in_filename_foldx = gene.lower() + '_foldx.csv'
|
in_filename_foldx = gene.lower() + '_foldx.csv'
|
||||||
in_filename_dssp = gene.lower() + '_dssp.csv'
|
in_filename_dssp = gene.lower() + '_dssp.csv'
|
||||||
in_filename_kd = gene.lower() + '_kd.csv'
|
in_filename_kd = gene.lower() + '_kd.csv'
|
||||||
in_filename_rd = gene.lower() + '_rd.csv'
|
in_filename_rd = gene.lower() + '_rd.csv'
|
||||||
in_filename_snpinfo = 'ns' + gene.lower() + '_snp_info_f.csv'
|
#in_filename_deepddg = gene.lower() + '_complex_ddg_results.txt' # change to decent filename and put it in the correct dir
|
||||||
|
|
||||||
|
in_filename_snpinfo = 'ns' + gene.lower() + '_snp_info_f.csv' # gwas f info
|
||||||
in_filename_afor = gene.lower() + '_af_or.csv'
|
in_filename_afor = gene.lower() + '_af_or.csv'
|
||||||
in_filename_afor_kin = gene.lower() + '_af_or_kinship.csv'
|
in_filename_afor_kin = gene.lower() + '_af_or_kinship.csv'
|
||||||
|
|
||||||
|
|
||||||
infile_mcsm = outdir + '/' + in_filename_mcsm
|
infile_mcsm = outdir + in_filename_mcsm
|
||||||
infile_foldx = outdir + '/' + in_filename_foldx
|
infile_foldx = outdir + in_filename_foldx
|
||||||
infile_dssp = outdir + '/' + in_filename_dssp
|
infile_dssp = outdir + in_filename_dssp
|
||||||
infile_kd = outdir + '/' + in_filename_kd
|
infile_kd = outdir + in_filename_kd
|
||||||
infile_rd = outdir + '/' + in_filename_rd
|
infile_rd = outdir + in_filename_rd
|
||||||
|
#infile_deepddg = outdir + in_filename_deepddg
|
||||||
|
|
||||||
infile_snpinfo = outdir + '/' + in_filename_snpinfo
|
infile_snpinfo = outdir + '/' + in_filename_snpinfo
|
||||||
infile_afor = outdir + '/' + in_filename_afor
|
infile_afor = outdir + '/' + in_filename_afor
|
||||||
infile_afor_kin = outdir + '/' + in_filename_afor_kin
|
infile_afor_kin = outdir + '/' + in_filename_afor_kin
|
||||||
|
@ -135,7 +140,9 @@ print('\nInput path:', indir
|
||||||
, '\nInput filename foldx:', infile_foldx, '\n'
|
, '\nInput filename foldx:', infile_foldx, '\n'
|
||||||
, '\nInput filename dssp:', infile_dssp
|
, '\nInput filename dssp:', infile_dssp
|
||||||
, '\nInput filename kd:', infile_kd
|
, '\nInput filename kd:', infile_kd
|
||||||
, '\nInput filename rd', infile_rd , '\n'
|
, '\nInput filename rd', infile_rd
|
||||||
|
# , '\nInput filename rd', infile_deepddg , '\n'
|
||||||
|
|
||||||
, '\nInput filename snp info:', infile_snpinfo, '\n'
|
, '\nInput filename snp info:', infile_snpinfo, '\n'
|
||||||
, '\nInput filename af or:', infile_afor
|
, '\nInput filename af or:', infile_afor
|
||||||
, '\nInput filename afor kinship:', infile_afor_kin
|
, '\nInput filename afor kinship:', infile_afor_kin
|
||||||
|
@ -225,10 +232,39 @@ print('\nResult of Fourth merge:', combined_df.shape
|
||||||
, '\n===================================================================')
|
, '\n===================================================================')
|
||||||
combined_df[merging_cols_m4].apply(len)
|
combined_df[merging_cols_m4].apply(len)
|
||||||
combined_df[merging_cols_m4].apply(len) == len(combined_df)
|
combined_df[merging_cols_m4].apply(len) == len(combined_df)
|
||||||
|
|
||||||
#%%============================================================================
|
#%%============================================================================
|
||||||
|
|
||||||
# OR merges: TEDIOUSSSS!!!!
|
#deepddg_df = pd.read_csv(infile_deepddg, sep = ' ')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#%%============================================================================
|
||||||
|
# Output columns
|
||||||
|
|
||||||
|
out_filename_stab_struc = gene.lower() + '_comb_stab_struc_params.csv'
|
||||||
|
outfile_stab_struc = outdir + '/' + out_filename_stab_struc
|
||||||
|
print('Output filename:', outfile_stab_struc
|
||||||
|
, '\n===================================================================')
|
||||||
|
|
||||||
|
# write csv
|
||||||
|
print('Writing file: combined stability and structural parameters')
|
||||||
|
combined_df.to_csv(outfile_stab_struc, index = False)
|
||||||
|
print('\nFinished writing file:'
|
||||||
|
, '\nNo. of rows:', combined_df.shape[0]
|
||||||
|
, '\nNo. of cols:', combined_df.shape[1])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#%%============================================================================
|
||||||
|
# OR merges: TEDIOUSSSS!!!!
|
||||||
|
#[ DELETE ]
|
||||||
del(mcsm_df, foldx_df, mcsm_foldx_dfs, dssp_kd_dfs, dssp_kd_rd_dfs,rd_df, kd_df, infile_mcsm, infile_foldx, infile_dssp, infile_kd)
|
del(mcsm_df, foldx_df, mcsm_foldx_dfs, dssp_kd_dfs, dssp_kd_rd_dfs,rd_df, kd_df, infile_mcsm, infile_foldx, infile_dssp, infile_kd)
|
||||||
del(merging_cols_m1, merging_cols_m2, merging_cols_m3, merging_cols_m4)
|
del(merging_cols_m1, merging_cols_m2, merging_cols_m3, merging_cols_m4)
|
||||||
del(in_filename_dssp, in_filename_foldx, in_filename_kd, in_filename_mcsm, in_filename_rd)
|
del(in_filename_dssp, in_filename_foldx, in_filename_kd, in_filename_mcsm, in_filename_rd)
|
||||||
|
|
|
@ -1,56 +1,24 @@
|
||||||
#!/usr/bin/env Rscript
|
#!/usr/bin/env Rscript
|
||||||
#########################################################
|
#########################################################
|
||||||
# TASK: formatting data that will be used for various plots
|
# TASK: importing dir str
|
||||||
|
# create a function that takes 'drug' and 'gene' as args,
|
||||||
# useful links
|
# This script is sourced by plotting.R to import dir str
|
||||||
#https://stackoverflow.com/questions/38851592/r-append-column-in-a-dataframe-with-frequency-count-based-on-two-columns
|
# for various plots, etc.
|
||||||
#########################################################
|
#########################################################
|
||||||
# working dir and loading libraries
|
import_dirs <- function(drug, gene) {
|
||||||
getwd()
|
gene_match = paste0(gene,"_p.")
|
||||||
setwd("~/git/LSHTM_analysis/scripts/plotting")
|
cat(gene_match)
|
||||||
getwd()
|
|
||||||
|
|
||||||
#source("Header_TT.R")
|
|
||||||
library(ggplot2)
|
|
||||||
library(data.table)
|
|
||||||
library(dplyr)
|
|
||||||
|
|
||||||
require("getopt", quietly = TRUE) #cmd parse arguments
|
|
||||||
#========================================================
|
|
||||||
# command line args
|
|
||||||
#spec = matrix(c(
|
|
||||||
# "drug" , "d", 1, "character",
|
|
||||||
# "gene" , "g", 1, "character"
|
|
||||||
#), byrow = TRUE, ncol = 4)
|
|
||||||
|
|
||||||
#opt = getopt(spec)
|
|
||||||
|
|
||||||
#drug = opt$druggene = opt$gene
|
|
||||||
|
|
||||||
#if(is.null(drug)|is.null(gene)) {
|
|
||||||
# stop("Missing arguments: --drug and --gene must both be specified (case-sensitive)")
|
|
||||||
#}
|
|
||||||
#========================================================
|
|
||||||
# FIXME: change to cmd
|
|
||||||
#%% variable assignment: input and output paths & filenames
|
|
||||||
drug = "pyrazinamide"
|
|
||||||
gene = "pncA"
|
|
||||||
gene_match = paste0(gene,"_p.")
|
|
||||||
cat(gene_match)
|
|
||||||
|
|
||||||
#=============
|
|
||||||
# directories and variables
|
|
||||||
#=============
|
|
||||||
datadir = paste0("~/git/Data")
|
|
||||||
indir = paste0(datadir, "/", drug, "/input")
|
|
||||||
outdir = paste0("~/git/Data", "/", drug, "/output")
|
|
||||||
plotdir = paste0("~/git/Data", "/", drug, "/output/plots")
|
|
||||||
|
|
||||||
dr_muts_col = paste0('dr_mutations_', drug)
|
|
||||||
other_muts_col = paste0('other_mutations_', drug)
|
|
||||||
resistance_col = "drtype"
|
|
||||||
|
|
||||||
#%%===============================================================
|
|
||||||
|
|
||||||
|
#=============
|
||||||
|
# directories and variables
|
||||||
|
#=============
|
||||||
|
datadir <<- paste0("~/git/Data")
|
||||||
|
indir <<- paste0(datadir, "/", drug, "/input")
|
||||||
|
outdir <<- paste0("~/git/Data", "/", drug, "/output")
|
||||||
|
plotdir <<- paste0("~/git/Data", "/", drug, "/output/plots")
|
||||||
|
|
||||||
|
dr_muts_col <<- paste0('dr_mutations_', drug)
|
||||||
|
other_muts_col <<- paste0('other_mutations_', drug)
|
||||||
|
resistance_col <<- "drtype"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -14,31 +14,37 @@ getwd()
|
||||||
library(ggplot2)
|
library(ggplot2)
|
||||||
library(data.table)
|
library(data.table)
|
||||||
library(dplyr)
|
library(dplyr)
|
||||||
|
|
||||||
source("dirs.R")
|
|
||||||
|
|
||||||
require("getopt", quietly = TRUE) #cmd parse arguments
|
require("getopt", quietly = TRUE) #cmd parse arguments
|
||||||
|
source("dirs.R")
|
||||||
|
|
||||||
#========================================================
|
#========================================================
|
||||||
# command line args
|
# command line args
|
||||||
#spec = matrix(c(
|
spec = matrix(c(
|
||||||
# "drug" , "d", 1, "character",
|
"drug" , "d", 1, "character",
|
||||||
# "gene" , "g", 1, "character"
|
"gene" , "g", 1, "character"
|
||||||
#), byrow = TRUE, ncol = 4)
|
), byrow = TRUE, ncol = 4)
|
||||||
|
|
||||||
#opt = getopt(spec)
|
opt = getopt(spec)
|
||||||
|
|
||||||
#drug = opt$druggene = opt$gene
|
#FIXME: detect if script running from cmd, then set these
|
||||||
|
#drug = opt$drug
|
||||||
|
#gene = opt$gene
|
||||||
|
|
||||||
|
# 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)")
|
||||||
|
}
|
||||||
|
|
||||||
#if(is.null(drug)|is.null(gene)) {
|
|
||||||
# stop("Missing arguments: --drug and --gene must both be specified (case-sensitive)")
|
|
||||||
#}
|
|
||||||
#========================================================
|
#========================================================
|
||||||
#======
|
#======
|
||||||
# input
|
# input
|
||||||
#======
|
#======
|
||||||
#in_filename = "mcsm_complex1_normalised.csv"
|
#in_filename = "mcsm_complex1_normalised.csv"
|
||||||
in_filename_params = paste0(tolower(gene), "_all_params.csv")
|
#in_filename_params = paste0(tolower(gene), "_all_params.csv")
|
||||||
|
in_filename_params = paste0(tolower(gene), "_comb_stab_struc_params.csv") # part combined
|
||||||
infile_params = paste0(outdir, "/", in_filename_params)
|
infile_params = paste0(outdir, "/", in_filename_params)
|
||||||
cat(paste0("Input file 1:", infile_params) )
|
cat(paste0("Input file 1:", infile_params) )
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue