BLUP值是育種中最重要的概念,在實際的計算中我們往往需要計算多個性狀的Blup值,為了提高效率,之前我們介紹過如何批量分析多個性狀的遺傳力,今天小編再給大家介紹一下如何使用ASReml 軟體批量計算多個性狀的育種值,并儲存到本地。
模拟資料
使用asreml包中的harvey資料,另外模拟7個資料,合并一起,構成10個性狀的資料,用于分析示範。
library(asreml)
data("harvey")
dat = harvey
head(dat)
dd = as.data.frame(matrix(rnorm(7*65,10,5),65))
names(dd) = paste0("y",4:10)
head(dd)
dat1 = cbind(dat,dd)
head(dat1)
這裡,先對y1性狀進行分析,将Line和ageOfDam作為固定因子,将Sire作為随機因子,進行模型拟合。模型跑通後,再寫程式進行批量處理:
m1 = asreml(y1 ~ Line + ageOfDam,
random = ~ Sire,
residual = ~ idv(units),
data=dat1)
summary(m1)$varcomp
vpredict(m1,h2~4*V1/(V1+V2))
結果中儲存了方差組分和遺傳力,以及育種值BLUP。
library(asreml)
data("harvey")
dat = harvey
head(dat)
set.seed(123)
dd = as.data.frame(matrix(rnorm(7*65,10,5),65))
names(dd) = paste0("y",4:10)
dat1 = cbind(dat,dd)
head(dat1)
m1 = asreml(y1 ~ Line + ageOfDam,
random = ~ Sire,
residual = ~ idv(units),
na.action = na.method(x = "include",y = "include"),
data=dat1)
summary(m1)$varcomp
vpredict(m1,h2~4*V1/(V1+V2))
blup = as.data.frame(coef(m1)$random)
blup$ID = rownames(blup)
blup = blup[,c(2,1)]
head(blup)
nn = paste0("y",1:10)
nn
status1 = NULL
h2 = NULL
vc = NULL
blup_re = NULL
for(i in seq_along(nn)){
# i = 1
mod = asreml(formula(paste0(nn[i],"~ Line + ageOfDam")),
random = ~ Sire,
residual = ~ idv(units),
data=dat1)
vc[[i]] = summary(mod)$varcomp
status1[[i]] = mod$converge
h2[[i]] = vpredict(mod,h2 ~ 4*V1/(V1+V2))
blup = as.data.frame(coef(m1)$random)
blup$ID = rownames(blup)
blup = blup[,c(2,1)]
blup_re[[i]] = blup
}
names(status1) = nn
names(h2) = nn
names(vc) = nn
names(blup_re) = nn
re1 = do.call("rbind",h2)
re2 = do.call("rbind",status1)
re3 = do.call("rbind",vc)
re3
h2_result = cbind(re1,Converged = re2)
library(openxlsx)
write.xlsx(h2_result,"h2_result.xlsx")
write.xlsx(blup_re,"blup_result.xlsx")
結果檔案
* 遺傳力結果:h2_result.xsx
* 育種值結果:blup_result.xsx
上面的代碼,也可以修改為對個體動物模型進行多個性狀的批量處理。
ASReml-R近期提供免費試用活動,感興趣的老師私聊小編了解更多軟體試用詳情。