af and or calcs, not merging
This commit is contained in:
parent
010ef133dd
commit
b33419c939
1 changed files with 27 additions and 14 deletions
|
@ -9,7 +9,7 @@ setwd('~/git/LSHTM_analysis/scripts')
|
|||
getwd()
|
||||
|
||||
options(scipen = 999) #disabling scientific notation in R.
|
||||
options(scipen = 4)
|
||||
#options(scipen = 4)
|
||||
|
||||
#%% variable assignment: input and output paths & filenames
|
||||
drug = 'pyrazinamide'
|
||||
|
@ -40,7 +40,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), '_meta_data_with_AF_OR.csv')
|
||||
out_filename = paste0(tolower(gene), '_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
|
||||
|
@ -261,7 +262,7 @@ statistic_chi = sapply(gene_snps_unique,function(m){
|
|||
})
|
||||
|
||||
# statistic_chi: has suffix added of '.X-squared'
|
||||
head(statistic_chi)
|
||||
stat_chi = statistic_chi
|
||||
|
||||
# remove suffix
|
||||
names(stat_chi) = gsub(".X-squared", "", names(statistic_chi))
|
||||
|
@ -389,7 +390,6 @@ hist(log(ors)
|
|||
, breaks = 100)
|
||||
|
||||
# sanity check: if names are equal (just for 3 vars)
|
||||
|
||||
all(sapply(list(names(afs)
|
||||
, names(pvals_chi)
|
||||
, names(statistic_chi) # should return False
|
||||
|
@ -445,11 +445,7 @@ comb_AF_and_OR = data.frame(afs
|
|||
, ci_ub_fisher
|
||||
, pvals_logistic
|
||||
, ors_logistic)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cat('No. of rows in comb_AF_and_OR: ', nrow(comb_AF_and_OR)
|
||||
, '\nNo. of cols in comb_AF_and_OR: ', ncol(comb_AF_and_OR))
|
||||
|
||||
|
@ -464,11 +460,28 @@ if (table(rownames(comb_AF_and_OR) == comb_AF_and_OR$mutation)){
|
|||
}else{
|
||||
cat('FAIL: rownames and mutation col values mismatch')
|
||||
}
|
||||
#########################################################
|
||||
# write file out: pnca_AF_OR
|
||||
#########################################################
|
||||
cat(paste0('writing output file: '
|
||||
, '\nFilename: ', outfile))
|
||||
|
||||
write.csv(comb_AF_and_OR, outfile
|
||||
, row.names = F)
|
||||
|
||||
cat(paste0('Finished writing:'
|
||||
, out_filename
|
||||
, '\nNo. of rows: ', nrow(comb_AF_and_OR)
|
||||
, '\nNo. of cols: ', ncol(comb_AF_and_OR)))
|
||||
#************************************************
|
||||
cat('======================================================================')
|
||||
rm(out_filename)
|
||||
cat('End of script: calculated AF, OR, pvalues and saved file')
|
||||
|
||||
#########################################################
|
||||
# 3: Merge meta data file + calculated num params
|
||||
#########################################################
|
||||
df1 = pnca_metadata
|
||||
df1 = gene_metadata
|
||||
df2 = comb_AF_and_OR
|
||||
|
||||
cat('checking commom col of the two dfs before merging:'
|
||||
|
@ -509,10 +522,10 @@ if ( identical(na_count[[length(na_count)]], na_count[[length(na_count)-1]], na_
|
|||
}
|
||||
|
||||
# reassign custom colnames
|
||||
cat('Assigning custom colnames for the calculated params...')
|
||||
colnames(merged_df)[colnames(merged_df)== "ors"] <- "OR"
|
||||
colnames(merged_df)[colnames(merged_df)== "pvals"] <- "pvalue"
|
||||
colnames(merged_df)[colnames(merged_df)== "afs"] <- "AF"
|
||||
#cat('Assigning custom colnames for the calculated params...')
|
||||
#colnames(merged_df)[colnames(merged_df)== "ors"] <- "OR"
|
||||
#colnames(merged_df)[colnames(merged_df)== "pvals"] <- "pvalue"
|
||||
#colnames(merged_df)[colnames(merged_df)== "afs"] <- "AF"
|
||||
|
||||
colnames(merged_df)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue