2 #calculates genomic estimated breeding values (GEBVs) using rrBLUP,
6 # Isaak Y Tecle (iyt2@cornell.edu)
17 library(genoDataFilter
)
18 library(phenoAnalysis
)
28 allArgs
<- commandArgs()
31 inputFiles
<- scan(grep("input_files", allArgs
, value
= TRUE),
34 outputFiles
<- scan(grep("output_files", allArgs
, value
= TRUE),
37 traitsFile
<- grep("traits", inputFiles
, value
= TRUE)
38 modelInfoFile
<- grep("model_info", inputFiles
, value
= TRUE)
39 message('model_info_file ', modelInfoFile
)
41 modelInfo
<- read
.table(modelInfoFile
,
42 header
=TRUE, sep
="\t",
45 modelInfo
<- column_to_rownames(modelInfo
, var
="Name")
46 traitId
<- modelInfo
["trait_id", 1]
47 traitAbbr
<- modelInfo
["trait_abbr", 1]
48 modelId
<- modelInfo
["model_id", 1]
49 protocolId
<- modelInfo
["protocol_id", 1]
51 message('class ', class(traitAbbr
))
52 message('trait_id ', traitId
)
53 message('trait_abbr ', traitAbbr
)
54 message('protocol_id ', protocolId
)
55 message('model_id ', modelId
)
57 datasetInfoFile
<- grep("dataset_info", inputFiles
, value
= TRUE)
60 if (length(datasetInfoFile
) != 0 ) {
61 datasetInfo
<- scan(datasetInfoFile
, what
= "character")
62 datasetInfo
<- paste(datasetInfo
, collapse
= " ")
64 datasetInfo
<- c('single population')
67 #validationTrait <- paste("validation", trait, sep = "_")
68 validationFile
<- grep('validation', outputFiles
, value
= TRUE)
70 if (is
.null(validationFile
)) {
71 stop("Validation output file is missing.")
74 #kinshipTrait <- paste("rrblup_training_gebvs", trait, sep = "_")
75 blupFile
<- grep('rrblup_training_gebvs', outputFiles
, value
= TRUE)
77 if (is
.null(blupFile
)) {
78 stop("GEBVs file is missing.")
81 #markerTrait <- paste("marker_effects", trait, sep = "_")
82 markerFile
<- grep('marker_effects', outputFiles
, value
= TRUE)
84 #traitPhenoFile <- paste("trait_phenotype_data", traitId, sep = "_")
85 modelPhenoFile
<- grep('model_phenodata', outputFiles
, value
= TRUE)
86 message('model input trait pheno file ', modelPhenoFile
)
87 varianceComponentsFile
<- grep("variance_components", outputFiles
, value
= TRUE)
88 filteredGenoFile
<- grep("filtered_genotype_data", outputFiles
, value
= TRUE)
89 formattedPhenoFile
<- grep("formatted_phenotype_data", inputFiles
, value
= TRUE)
91 genoFile
<- grep("genotype_data_", inputFiles
, value
= TRUE)
93 if (is
.null(genoFile
)) {
94 stop("genotype data file is missing.")
97 if (file
.info(genoFile
)$size
== 0) {
98 stop("genotype data file is empty.")
101 readFilteredGenoData
<- c()
102 filteredGenoData
<- c()
103 formattedPhenoData
<- c()
107 if (length(filteredGenoFile
) != 0 && file
.info(filteredGenoFile
)$size
!= 0) {
108 filteredGenoData
<- fread(filteredGenoFile
,
109 na
.strings
= c("NA", "", "--", "-"),
112 genoData
<- data
.frame(filteredGenoData
)
113 genoData
<- column_to_rownames(genoData
, 'V1')
114 readFilteredGenoData
<- 1
118 if (is
.null(filteredGenoData
)) {
119 genoData
<- fread(genoFile
,
120 na
.strings
= c("NA", "", "--", "-"),
123 genoData
<- unique(genoData
, by
='V1')
124 genoData
<- data
.frame(genoData
)
125 genoData
<- column_to_rownames(genoData
, 'V1')
127 #genoDataFilter::filterGenoData
128 genoData
<- convertToNumeric(genoData
)
129 genoData
<- filterGenoData(genoData
, maf
=0.01)
130 genoData
<- roundAlleleDosage(genoData
)
132 filteredGenoData
<- genoData
136 genoData
<- genoData
[order(row
.names(genoData
)), ]
138 if (length(formattedPhenoFile
) != 0 && file
.info(formattedPhenoFile
)$size
!= 0) {
139 formattedPhenoData
<- data
.frame(fread(formattedPhenoFile
,
141 na
.strings
= c("NA", "", "--", "-", ".")
146 if (datasetInfo
== 'combined populations') {
148 phenoFile
<- grep("model_phenodata", inputFiles
, value
= TRUE)
151 phenoFile
<- grep("\\/phenotype_data", inputFiles
, value
= TRUE)
154 if (is
.null(phenoFile
)) {
155 stop("phenotype data file is missing.")
158 if (file
.info(phenoFile
)$size
== 0) {
159 stop("phenotype data file is empty.")
162 phenoData
<- data
.frame(fread(phenoFile
,
164 na
.strings
= c("NA", "", "--", "-", "."),
170 if (datasetInfo
== 'combined populations') {
172 if (!is
.null(formattedPhenoData
)) {
173 phenoTrait
<- subset(formattedPhenoData
, select
= traitAbbr
)
174 phenoTrait
<- na
.omit(phenoTrait
)
178 if (any(grepl('Average', names(phenoData
)))) {
179 phenoTrait
<- phenoData
%>% select(V1
, Average
) %>% data
.frame
181 phenoTrait
<- phenoData
184 colnames(phenoTrait
) <- c('genotypes', traitAbbr
)
188 if (!is
.null(formattedPhenoData
)) {
189 phenoTrait
<- subset(formattedPhenoData
, select
= c('V1', traitAbbr
))
190 phenoTrait
<- as
.data
.frame(phenoTrait
)
191 phenoTrait
<- na
.omit(phenoTrait
)
192 print(head(phenoTrait
))
193 colnames(phenoTrait
)[1] <- 'genotypes'
195 } else if (length(grep('list', phenoFile
)) != 0) {
196 message('phenoTrait traitAbbr ', traitAbbr
)
197 phenoTrait
<- averageTrait(phenoData
, traitAbbr
)
200 print(head(phenoTrait
))
201 print(head(phenoData
))
202 message('phenoTrait trait_abbr ', traitAbbr
)
203 print(class(traitAbbr
))
205 phenoTrait
<- getAdjMeans(phenoData
,
206 traitName
= traitAbbr
,
212 print(head(phenoTrait
))
213 meanType
<- names(phenoTrait
)[2]
214 names(phenoTrait
) <- c('genotypes', traitAbbr
)
216 selectionTempFile
<- grep("selection_population", inputFiles
, value
= TRUE)
219 filteredPredGenoFile
<- c()
220 selectionAllFiles
<- c()
222 if (length(selectionTempFile
) !=0 ) {
223 selectionAllFiles
<- scan(selectionTempFile
, what
= "character")
225 selectionFile
<- grep("\\/genotype_data", selectionAllFiles
, value
= TRUE)
227 #filteredPredGenoFile <- grep("filtered_genotype_data_", selectionAllFiles, value = TRUE)
230 selectionPopGEBVsFile
<- grep("rrblup_selection_gebvs", outputFiles
, value
= TRUE)
233 readFilteredPredGenoData
<- c()
234 filteredPredGenoData
<- c()
236 ## if (length(filteredPredGenoFile) != 0 && file.info(filteredPredGenoFile)$size != 0) {
237 ## selectionData <- fread(filteredPredGenoFile, na.strings = c("NA", " ", "--", "-"),)
238 ## readFilteredPredGenoData <- 1
240 ## selectionData <- data.frame(selectionData)
241 ## rownames(selectionData) <- selectionData[, 1]
242 ## selectionData[, 1] <- NULL
245 if (length(selectionFile
) != 0) {
247 selectionData
<- fread(selectionFile
,
249 na
.strings
= c("NA", "", "--", "-"))
251 selectionData
<- unique(selectionData
, by
='V1')
252 selectionData
<- data
.frame(selectionData
)
253 selectionData
<- column_to_rownames(selectionData
, 'V1')
255 selectionData
<- convertToNumeric(selectionData
)
256 selectionData
<- filterGenoData(selectionData
, maf
=0.01)
257 selectionData
<- roundAlleleDosage(selectionData
)
259 filteredPredGenoData
<- selectionData
263 #impute genotype values for obs with missing values,
264 genoDataMissing
<- c()
266 if (sum(is
.na(genoData
)) > 0) {
267 genoDataMissing
<- c('yes')
269 genoData
<- na
.roughfix(genoData
)
270 genoData
<- data
.frame(genoData
)
273 #create phenotype and genotype datasets with
276 #extract observation lines with both
277 #phenotype and genotype data only.
278 commonObs
<- intersect(phenoTrait$genotypes
, row
.names(genoData
))
279 commonObs
<- data
.frame(commonObs
)
280 rownames(commonObs
) <- commonObs
[, 1]
282 #include in the genotype dataset only phenotyped lines
283 genoDataFilteredObs
<- genoData
[(rownames(genoData
) %in% rownames(commonObs
)), ]
285 #drop phenotyped lines without genotype data
286 phenoTrait
<- phenoTrait
[(phenoTrait$genotypes
%in% rownames(commonObs
)), ]
288 phenoTraitMarker
<- data
.frame(phenoTrait
)
289 rownames(phenoTraitMarker
) <- phenoTraitMarker
[, 1]
290 phenoTraitMarker
[, 1] <- NULL
292 #impute missing data in prediction data
293 selectionDataMissing
<- c()
294 if (length(selectionData
) != 0) {
295 #purge markers unique to both populations
296 commonMarkers
<- intersect(names(data
.frame(genoDataFilteredObs
)), names(selectionData
))
297 selectionData
<- subset(selectionData
, select
= commonMarkers
)
298 genoDataFilteredObs
<- subset(genoDataFilteredObs
, select
= commonMarkers
)
300 if (sum(is
.na(selectionData
)) > 0) {
301 selectionDataMissing
<- c('yes')
302 selectionData
<- na
.roughfix(selectionData
)
303 selectionData
<- data
.frame(selectionData
)
307 #change genotype coding to [-1, 0, 1], to use the A.mat ) if [0, 1, 2]
308 genoTrCode
<- grep("2", genoDataFilteredObs
[1, ], value
= TRUE)
309 if(length(genoTrCode
) != 0) {
310 genoData
<- genoData
- 1
311 genoDataFilteredObs
<- genoDataFilteredObs
- 1
314 if (length(selectionData
) != 0 ) {
315 genoSlCode
<- grep("2", selectionData
[1, ], value
= TRUE)
316 if (length(genoSlCode
) != 0 ) {
317 selectionData
<- selectionData
- 1
321 ordered
.markerEffects
<- c()
324 combinedGebvsFile
<- c()
326 modelPhenoData
<- c()
327 relationshipMatrix
<- c()
329 #additive relationship model
330 #calculate the inner products for
331 #genotypes (realized relationship matrix)
332 relationshipMatrixFile
<- grep("relationship_matrix_table", outputFiles
, value
= TRUE)
333 relationshipMatrixJsonFile
<- grep("relationship_matrix_json", outputFiles
, value
= TRUE)
335 traitRelationshipMatrixFile
<- grep("relationship_matrix_adjusted_table", outputFiles
, value
= TRUE)
336 traitRelationshipMatrixJsonFile
<- grep("relationship_matrix_adjusted_json", outputFiles
, value
= TRUE)
338 inbreedingFile
<- grep('inbreeding_coefficients', outputFiles
, value
=TRUE)
339 aveKinshipFile
<- grep('average_kinship', outputFiles
, value
=TRUE)
344 if (length(relationshipMatrixFile
) != 0) {
345 if (file
.info(relationshipMatrixFile
)$size
> 0 ) {
346 relationshipMatrix
<- data
.frame(fread(relationshipMatrixFile
,
349 rownames(relationshipMatrix
) <- relationshipMatrix
[, 1]
350 relationshipMatrix
[, 1] <- NULL
351 colnames(relationshipMatrix
) <- rownames(relationshipMatrix
)
352 relationshipMatrix
<- data
.matrix(relationshipMatrix
)
355 relationshipMatrix
<- A
.mat(genoData
)
356 diag(relationshipMatrix
) <- diag(relationshipMatrix
) + 1e-6
358 inbreeding
<- diag(relationshipMatrix
)
359 inbreeding
<- inbreeding
- 1
361 inbreeding
<- inbreeding
%>% replace(., . < 0, 0)
362 inbreeding
<- data
.frame(inbreeding
)
364 inbreeding
<- inbreeding
%>%
365 rownames_to_column('genotypes') %>%
366 rename(Inbreeding
= inbreeding
) %>%
367 arrange(Inbreeding
) %>%
368 mutate_at('Inbreeding', round
, 3) %>%
369 column_to_rownames('genotypes')
373 relationshipMatrix
<- data
.frame(relationshipMatrix
)
374 colnames(relationshipMatrix
) <- rownames(relationshipMatrix
)
376 relationshipMatrix
<- rownames_to_column(relationshipMatrix
, var
="genotypes")
377 relationshipMatrix
<- relationshipMatrix
%>% mutate_if(is
.numeric
, round
, 3)
378 relationshipMatrix
<- column_to_rownames(relationshipMatrix
, var
="genotypes")
380 traitRelationshipMatrix
<- relationshipMatrix
[(rownames(relationshipMatrix
) %in% rownames(commonObs
)), ]
381 traitRelationshipMatrix
<- traitRelationshipMatrix
[, (colnames(traitRelationshipMatrix
) %in% rownames(commonObs
))]
383 traitRelationshipMatrix
<- data
.matrix(traitRelationshipMatrix
)
385 #relationshipMatrixFiltered <- relationshipMatrixFiltered + 1e-3
387 nCores
<- detectCores()
390 nCores
<- (nCores
%/% 2)
396 if (length(selectionData
) == 0) {
398 trModel
<- kin
.blup(data
= phenoTrait
,
401 K
= traitRelationshipMatrix
,
407 trGEBVPEV
<- trModel$PEV
408 trGEBVSE
<- sqrt(trGEBVPEV
)
409 trGEBVSE
<- data
.frame(round(trGEBVSE
, 2))
411 trGEBV
<- data
.frame(round(trGEBV
, 2))
413 colnames(trGEBVSE
) <- c('SE')
414 colnames(trGEBV
) <- traitAbbr
416 trGEBVSE
<- rownames_to_column(trGEBVSE
, var
="genotypes")
417 trGEBV
<- rownames_to_column(trGEBV
, var
="genotypes")
419 trGEBVSE
<- full_join(trGEBV
, trGEBVSE
)
421 trGEBVSE
<- trGEBVSE
%>% arrange_(.dots
= paste0('desc(', traitAbbr
, ')'))
423 trGEBVSE
<- column_to_rownames(trGEBVSE
, var
="genotypes")
425 trGEBV
<- trGEBV
%>% arrange_(.dots
= paste0('desc(', traitAbbr
, ')'))
426 trGEBV
<- column_to_rownames(trGEBV
, var
="genotypes")
428 phenoTraitMarker
<- data
.matrix(phenoTraitMarker
)
429 genoDataFilteredObs
<- data
.matrix(genoDataFilteredObs
)
431 markerEffects
<- mixed
.solve(y
= phenoTraitMarker
,
432 Z
= genoDataFilteredObs
435 ordered
.markerEffects
<- data
.matrix(markerEffects$u
)
436 ordered
.markerEffects
<- data
.matrix(ordered
.markerEffects
[order (-ordered
.markerEffects
[, 1]), ])
437 ordered
.markerEffects
<- round(ordered
.markerEffects
, 5)
439 colnames(ordered
.markerEffects
) <- c("Marker Effects")
440 ordered
.markerEffects
<- data
.frame(ordered
.markerEffects
)
443 modelPhenoData
<- data
.frame(round(phenoTraitMarker
, 2))
445 heritability
<- round((trModel$Vg
/(trModel$Ve
+ trModel$Vg
)), 2)
447 cat("\n", file
= varianceComponentsFile
, append
= FALSE)
448 cat('Additive genetic variance', trModel$Vg
, file
= varianceComponentsFile
, sep
= '\t', append
= TRUE)
449 cat("\n", file
= varianceComponentsFile
, append
= TRUE)
450 cat('Error variance', trModel$Ve
, file
= varianceComponentsFile
, sep
= "\t", append
= TRUE)
451 cat("\n", file
= varianceComponentsFile
, append
= TRUE)
452 cat('SNP heritability (h)', heritability
, file
= varianceComponentsFile
, sep
= '\t', append
= TRUE)
454 combinedGebvsFile
<- grep('selected_traits_gebv', outputFiles
, ignore
.case
= TRUE,value
= TRUE)
456 if (length(combinedGebvsFile
) != 0) {
457 fileSize
<- file
.info(combinedGebvsFile
)$size
458 if (fileSize
!= 0 ) {
459 combinedGebvs
<- data
.frame(fread(combinedGebvsFile
,
462 rownames(combinedGebvs
) <- combinedGebvs
[,1]
463 combinedGebvs
[,1] <- NULL
465 allGebvs
<- merge(combinedGebvs
, trGEBV
,
470 rownames(allGebvs
) <- allGebvs
[,1]
477 if (is
.null(selectionFile
)) {
478 genoNum
<- nrow(phenoTrait
)
481 warning(genoNum
, " is too small number of genotypes.")
488 cvFolds
<- createMultiFolds(phenoTrait
[, 2], k
=k
, times
=times
)
490 for ( r
in 1:times
) {
491 re
<- paste0('Rep', r
)
494 fo
<- ifelse(i
< 10, 'Fold0', 'Fold')
496 trFoRe
<- paste0(fo
, i
, '.', re
)
497 trG
<- cvFolds
[[trFoRe
]]
498 slG
<- as
.numeric(rownames(phenoTrait
[-trG
,]))
500 kblup
<- paste("rKblup", i
, sep
= ".")
502 result
<- kin
.blup(data
= phenoTrait
[trG
,],
505 K
= traitRelationshipMatrix
,
510 assign(kblup
, result
)
512 #calculate cross-validation accuracy
515 valBlups
<- data
.frame(valBlups
)
517 slG
<- slG
[which(slG
<= nrow(phenoTrait
))]
519 slGDf
<- phenoTrait
[(rownames(phenoTrait
) %in% slG
),]
520 rownames(slGDf
) <- slGDf
[, 1]
523 valBlups
<- rownames_to_column(valBlups
, var
="genotypes")
524 slGDf
<- rownames_to_column(slGDf
, var
="genotypes")
526 valCorData
<- inner_join(slGDf
, valBlups
, by
="genotypes")
527 valCorData$genotypes
<- NULL
529 accuracy
<- try(cor(valCorData
))
530 validation
<- paste("validation", trFoRe
, sep
= ".")
531 cvTest
<- paste("CV", trFoRe
, sep
= " ")
533 if ( class(accuracy
) != "try-error")
535 accuracy
<- round(accuracy
[1,2], digits
= 3)
536 accuracy
<- data
.matrix(accuracy
)
538 colnames(accuracy
) <- c("correlation")
539 rownames(accuracy
) <- cvTest
541 assign(validation
, accuracy
)
543 if (!is
.na(accuracy
[1,1])) {
544 validationAll
<- rbind(validationAll
, accuracy
)
550 validationAll
<- data
.frame(validationAll
[order(-validationAll
[, 1]), ])
551 colnames(validationAll
) <- c('Correlation')
555 selectionPopResult
<- c()
556 selectionPopGEBVs
<- c()
557 selectionPopGEBVSE
<- c()
559 if (length(selectionData
) != 0) {
561 genoDataTrSl
<- rbind(genoDataFilteredObs
, selectionData
)
562 rTrSl
<- A
.mat(genoDataTrSl
)
564 selectionPopResult
<- kin
.blup(data
= phenoTrait
,
572 selectionPopGEBVs
<- round(data
.frame(selectionPopResult$g
), 2)
573 colnames(selectionPopGEBVs
) <- traitAbbr
574 selectionPopGEBVs
<- rownames_to_column(selectionPopGEBVs
, var
="genotypes")
576 selectionPopPEV
<- selectionPopResult$PEV
577 selectionPopSE
<- sqrt(selectionPopPEV
)
578 selectionPopSE
<- data
.frame(round(selectionPopSE
, 2))
579 colnames(selectionPopSE
) <- 'SE'
580 genotypesSl
<- rownames(selectionData
)
582 selectionPopSE
<- rownames_to_column(selectionPopSE
, var
="genotypes")
583 selectionPopSE
<- selectionPopSE
%>% filter(genotypes
%in% genotypesSl
)
585 selectionPopGEBVs
<- selectionPopGEBVs
%>% filter(genotypes
%in% genotypesSl
)
587 selectionPopGEBVSE
<- inner_join(selectionPopGEBVs
, selectionPopSE
, by
="genotypes")
589 sortVar
<- parse_quosure(traitAbbr
)
590 selectionPopGEBVs
<- selectionPopGEBVs
%>% arrange(desc((!!sortVar
)))
591 selectionPopGEBVs
<- column_to_rownames(selectionPopGEBVs
, var
="genotypes")
593 selectionPopGEBVSE
<- selectionPopGEBVSE
%>% arrange(desc((!!sortVar
)))
594 selectionPopGEBVSE
<- column_to_rownames(selectionPopGEBVSE
, var
="genotypes")
597 if (!is
.null(selectionPopGEBVs
) & length(selectionPopGEBVsFile
) != 0) {
598 fwrite(selectionPopGEBVs
,
599 file
= selectionPopGEBVsFile
,
606 if(!is
.null(validationAll
)) {
607 fwrite(validationAll
,
608 file
= validationFile
,
616 if (!is
.null(ordered
.markerEffects
)) {
617 fwrite(ordered
.markerEffects
,
626 if (!is
.null(trGEBV
)) {
635 if (length(combinedGebvsFile
) != 0 ) {
636 if(file
.info(combinedGebvsFile
)$size
== 0) {
638 file
= combinedGebvsFile
,
645 file
= combinedGebvsFile
,
654 if (!is
.null(modelPhenoData
) & length(modelPhenoFile
) != 0) {
656 if (!is
.null(meanType
)) {
657 colnames(modelPhenoData
) <- meanType
660 fwrite(modelPhenoData
,
661 file
= modelPhenoFile
,
669 if (!is
.null(filteredGenoData
) && is
.null(readFilteredGenoData
)) {
670 fwrite(filteredGenoData
,
671 file
= filteredGenoFile
,
679 ## if (length(filteredPredGenoFile) != 0 && is.null(readFilteredPredGenoData)) {
680 ## fwrite(filteredPredGenoData,
681 ## file = filteredPredGenoFile,
688 ## if (!is.null(genoDataMissing)) {
689 ## write.table(genoData,
698 ## if (!is.null(predictionDataMissing)) {
699 ## write.table(predictionData,
700 ## file = predictionFile,
708 if (file
.info(relationshipMatrixFile
)$size
== 0) {
710 fwrite(relationshipMatrix
,
711 file
= relationshipMatrixFile
,
718 if (file
.info(relationshipMatrixJsonFile
)$size
== 0) {
720 relationshipMatrixJson
<- relationshipMatrix
721 relationshipMatrixJson
[upper
.tri(relationshipMatrixJson
)] <- NA
724 relationshipMatrixJson
<- data
.frame(relationshipMatrixJson
)
726 relationshipMatrixList
<- list(labels
= names(relationshipMatrixJson
),
727 values
= relationshipMatrixJson
)
729 relationshipMatrixJson
<- jsonlite
::toJSON(relationshipMatrixList
)
732 write(relationshipMatrixJson
,
733 file
= relationshipMatrixJsonFile
,
738 if (file
.info(traitRelationshipMatrixFile
)$size
== 0) {
740 inbre
<- diag(traitRelationshipMatrix
)
743 diag(traitRelationshipMatrix
) <- inbre
745 traitRelationshipMatrix
<- data
.frame(traitRelationshipMatrix
) %>% replace(., . < 0, 0)
747 fwrite(traitRelationshipMatrix
,
748 file
= traitRelationshipMatrixFile
,
754 if (file
.info(traitRelationshipMatrixJsonFile
)$size
== 0) {
756 traitRelationshipMatrixJson
<- traitRelationshipMatrix
757 traitRelationshipMatrixJson
[upper
.tri(traitRelationshipMatrixJson
)] <- NA
759 traitRelationshipMatrixJson
<- data
.frame(traitRelationshipMatrixJson
)
761 traitRelationshipMatrixList
<- list(labels
= names(traitRelationshipMatrixJson
),
762 values
= traitRelationshipMatrixJson
)
764 traitRelationshipMatrixJson
<- jsonlite
::toJSON(traitRelationshipMatrixList
)
766 write(traitRelationshipMatrixJson
,
767 file
= traitRelationshipMatrixJsonFile
,
773 if (file
.info(inbreedingFile
)$size
== 0) {
776 file
= inbreedingFile
,
784 if (file
.info(aveKinshipFile
)$size
== 0) {
786 aveKinship
<- data
.frame(apply(traitRelationshipMatrix
, 1, mean
))
788 aveKinship
<- aveKinship
%>%
789 rownames_to_column('genotypes') %>%
790 rename(Mean_kinship
= contains('traitRe')) %>%
791 arrange(Mean_kinship
) %>%
792 mutate_at('Mean_kinship', round
, 3) %>%
793 column_to_rownames('genotypes')
796 file
= aveKinshipFile
,
804 if (file
.info(formattedPhenoFile
)$size
== 0 && !is
.null(formattedPhenoData
) ) {
805 fwrite(formattedPhenoData
,
806 file
= formattedPhenoFile
,
815 q(save
= "no", runLast
= FALSE)