畜牧兽医学报  2020, Vol. 51 Issue (8): 1804-1810. DOI: 10.11843/j.issn.0366-6964.2020.08.004    PDF    
大型基因组亲缘矩阵求逆算法的优化研究
周洁1, 曾维俊1, 杨天瑞1, 程郁斐1, 龙贤达1, 经佩齐1, 曾仰双2, 徐旭2, 唐国庆1     
1. 四川农业大学, 成都 611130;
2. 四川省畜牧总站, 成都 610041
摘要:基因组选择常用的评估方法GBLUP和ssGBLUP都涉及到基因组亲缘矩阵的求逆,而大规模矩阵求逆运算非常耗时。本研究以提高大型基因组亲缘矩阵求逆运算的效率为目的。本研究通过真实数据和模拟数据构建基因组亲缘矩阵,引入Intel MKL矩阵函数,以减少迭代次数(方法1)和重复分块(方法2)两种方式改良分块迭代求逆算法,编程实现算法并在台式电脑和服务器上测试计算时间。结果表明,利用方法1计算4 000×4 000的基因组亲缘矩阵逆矩阵时,与MKL库函数的加速比为0.898。而16 000×16 000矩阵的计算速度为MKL库函数的1.006倍。利用方法2计算4 000×4 000矩阵的运算速度是MKL库函数的1.084倍;而在更大型的128 000×128 000基因组亲缘矩阵求逆运算时,该方法与MKL直接求逆函数的加速比为1.805倍。相比于MKL直接求逆函数,改进后的两种方法在效率上有一定程度的提升。
关键词基因组选择    矩阵求逆    分块迭代求逆    
Optimization Study of Inverse Algorithm of Large Genomic Relationship Matrix
ZHOU Jie1, ZENG Weijun1, YANG Tianrui1, CHENG Yufei1, LONG Xianda1, JING Peiqi1, ZENG Yangshuang2, XU Xu2, TANG Guoqing1     
1. Sichuan Agricultural University, Chengdu 611130, China;
2. Sichuan Animal Husbandry Station, Chengdu 610041, China
Abstract: Both GBLUP and ssGBLUP methods involved in the inversion of genomic relationship matrices in genomic selection, and large-scale matrix inversion operations were time-consuming. The purpose of this study was to improve the efficiency of the inverse operation of large genomic relationship matrix. The genomic relationship matrix from real data and simulated data was constructed, and the Intel MKL matrix function was introduced, and the efficiency of matrix inversion was improved by reducing the number of iterations (method 1) and repeating the block (method 2), programming to implement algorithms and test computing time on desktop computers and servers. The results showed that the acceleration ratio of the direct inversion function with the MKL was 0.898 when calculating the genomic relationship matrix of 4 000×4 000 using method 1. The calculation speed of 16 000×16 000 was 1.006 times more than that of the inversion function in MKL; The calculation speed of method 2 in the 4 000×4 000 genomic relationship matrix was 1.084 times more than that of the MKL inversion function; For larger 128 000×128 000 matrix inversion operations, the acceleration ratio of this method was 1.805 times more than that of the inversion function in MKL. Compared with MKL direct inversion function, the improved two methods have higher efficiency.
Key words: genomic selection    matrix inversion    block iterative inverse    

随着基因分型技术的发展,成本随之降低[1],基因组选择逐渐成为畜禽育种的主流方法[2-9]。当前基因组选择应用最多的评估方法是一步基因组最佳线性无偏预测(ssGBLUP)[10-16],该方法在基因组最佳线性无偏预测(genome best linear unbiased prediction, GBLUP)方法的基础上将基因组分型和未分型的个体统一进行遗传评估[17-19],能进一步提高遗传评估的准确性[20-21],且和常规育种软件无缝衔接[22-24]。GBLUP和ssGBLUP都涉及到基因组亲缘矩阵(G)的求逆运算[25-26]。大规模矩阵求逆是一个十分耗时的过程[27],而育种具有时效性,随着数据的积累,快速进行基因组估计育种值(GEBV)估计是基因组选择亟待解决的问题。

