Mercurial > repos > abims-sbr > mutcount
comparison scripts/S03b_sign_test_binomial.R @ 0:acc3674e515b draft default tip
planemo upload for repository htpps://github.com/abims-sbr/adaptearch commit 3c7982d775b6f3b472f6514d791edcb43cd258a1-dirty
| author | abims-sbr |
|---|---|
| date | Fri, 01 Feb 2019 10:28:50 -0500 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:acc3674e515b |
|---|---|
| 1 #!/usr/bin/env Rscript | |
| 2 #coding: utf-8 | |
| 3 #Author : Eric Fontanillas (2010) - Victor Mataigne (2018) | |
| 4 | |
| 5 # binom test - null hypothesis : | |
| 6 # The test computes the number of times where the value of the variable A is higher to the value of the variable B. | |
| 7 # Under the null hypothesis, there is no difference between variables : A > B in 50% of the trials | |
| 8 | |
| 9 options(warn = -1) | |
| 10 | |
| 11 library(optparse) | |
| 12 | |
| 13 option_list = list( | |
| 14 make_option(c('-i', '--indir'), type='character', default=NULL, help='input directory name', metavar='character'), | |
| 15 make_option(c('-o', '--outdir'), type='character', default=NULL, help='output directory name', metavar='character') | |
| 16 ); | |
| 17 | |
| 18 opt_parser = OptionParser(option_list=option_list); | |
| 19 opt = parse_args(opt_parser); | |
| 20 path_IN <- opt$indir | |
| 21 path_OUT <- opt$outdir | |
| 22 files_OUT <- paste(path_OUT,"/*",sep='') | |
| 23 unlink(files_OUT) ### clean the path_OUT folder from previous files | |
| 24 list_files <- list.files(path_IN) | |
| 25 | |
| 26 # iterate over file | |
| 27 for(file in list_files){ | |
| 28 name_OUT = paste(path_OUT,"/", file, sep='') | |
| 29 name_IN = paste(path_IN,"/", file, sep='') | |
| 30 | |
| 31 b <- read.table(name_IN, sep=",", header=T, row.names=1) | |
| 32 | |
| 33 supplemental_cells <- matrix(0, nrow=4, ncol=ncol(b)) | |
| 34 colnames(supplemental_cells) <- colnames(b) | |
| 35 row.names(supplemental_cells) <- c('p-value', 'probability_of_success', 'confidence_interval_low', 'confidence_interval_high') | |
| 36 | |
| 37 # iterate over species groups | |
| 38 for (i in 1:ncol(b)) { | |
| 39 if (b[4,i] != 0) { | |
| 40 binom_test <- binom.test(b[1,i], b[4,i]) | |
| 41 supplemental_cells[1,i] <- binom_test$p.value | |
| 42 supplemental_cells[2,i] <- binom_test$estimate | |
| 43 supplemental_cells[3,i] <- binom_test$conf.int[1] | |
| 44 supplemental_cells[4,i] <- binom_test$conf.int[2] | |
| 45 } else { | |
| 46 supplemental_cells[1,i] <- NA | |
| 47 supplemental_cells[2,i] <- NA | |
| 48 supplemental_cells[3,i] <- NA | |
| 49 supplemental_cells[4,i] <- NA | |
| 50 } | |
| 51 } | |
| 52 | |
| 53 final <- rbind(b, supplemental_cells) | |
| 54 write.csv(final, file=name_OUT) | |
| 55 } | |
| 56 |
