#!/usr/bin/env Rscript                                                  
#########################################################
# TASK: To calculate Allele Frequency and
# Odds Ratio from master data
#########################################################
# load libraries
#source("~/git/LSHTM_analysis/scripts/Header_TT.R")
require("getopt", quietly = TRUE) # cmd parse arguments

# working dir and loading libraries
getwd()
setwd("~/git/LSHTM_analysis/scripts/functions/")
getwd()

# load functions
source("plotting_globals.R")
source("mychisq_or.R")
source("myaf_or_calcs.R")

# cmd options + sensible defaults
drug = "streptomycin"
gene = "gid"

# call function
import_dirs(drug, gene)

# input file 1: master data
#in_filename_master  = 'original_tanushree_data_v2.csv' #19K
in_filename_master  = 'mtb_gwas_meta_v6.csv' #35k
infile_master = paste0(datadir, in_filename_master)
cat(paste0('Reading infile1: raw data', ' ', infile_master) )

# input file 2: gene associated meta data file to extract valid snps and add calcs to.
# This is outfile_metadata from data_extraction.py
in_filename_metadata =  paste0(tolower(gene), '_metadata.csv')
infile_metadata = paste0(outdir, '/', in_filename_metadata)
cat(paste0('Reading input file 2 i.e gene associated metadata:', infile_metadata))

# out_filename_af_or = paste0(tolower(gene), '_meta_data_with_AF_OR.csv')
out_filename_af_or = paste0(tolower(gene), '_af_or.csv')
outfile_af_or = paste0(outdir, '/', out_filename_af_or)
cat(paste0('Output file with full path:', outfile_af_or))

cat("master data:", infile_master)
cat("gene data:", infile_metadata)

dr_muts_col # comes from global (dr_mutations_<drug>)
other_muts_col # comes from global (other_mutations_<drug>)
#################################################
my_afor (  infile_master
         , infile_metadata
         , outfile = outfile_af_or
         #, outfile = "FOO_TEST.csv"
         , drug
         , gene
         , idcol = "id"
         , dr_muts_col 
         , other_muts_col
         )