大型稠密矩阵求逆对于计算设备的要求很高,计算时间长。在寄希望于计算设备发展更快、成本更低的同时,数量遗传学家也在尝试寻找更加高效、快速的算法,来实现G矩阵的求逆。更新法[28](updating the inverse)、APY法[29-30](algorithm for proven and young animals)、迭代法[31](recursive algorithm for approximation of inverse)等一系列方法都在一定程度上实现了G矩阵的快速求逆。更新法将新的基因分型个体增加到G-1中,避免了重新构建G矩阵与求逆的过程。该方法在实际生产中具有一定的应用价值,但并没有解决求逆效率问题。APY法将基因分型后的个体分为核心个体和非核心个体,利用分块矩阵的思想[32]将非核心个体的子块转化为一个对角矩阵,在损失一定准确性基础上提高了求逆的效率。张国亮等[33]提出了大型实对称矩阵分块迭代求逆算法,每次迭代一行元素,避免了矩阵直接求逆的过程,但大量的矩阵、向量相乘影响了大型矩阵的求逆效率。

本研究旨在在分块迭代求逆算法基础上寻找一种更高效的求逆方法,从而有效提高GEBV的估计效率。

1 材料与方法 1.1 数据来源与计算设备

利用VanRaden[34]报道的亲缘矩阵构建方法计算G矩阵,并通过与分子亲缘矩阵加权求和来避免矩阵奇异,G*=wG+(1-w)AG*为基因组亲缘矩阵和分子亲缘矩阵加权求和后的矩阵,w为权重,其值可取0.95或0.98[35]A为分子亲缘矩阵。本研究利用该方法对基因组亲缘矩阵及其对角子块进行加权处理,保证矩阵和各子块可逆,以便于后续方法验证。基因型数据分为两部分,其中4 000阶、8 000阶、12 000阶、16 000阶、32 000阶、64 000阶和128 000阶的矩阵所用基因型数据是使用QMSIM[36]模拟软件产生的模拟数据;剩余数据为1 734头猪的Geneseek 50K芯片数据,来源于各个猪场(四川江油新希望(971头)、浙江天蓬集团(604)、四川绵阳明兴农业(159头))。计算设备分为两部分:一是自用台式电脑,CPU为intel i7-8550U 1.8 GHz,内存8 GB;二是学校的公共服务器,CPU为intel Xeon E5-2630 2.6 GHz。

1.2 方法

1.2.1 方法1   分块迭代方法可以避免直接对矩阵进行求逆运算,但是其迭代的次数太多,每次迭代都涉及到矩阵的分块和组合以及子块间的乘法。减少迭代次数理论上能够提高求逆效率,同时引入intel数学核心函数库(MKL)解决子块直接求逆问题并进一步提高求逆效率。每一次分块都将pt分为一个2×2、3×3或者更大的矩阵(方法1),这样能有效减少迭代次数。公式:

$ \begin{array}{c} \mathit{\boldsymbol{W}}_t^{ - 1} = {\left[ {\begin{array}{*{20}{c}} {{\mathit{\boldsymbol{W}}_{t - 1}}}&{{\mathit{\boldsymbol{r}}_t}}\\ {\mathit{\boldsymbol{r}}_t^T}&{{\mathit{\boldsymbol{p}}_t}} \end{array}} \right]^{ - 1}} = \\ \left[ {\begin{array}{*{20}{c}} {\mathit{\boldsymbol{W}}_{t - 1}^{ - 1} + \mathit{\boldsymbol{W}}_{t - 1}^{ - 1}{\mathit{\boldsymbol{r}}_t}\mathit{\boldsymbol{\beta }}_t^{ - 1}\mathit{\boldsymbol{r}}_t^T\mathit{\boldsymbol{W}}_{t - 1}^{ - 1}}&{ - \mathit{\boldsymbol{W}}_{t - 1}^{ - 1}{\mathit{\boldsymbol{r}}_t}\mathit{\boldsymbol{\beta }}_t^{ - 1}}\\ { - \mathit{\boldsymbol{\beta }}_t^{ - 1}\mathit{\boldsymbol{r}}_t^T{\mathit{\boldsymbol{W}}_{t - 1}}}&{\mathit{\boldsymbol{\beta }}_t^{ - 1}} \end{array}} \right] \end{array} $ (1)
$ {\mathit{\boldsymbol{\beta }}_t} = {\mathit{\boldsymbol{p}}_t} - \mathit{\boldsymbol{r}}_t^T\mathit{\boldsymbol{W}}_{t - 1}^{ - 1}{\mathit{\boldsymbol{r}}_t} $ (2)

