ANOVA r script..
[sgn.git] / R / anova.r
blob22945406ff52e844d99030a3cf43f6760ad879a0
1 #SNOPSIS
3 #runs ANOVA.
6 #AUTHOR
7 # Isaak Y Tecle (iyt2@cornell.edu)
10 options(echo = FALSE)
13 #library(dplyr)
14 library(data.table)
15 library(phenoAnalysis)
18 allArgs <- commandArgs()
20 outputFiles <- scan(grep("output_files", allArgs, value = TRUE),
21 what = "character")
23 inputFiles <- scan(grep("input_files", allArgs, value = TRUE),
24 what = "character")
26 phenoDataFile <- grep("phenotype_data", inputFiles, value = TRUE)
27 message('pheno file: ', phenoDataFile)
28 traitsFile <- grep("traits", inputFiles, value = TRUE)
29 message('traits file: ', traitsFile)
31 #phenoDataFile <- '/export/prod/tmp/localhost/GBSApeKIgenotypingv4/solgs/cache/phenotype_data_139.txt';
32 #phenoDataFile <- '/mnt/hgfs/cxgn/phenotype_data_RCBD_1596.txt';
34 phenoData <- fread(phenoDataFile,
35 na.strings=c("NA", "-", " ", ".", ".."))
37 phenoData <- data.frame(phenoData)
39 traits <- scan(traitsFile,
40 what = "character",)
42 traits <- strsplit(traits, "\t")
44 #needs more work for multi traits anova
45 for (trait in traits) {
46 anovaFiles <- grep("anova_table",
47 outputFiles,
48 value = TRUE)
50 message('anova file: ', anovaFiles)
51 anovaHtmlFile <- grep("html",
52 anovaFiles,
53 value = TRUE)
55 message('anova html file: ', anovaHtmlFile)
56 anovaTxtFile <- grep("txt",
57 anovaFiles,
58 value = TRUE)
60 message('anova txt file: ', anovaTxtFile)
61 modelSummFile <- grep("anova_model",
62 outputFiles,
63 value = TRUE)
65 message('model file: ', modelSummFile)
66 adjMeansFile <- grep("adj_means",
67 outputFiles,
68 value = TRUE)
70 message('means file: ', adjMeansFile)
72 anovaOut <- runAnova(phenoData, trait)
74 anovaTable <- getAnovaTable(anovaOut,
75 tableType="html",
76 traitName=trait,
77 out=anovaHtmlFile)
79 anovaTable <- getAnovaTable(anovaOut,
80 tableType="text",
81 traitName=trait,
82 out=anovaTxtFile)
84 adjMeans <- getAdjMeans(phenoData, trait)
86 fwrite(adjMeans,
87 file = adjMeansFile,
88 row.names = FALSE,
89 sep = "\t",
90 quote = FALSE,
93 sink(modelSummFile)
94 print(anovaOut)
95 sink()
99 q(save = "no", runLast = FALSE)