6 # Isaak Y Tecle (iyt2@cornell.edu)
14 library(phenoAnalysis
)
18 allArgs
<- commandArgs()
20 outputFiles
<- scan(grep("output_files", allArgs
, value
= TRUE),
23 inputFiles
<- scan(grep("input_files", allArgs
, value
= TRUE),
26 phenoDataFile
<- grep("phenotype_data", inputFiles
, value
= TRUE)
27 message('pheno file: ', phenoDataFile
)
29 traitsFile
<- grep("traits", inputFiles
, value
= TRUE)
30 message('traits file: ', traitsFile
)
32 #phenoDataFile = '/export/prod/tmp/localhost/GBSApeKIgenotypingv4/anova/cache/phenotype_data_3639.txt';
33 #phenoDataFile = '/mnt/hgfs/cxgn/phenotype-3639.txt';
35 dropCols
<- c('programDbId','programName', 'programDescription', 'studyDbId', 'studyDescription', 'plotWidth', 'plotLength')
36 dropCols
<- c(dropCols
, 'fieldSize', 'fieldTrialIsPlannedToBeGenotyped', 'fieldTrialIsPlannedToCross', 'plantingDate', 'harvestDate')
37 dropCols
<- c(dropCols
,'entryType', 'plantNumber', 'plantedSeedlotStockDbId', 'plantedSeedlotStockUniquename')
38 dropCols
<- c(dropCols
, 'plantedSeedlotCurrentCount', 'plantedSeedlotCurrentWeightGram', 'plantedSeedlotBoxName')
39 dropCols
<- c(dropCols
, 'plantedSeedlotTransactionCount','plantedSeedlotTransactionWeight')
40 dropCols
<- c(dropCols
, 'plantedSeedlotTransactionDescription', 'availableGermplasmSeedlotUniquenames')
42 phenoData
<- fread(phenoDataFile
, sep
="\t", drop
=dropCols
,
43 na
.strings
=c("NA", "-", " ", ".", ".."))
45 phenoData
<- data
.frame(phenoData
)
47 traits
<- scan(traitsFile
,
50 traits
<- strsplit(traits
, "\t")
53 #needs more work for multi traits anova
54 for (trait
in traits
) {
56 message('trait: ', trait
)
57 anovaFiles
<- grep("anova_table",
61 message('anova file: ', anovaFiles
)
62 anovaHtmlFile
<- grep("html",
66 message('anova html file: ', anovaHtmlFile
)
67 anovaTxtFile
<- grep("txt",
71 message('anova txt file: ', anovaTxtFile
)
72 modelSummFile
<- grep("anova_model",
76 message('model file: ', modelSummFile
)
77 adjMeansFile
<- grep("adj_means",
81 message('means file: ', adjMeansFile
)
84 diagnosticsFile
<- grep("anova_diagnostics",
88 errorFile
<- grep("anova_error",
92 anovaOut
<- runAnova(phenoData
, trait
)
93 if (class(anovaOut
) == 'character') {
94 cat(anovaOut
, file
=errorFile
)
95 } else if (is
.null(anovaOut
)) {
96 cat('Error occured fitting anova model to this trait data. Please check the trait data and design factors.', file
=errorFile
)
97 } else if (class(anovaOut
)[1] == 'lmerModLmerTest' || class(anovaOut
)[1] == 'merModLmerTest') {
99 png(diagnosticsFile
, 960, 480)
101 plot(fitted(anovaOut
), resid(anovaOut
),
102 xlab
="Fitted values",
104 main
="Fitted values vs Residuals")
106 qqnorm(resid(anovaOut
))
109 anovaTable
<- getAnovaTable(anovaOut
,
114 anovaTable
<- getAnovaTable(anovaOut
,
120 adjMeans
<- getAdjMeans(phenoData
, trait
)
137 q(save
= "no", runLast
= FALSE)