Merge branch 'master' into topic/upload_fieldbook_images
[sgn.git] / R / combine_gebvs_files.r
blobbd43c52a62e0c2bd4c214d4a4e8e7d4eb115b09b
1 #combines gebvs of traits of a population
2 # Isaak Y Tecle
5 options(echo = FALSE)
8 allArgs <- commandArgs()
10 inFile <- grep("gebv_files",
11 allArgs,
12 ignore.case = TRUE,
13 perl = TRUE,
14 value = TRUE
17 outputFile <- grep("combined_gebvs",
18 allArgs,
19 ignore.case = TRUE,
20 perl = TRUE,
21 value = TRUE
24 inputFiles <- scan(inFile,
25 what = "character"
29 combinedGebvs <- c()
30 count <- 0
32 for (i in inputFiles) {
34 traitGebv <- read.table(i,
35 header = TRUE,
36 row.names = NULL,
37 sep = "\t",
38 dec = "."
41 trait <- colnames(traitGebv)
42 count <- count + 1
44 traitGebv <- traitGebv[order(traitGebv$X), ]
46 if(count == 1) {
47 combinedGebvs <- traitGebv
49 row.names(combinedGebvs) <- combinedGebvs[, 1]
50 combinedGebvs[, 1] <- NULL
52 } else {
53 row.names(traitGebv) <- traitGebv[, 1]
54 traitGebv[, 1] <- NULL
56 combinedGebvs <- merge(traitGebv,
57 combinedGebvs,
58 by=0,
59 all=FALSE
62 rownames(combinedGebvs) <- combinedGebvs[, 1]
63 combinedGebvs$Row.names <- NULL
67 if (length(outputFile) != 0 ) {
68 write.table(combinedGebvs,
69 file = outputFile,
70 sep = "\t",
71 quote = FALSE,
72 col.names = NA,
76 q(save = "no", runLast = FALSE)