Wt-1为第t次迭代求逆完成后的逆矩阵,t表示迭代的次数,T表示转置矩阵。Wt-1rtptrtT为第t次迭代所用子块,βt为第t次迭代后逆矩阵的右下角子块。

1.2.2 方法2   对于一个N (N>0)阶矩阵,方法1中的pt最大阶数为N/2,此时矩阵被分为4个大小相等的矩阵,重复对左上角子块进行分块降阶,理论上可以进一步提高矩阵求逆的效率。进行m (m>0)次分块后需要直接求逆的矩阵的阶数为$ \frac{N}{{{2^m}}}$

$ {\mathit{\boldsymbol{G}}^{* - 1}} = {\left[ {\begin{array}{*{20}{c}} \mathit{\boldsymbol{a}}&\mathit{\boldsymbol{b}}\\ \mathit{\boldsymbol{c}}&\mathit{\boldsymbol{d}} \end{array}} \right]^{ - 1}} $ (3)
$ {\mathit{\boldsymbol{a}}^{ - 1}} = {\left[ {\begin{array}{*{20}{c}} \mathit{\boldsymbol{p}}&\mathit{\boldsymbol{q}}\\ \mathit{\boldsymbol{k}}&\mathit{\boldsymbol{l}} \end{array}} \right]^{ - 1}} $ (4)

G*-1为加权基因组亲缘矩阵的逆矩阵,abcdG*矩阵的子块,a-1为子块a的逆矩阵,pqkl为子块a的子矩阵块。两次分块后矩阵p的阶数为N/4。然后根据公式(1)和(2)求得a-1,继而求得G*-1

2 结果 2.1 方法1结果

根据张国亮等[33]的方法,用真实数据测试矩阵求逆的效率,可以看到随着子块pt阶数增加,矩阵求逆的效率明显提升。详细结果见图 1 (计算设备:台式电脑)。

n为子块pt的阶数;inv为直接调用MKL LAPACKE_dgetri函数,下同 n is the order of the sub-block; inv is to directly call the MKL LAPACKE_dgetri function, the same as below 图 1 真实数据方法1与inv方法效率对比 Fig. 1 Efficiency comparison between real data method 1 and inv method
2.2 方法2结果

将矩阵分成4个大小相等的子块,再对右上角的子块继续分块或直接求逆。为了使结果对比更加明显,本研究使用模拟数据来测试,并分开画图。可以发现,随着矩阵阶数增加,方法2的优势愈加明显,详细结果见图 2图 3(计算设备:服务器)。

m为矩阵分块的次数。下同 m is the number of times the matrix partitioned. The same as below 图 2 模拟数据方法2与inv方法效率对比 Fig. 2 Comparison of efficiency between method 2 and inv method for simulated data
图 3 模拟数据方法2与inv方法效率对比 Fig. 3 Comparison of efficiency between method 2 and inv method for simulated data

方法2在计算矩阵求逆上有更高的效率,4 000× 4 000的基因组亲缘矩阵求逆效率是inv方法的1.084倍;128 000×128 000的矩阵,与inv方法的加速比为1.805倍。但是计算效率并不会随迭代次数无限增加,64 000阶矩阵求逆效率随迭代次数先升高后降低,详细结果见图 4(计算设备:服务器)。

图 4 模拟数据方法2效率随分块次数变化趋势 Fig. 4 The efficiency changes of method 2 with the number of blocks for simulated data
2.3 方法1与方法2结果对比

方法1在计算4 000×4 000的基因组亲缘矩阵逆矩阵时,与inv方法的加速比为0.898。而16 000× 16 000的计算速度为inv方法的1.006倍。当方法1中pt的阶数等于方法2子块的阶数时,两种方法的计算思路和计算步骤完全一致,理论上两种方法在计算时间上应该非常接近。在实际测试中两种方法的计算效率存在差异,详细结果如图 5 (计算设备:台式电脑)。

