getopt and commandArgs examples, and AF/OR update to use getopt()
This commit is contained in:
parent
864f814e1b
commit
f9a8ed3dc7
3 changed files with 66 additions and 21 deletions
60
scripts/AF_and_OR_calcs.R
Normal file → Executable file
60
scripts/AF_and_OR_calcs.R
Normal file → Executable file
|
@ -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()
|
||||
cat(c(getwd(),'\n'))
|
||||
|
||||
options(scipen = 999) #disabling scientific notation in R.
|
||||
# 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)
|
9
scripts/commandArgs-example.r
Executable file
9
scripts/commandArgs-example.r
Executable file
|
@ -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))
|
14
scripts/getopt-example.r
Executable file
14
scripts/getopt-example.r
Executable file
|
@ -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'))
|
Loading…
Add table
Add a link
Reference in a new issue