diff --git a/scripts/AF_and_OR_calcs.R b/scripts/AF_and_OR_calcs.R old mode 100644 new mode 100755 index 292061d..be06ed5 --- a/scripts/AF_and_OR_calcs.R +++ b/scripts/AF_and_OR_calcs.R @@ -1,19 +1,37 @@ +#!/usr/bin/env Rscript +#require('compare') +require('getopt', quietly=TRUE) # We need to be able to parse arguments ######################################################### # TASK: To calculate Allele Frequency and # Odds Ratio from master data # and add the calculated params to meta_data extracted from # data_extraction.py ######################################################### -getwd() +#getwd() setwd('~/git/LSHTM_analysis/scripts') -getwd() - -options(scipen = 999) #disabling scientific notation in R. +cat(c(getwd(),'\n')) + +# Command line args +spec = matrix(c( + "drug" , "d", 1, "character", + "gene" , "g", 1, "character" +), byrow = TRUE, ncol = 4) + +opt = getopt(spec); + +drug = opt$drug +gene = opt$gene + +if(is.null(drug)|is.null(gene)) { + stop('--drug and --gene must both be specified (case-sensitive)') + } + +#options(scipen = 999) #disabling scientific notation in R. #options(scipen = 4) #%% variable assignment: input and output paths & filenames -drug = 'pyrazinamide' -gene = 'pncA' +#drug = 'pyrazinamide' +#gene = 'pncA' gene_match = paste0(gene,'_p.') cat(gene_match) @@ -41,7 +59,8 @@ cat(paste0('Reading infile2: gene associated metadata:', infile_metadata)) # outdir = 'git/Data/pyrazinamide/output' outdir = paste0('~/git/Data', '/', drug, '/', 'output') #out_filename = paste0(tolower(gene), '_meta_data_with_AF_OR.csv') -out_filename = paste0(tolower(gene), '_AF_OR.csv') +#out_filename = paste0(tolower(gene), '_AF_OR.csv') +out_filename = paste0(tolower(gene), '_XXXXX_AF_OR.csv') outfile = paste0(outdir, '/', out_filename) cat(paste0('Output file with full path:', outfile)) #%% end of variable assignment for input and output files @@ -380,14 +399,14 @@ head(pvals_logistic) #============================================= # check ..(hmmm) perhaps separate script) -afs['pnca_p.trp68gly'] -afs['pnca_p.gln10pro'] -afs['pnca_p.leu4ser'] - -plot(density(log(ors_logistic))) -plot(-log10(pvals)) -hist(log(ors) - , breaks = 100) +#afs['pnca_p.trp68gly'] +#afs['pnca_p.gln10pro'] +#afs['pnca_p.leu4ser'] +# +#plot(density(log(ors_logistic))) +#plot(-log10(pvals)) +#hist(log(ors) +# , breaks = 100) # sanity check: if names are equal (just for 3 vars) all(sapply(list(names(afs) @@ -395,11 +414,11 @@ all(sapply(list(names(afs) , names(statistic_chi) # should return False , names(ors_chi_cus)), function (x) x == names(ors_logistic))) -compare(names(afs) - , names(pvals_chi) - , names(statistic_chi) #TEST: should return False, but DOESN'T - , names(ors_chi_cus) - , names(stat_chi))$result +#compare(names(afs) +# , names(pvals_chi) +# , names(statistic_chi) #TEST: should return False, but DOESN'T +# , names(ors_chi_cus) +# , names(stat_chi))$result #=============== Now with all vars @@ -484,4 +503,7 @@ cat('End of script: calculated AF, OR, pvalues and saved file') #df1 = gene_metadata #df2 = comb_AF_and_OR -# COMMENT: will do the combining with the other OR and AF (in python) \ No newline at end of file + + + +# COMMENT: will do the combining with the other OR and AF (in python) diff --git a/scripts/commandArgs-example.r b/scripts/commandArgs-example.r new file mode 100755 index 0000000..00ad67f --- /dev/null +++ b/scripts/commandArgs-example.r @@ -0,0 +1,9 @@ +#!/usr/bin/env Rscript +print('R Argument Test') + +cmd <- paste(commandArgs(), collapse=" ") +cat("How R was invoked:\n"); +cat(cmd, "\n") + +args <- commandArgs(trailingOnly = TRUE) +cat(c('Command Line Arguments supplied: ', args)) diff --git a/scripts/getopt-example.r b/scripts/getopt-example.r new file mode 100755 index 0000000..564c481 --- /dev/null +++ b/scripts/getopt-example.r @@ -0,0 +1,14 @@ +#!/usr/bin/env Rscript +require('getopt', quietly=TRUE) + +spec = matrix(c( + "drug" , "d", 1, "character", + "gene" , "g", 1, "character" +), byrow=TRUE, ncol=4) + +opt = getopt(spec); + +drug = opt$drug +gene = opt$gene + +cat(c('\nDrug:', drug, '\nGene:', gene, '\n'))