n为方法1中子块的阶数;inv为直接调用MKL LAPACKE_dgetri函数;m为方法2中矩阵分块的次数 n is the order of the sub-blocks in method 1; inv is to directly call the MKL LAPACKE_dgetri function; m is the number of times the matrix partitioned in method 2 图 5 模拟数据两种方法的效率对比 Fig. 5 Efficiency comparison of two methods for simulated data
3 讨论

利用公式G*=wG+(1-w)AG矩阵处理后,可以避免矩阵奇异。当子块不可逆时,同样利用该公式对子块进行处理,A为分子亲缘矩阵中对应子块个体的元素,该方式能有效避免子块奇异且不影响后续评估GEBV[35]

在张国亮等[33]的报道中,700×700的矩阵求逆时间为3.506 s (计算设备:intel i5-3470),而在本研究中,方法1(n=3)计算885×885大小矩阵的逆时间为0.365 s。Meyer等[28]对10 000×10 000的矩阵直接求逆,消耗45 s,再用更新法在前面的逆矩阵基础上增加2 000阶,消耗44 s。最终完成一个12 000×12 000大小的矩阵求逆,消耗时间89 s(计算设备:intel i7-3930K)。在本研究中,方法2(m=3)计算12 000×12 000的矩阵逆消耗时间10.149 s。本研究的方法计算效率更高,但计算设备不同,因此该部分仅供参考。

通过图 2图 3来看,方法2比直接调用LAPACKE_dgetri函数具有一定的优势,且随着迭代次数的增加优势更加明显。对于一个N阶矩阵,矩阵乘法和矩阵求逆的复杂度都为O(N3)。基因组亲缘矩阵为对称矩阵,结合公式(1)和公式(2),一次分块后,方法2需要计算两次子块的求逆、4次子块间的乘法。因此,方法2(m=1)的复杂度为$ O\left( {{{\left( {\frac{N}{2}} \right)}^3} \times 6} \right) = O\left( {\frac{{3{N^3}}}{4}} \right)$。所以,理论上方法2比直接求逆效率更高,实际结果符合预期。

方法2要求被分块的矩阵为偶数,这在实际应用中存在一定限制。方法1可以任意分块,更符合实际情况。通过图 5可以看出,选择合适的pt阶数,方法1也能超越MKL函数直接求逆的效率,但和方法2 (m=1)相比仍然较低。两种方法在思路和步骤上几乎完全一致,但在分块方式上存在一定差异。方法1首先确定了子块d (公式(3))的大小,子块b的大小会随迭代逐渐增大。为了保证可以任意分块,子块db的赋值过程必须单独进行。方法2每次分块后子块db的阶数相同,因此赋值过程可以在同一个循环中完成。相比方法2,方法1每次迭代过程都要多出一个循环赋值的过程,这是方法2比方法1效率更高的原因。但方法2随着分块次数增加,矩阵求逆的效率先增加后降低(图 4)。可能原因是随着分块次数的增加,矩阵的分块与子块的组合消耗了过多的时间。对于不同大小的矩阵,其最佳分块次数是不同的,64 000×64 000的矩阵最佳分块次数是四次(图 4),但128 000×128 000 (图 3)的矩阵在第二次分块后效率开始降低。从图 2图 3图 4来看,最佳的分块次数出现在2~4次之间,最佳分块次数及其原理是下一步研究的方向。

4 结论

综上所述,方法1与方法2在效率上都能超越MKL中的直接求逆函数。方法2在效率上更具有优势,但其分块方式在实际应用中存在限制。在实际应用中,两种方法可以选择性使用。对于两种方法的进一步优化,应该从数据结构方面进行,降低内存的消耗、减少数据赋值的次数,进一步提高矩阵求逆的效率。

参考文献
[1] 张闻, 何永蜀, 陈元晓. 新一代DNA测序技术[J]. 国际遗传学杂志, 2009, 32(5): 341–344.
ZHANG W, HE Y S, CHEN Y X. New-generation DNA sequencing technology[J]. International Journal of Genetics, 2009, 32(5): 341–344. (in Chinese)
[2] 王晨, 秦珂, 薛明, 等. 全基因组选择在猪育种中的应用[J]. 畜牧兽医学报, 2016, 47(1): 1–9.
WANG C, QIN K, XUE M, et al. Application of genomic selection in swine breeding[J]. Acta Veterinaria et Zootechnica Sinica, 2016, 47(1): 1–9. (in Chinese)
[3] 赵晓铎, 张鹏, 吕昕哲, 等. 全基因组选择技术在牧场的应用[J]. 中国奶牛, 2019(7): 21–24.
ZHAO X D, ZHANG P, LV X Z, et al. New-generation dna sequencing technology[J]. China Dairy Cattle, 2019(7): 21–24. (in Chinese)
[4] MEUWISSEN T H, HAYES B J, GODDARD M E. Prediction of total genetic value using genome-wide dense marker maps[J]. Genetics, 2001, 157(4): 1819–1829.
[5] WIGGANS G R, COLE J B, HUBBARD S M, et al. Genomic selection in dairy cattle:the USDA experience[J]. Annu Rev Anim Biosci, 2017, 5: 309–327.
[6] ELSEN J M. Genomic selection-the final step or another step in an endless race?[J]. J Anim Breed Genet, 2018, 135(2): 95–96.
[7] 李宏伟, 王瑞军, 王志英, 等. 家畜基因组选择研究进展[J]. 遗传, 2017, 39(5): 377–387.
LI H W, WANG R J, WANG Z Y, et al. The research progress of genomic selection in livestock[J]. Hereditas (Beijing), 2017, 39(5): 377–387. (in Chinese)
[8] MISZTAL I, LEGARRA A. Invited review:efficient computation strategies in genomic selection[J]. Animal, 2017, 11(5): 731–736.
[9] WELLER J I, EZRA E, RON M. Invited review:a perspective on the future of genomic selection in dairy cattle[J]. J Dairy Sci, 2017, 100(11): 8633–8644.
[10] FRAGOMENI B D, LOURENCO D, TSURUTA S, et al. 0352 Genetics of heat stress in purebred and crossbred pigs from different states using BLUP or ssGBLUP[J]. J Anim Sci, 2016, 94(5): 169–170.
[11] KOIVULA M, STRANDÉN I, PÖSÖ J, et al. Single-step genomic evaluation using multitrait random regression model and test-day data[J]. J Dairy Sci, 2015, 98(4): 2775–2784.
[12] KOIVULA M, STRANDÉN I, AAMAND G P, et al.Comparison of ssGBLUP and ssGTBLUP using Nordic Holstein TD data[C]//Proceedings of the World Congress on Genetics Applied to Livestock Production.2018.
[13] HOWARD J T, RATHJE T A, BRUNS C E, et al. The impact of truncating data on the predictive ability of selection candidate EBV in swine using ssgblup[J]. J Anim Sci, 2018, 96(S2): 18–19.
[14] SOLLERO B P, HOWARD J T, SPANGLER M L. The impact of reducing the frequency of animals geno-typed at higher density on imputation and prediction accuracies using ssGBLUP[J]. J Anim Sci, 2019, 97(7): 2780–2792.
[15] BALOCHE G, LEGARRA A, SALLÉ G, et al. Assessment of accuracy of genomic prediction for French Lacaune dairy sheep[J]. J Dairy Sci, 2014, 97(2): 1107–1116.
[16] MASUDA Y, MISZTAL I, TSURUTA S, et al. Single-step genomic evaluations with 570K genotyped animals in US Holsteins[J]. Interbull Bulletin, 2015(49): 85–89.
[17] 潘荣杨, 张哲, 高宁, 等. 基因组选择一步法理论及应用研究进展[J]. 广东农业科学, 2016, 43(9): 124–131.
PAN R Y, ZHANG Z, GAO N, et al. Research progress in Single step procedure theory and application in genomic selection[J]. Guangdong Agricultural Sciences, 2016, 43(9): 124–131. (in Chinese)
[18] MISZTAL I, LEGARRA A, AGUILAR I. Computing procedures for genetic evaluation including phenotypic, full pedigree, and genomic information[J]. J Dairy Sci, 2009, 92(9): 4648–4655.
[19] LEGARRA A, AGUILAR I, MISZTAL I. A relationship matrix including full pedigree and genomic information[J]. J Dairy Sci, 2009, 92(9): 4656–4663.
[20] ZHANG X Y, LOURENCO D, AGUILAR I, et al. Weighting strategies for single-step genomic BLUP:an iterative approach for accurate calculation of GEBV and GWAS[J]. Front Genet, 2016, 7: 151.
[21] 彭潇, 尹立林, 梅全顺, 等. 猪主要经济性状的基因组选择研究[J]. 畜牧兽医学报, 2019, 50(2): 439–445.
PENG X, YIN L L, MEI Q S, et al. A study of genome selection based on the porcine major economic traits[J]. Acta Veterinaria et Zootechnica Sinica, 2019, 50(2): 439–445. (in Chinese)
[22] KINCAID D R, RESPESS J R, YOUNG D M.Itpack 2C: a FORTRAN package for solving large sparse linear systems by adaptative accelerated iterative methods[R]. Austin: University of Texas, 1997. https://dl.acm.org/doi/10.1145/356004.356009
[23] MADSEN P, JENSEN J, LABOURIAU R, et al.DMU-a package for analyzing multivariate mixed models in quantitative genetics and genomics[C]//Proceedings of the 10th World Congress of Genetics Applied to Livestock Production.2014: 18-22.
[24] 周学勇. 计算机在养猪生产管理和育种中的应用[J]. 现代农业科技, 2011(12): 34–35.
ZHOU X Y. Application of computer in pig production management and breeding[J]. Modern Agricultural Science and Technology, 2011(12): 34–35. (in Chinese)
[25] AGUILAR I, MISZTAL I, LEGARRA A, et al. Efficient computation of the genomic relationship matrix and other matrices used in single-step evaluation[J]. J Anim Breed Genet, 2011, 128(6): 422–428.
[26] FORNI S, AGUILAR I, MISZTAL I. Different genomic relationship matrices for single-step analysis using phenotypic, pedigree and genomic information[J]. Genet Sel Evol, 2011, 43(1): 1.
[27] MISZTAL I, TSURUTA S, AGUILAR I, et al. Methods to approximate reliabilities in single-step genomic evaluation[J]. J Dairy Sci, 2013, 96(1): 647–654.
[28] MEYER K, TIER B, GRASER H U. Technical note:updating the inverse of the genomic relationship matrix[J]. J Anim Sci, 2013, 91(6): 2583–2586.
[29] MISZTAL I. Inexpensive computation of the inverse of the genomic relationship matrix in populations with small effective population size[J]. Genetics, 2016, 202(2): 401–409.
[30] FRAGOMENI B O, LOURENCO D A L, TSURUTA S, et al. Use of genomic recursions and algorithm for proven and young animals for single-step genomic BLUP analyses-a simulation study[J]. J Anim Breed Genet, 2015, 132(5): 340–345.
[31] FAUX P, GENGLER N, MISZTAL I. A recursive algorithm for decomposition and creation of the inverse of the genomic relationship matrix[J]. J Dairy Sci, 2012, 95(10): 6093–6102.
[32] 毛汉清. 可逆矩阵的分块求逆方法研究[J]. 上海铁道学院学报, 1994, 15(3): 110–117.
MAO H Q. Research of methods to obtain an inverse matrix by partitioning an inversible matrix[J]. Journal of Shanghai Institute of Railway Technology, 1994, 15(3): 110–117. (in Chinese)
[33] 张国亮, 沈慧, 石峰, 等. 大型实对称矩阵分块迭代求逆算法[J]. 无线互联科技, 2015(6): 127–129.
ZHANG G L, SHEN H, SHI F, et al. Block iterative inverse algorithm for a iarge-scale real matrix[J]. Wireless Internet Technology, 2015(6): 127–129. (in Chinese)
[34] VANRADEN P M. Efficient methods to compute genomic predictions[J]. J Dairy Sci, 2008, 91(11): 4414–4423.
[35] AGUILAR I, MISZTAL I, JOHNSON D L, et al. Hot topic:a unified approach to utilize phenotypic, full pedigree, and genomic information for genetic evaluation of Holstein final score[J]. J Dairy Sci, 2010, 93(2): 743–752.
[36] SARGOLZAEI M, SCHENKEL F S. QMSim:a large-scale genome simulator for livestock[J]. Bioinformatics, 2009, 25(5): 680–681.
大型基因组亲缘矩阵求逆算法的优化研究
周洁, 曾维俊, 杨天瑞, 程郁斐, 龙贤达, 经佩齐, 曾仰双, 徐旭, 唐国庆