千家信息网

WGCNA如何获取关系矩阵

发表于:2024-11-28 作者:千家信息网编辑
千家信息网最后更新 2024年11月28日,这篇文章主要介绍WGCNA如何获取关系矩阵,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!在进行WGCNA分析的过程(学习WGCNA)中需要基于表达矩阵转换关系矩阵,结合powe
千家信息网最后更新 2024年11月28日WGCNA如何获取关系矩阵

这篇文章主要介绍WGCNA如何获取关系矩阵,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

在进行WGCNA分析的过程(学习WGCNA)中需要基于表达矩阵转换关系矩阵,结合power值构建邻接矩阵,并由此构建TOM矩阵最终构建网络。在代码实现的过程中往往:

1、计算power值

2、基于power直接利用adjacency()由表达矩阵--邻接矩阵,实现多步计算

但是如果想要关系矩阵呢?基于什么样的代码可以获得关系矩阵?并且不拘于WGCNA中?

可以基于cor 或者corAndPvalue(注意提前加载WGCNA包,否则函数无法使用)

案例数据:dat1

> dat1                 A       B        C        D          E         F        G        H         I        J         K       LCK-WT-1    3.74149 5.23528 2.821317 118.6600  1.8737693 1.7103460 30.26110  86.6405 1448.6278 173.9960  77.06166 3.19210CK-WT-2    7.36180 2.77070 1.563395 140.1430 16.9090246 0.7802436 33.65711 116.4700 1634.0417  51.0019  98.30970 4.69276CK-WT-3    5.81734 2.66859 1.931628 123.3830  0.9559375 2.7996091 31.46691 111.7380 1566.5626  52.3322 101.42702 3.58136CK-tdr1-1  5.71131 3.22632 3.194809  97.2229  0.4774184 4.7297117 30.96890  82.8809  648.4734  66.9486  46.86340 3.03234CK-tdr1-2  7.97054 1.32105 2.600854  95.2539  0.5273923 4.3637146 28.03340  85.7292  683.4113  41.1148  70.29293 2.11160CK-tdr1-3 10.37620 1.96726 2.301278  91.8525  0.4333881 3.3732144 27.62150  79.6027  647.2750  49.7169  57.09809 3.53808NaWT-1     6.29949 2.40259 2.044360 121.8080 39.1065780 2.2783575 35.59571 106.4650 1248.4062 192.7300 151.37454 4.79151NaWT-2     5.55062 3.23077 2.104095 125.1350 36.5302500 2.8043996 32.99440 111.3370 1117.6042 183.2700 160.54078 4.16132NaWT-3     5.84779 4.80378 2.630611 106.5070 19.4561309 2.9542534 32.77111  98.1677 1191.6926 111.2120 137.35694 3.40994Natdr1-1  15.58810 2.04301 2.289544  81.6997 13.2227038 3.1700429 19.02370  69.4519  501.2779  78.8024 101.08433 6.01932Natdr1-2  14.76360 2.29524 2.801336  84.8495 10.8897780 4.6643058 18.14860  69.7807  395.9033  96.2520  82.21420 5.59169Natdr1-3  17.74670 1.95286 2.450605  80.3895 12.2580100 4.0243357 15.79980  68.8929  468.8953  66.7984 108.79391 8.12127

1,计算矩阵内,每个对象(需计算的对象)--基因(或者其他)两两之间的相关性:相当于列两两之间计算

cor:pearson,构成一个12X12的对称2关系矩阵,行列皆为ABC.....,譬如A行,反应了基因A和ABC...12个基因之间的pearson相关性系数,如果需要进行pvalue值计算需要借助其他的函数

> correlationDat1=cor(dat1,method = "pearson",use="p")> correlationDat1            A           B           C          D           E          F          G          H          I             J          K             LA  1.00000000 -0.59583393  0.04210008 -0.7653767 -0.08993499  0.4431767 -0.9341117 -0.7344355 -0.7497806 -3.808723e-01 -0.1198969  8.083187e-01B -0.59583393  1.00000000  0.26970294  0.4147493  0.07036514 -0.4175610  0.4353225  0.2769349  0.5322412  5.188070e-01  0.1793751 -3.134547e-01C  0.04210008  0.26970294  1.00000000 -0.5854244 -0.43456495  0.6807807 -0.2927207 -0.6463363 -0.5398572  1.914220e-02 -0.4921559 -2.044431e-01D -0.76537665  0.41474925 -0.58542443  1.0000000  0.38000901 -0.8057937  0.8364376  0.9445312  0.9418587  3.742554e-01  0.4060881 -3.653468e-01E -0.08993499  0.07036514 -0.43456495  0.3800090  1.00000000 -0.3500579  0.2973247  0.4515257  0.2264080  6.947862e-01  0.9017631  3.043045e-01F  0.44317672 -0.41756097  0.68078073 -0.8057937 -0.35005795  1.0000000 -0.5485788 -0.6745604 -0.8450679 -3.474236e-01 -0.3917673  5.689610e-02G -0.93411169  0.43532253 -0.29272071  0.8364376  0.29732475 -0.5485788  1.0000000  0.8579521  0.7792997  3.536281e-01  0.2771652 -6.892251e-01H -0.73443549  0.27693490 -0.64633635  0.9445312  0.45152567 -0.6745604  0.8579521  1.0000000  0.8767053  2.816941e-01  0.5186044 -3.793407e-01I -0.74978056  0.53224125 -0.53985724  0.9418587  0.22640799 -0.8450679  0.7792997  0.8767053  1.0000000  3.127929e-01  0.3626986 -3.640842e-01J -0.38087228  0.51880702  0.01914220  0.3742554  0.69478622 -0.3474236  0.3536281  0.2816941  0.3127929  1.000000e+00  0.6315628 -8.267543e-05K -0.11989693  0.17937513 -0.49215586  0.4060881  0.90176313 -0.3917673  0.2771652  0.5186044  0.3626986  6.315628e-01  1.0000000  2.884711e-01L  0.80831868 -0.31345469 -0.20444309 -0.3653468  0.30430452  0.0568961 -0.6892251 -0.3793407 -0.3640842 -8.267543e-05  0.2884711  1.000000e+00

corAndPvalue:pearson 计算关系矩阵,同时可以获得pvalue值,返回结果是一个列表,包括关系矩阵cor以及p值矩阵等等。。。

> correlation_pvalueDat1=corAndPvalue(dat1,method="pearson",use="p")> correlation_pvalueDat1$cor            A           B           C          D           E          F          G          H          I             J          K             LA  1.00000000 -0.59583393  0.04210008 -0.7653767 -0.08993499  0.4431767 -0.9341117 -0.7344355 -0.7497806 -3.808723e-01 -0.1198969  8.083187e-01B -0.59583393  1.00000000  0.26970294  0.4147493  0.07036514 -0.4175610  0.4353225  0.2769349  0.5322412  5.188070e-01  0.1793751 -3.134547e-01C  0.04210008  0.26970294  1.00000000 -0.5854244 -0.43456495  0.6807807 -0.2927207 -0.6463363 -0.5398572  1.914220e-02 -0.4921559 -2.044431e-01D -0.76537665  0.41474925 -0.58542443  1.0000000  0.38000901 -0.8057937  0.8364376  0.9445312  0.9418587  3.742554e-01  0.4060881 -3.653468e-01E -0.08993499  0.07036514 -0.43456495  0.3800090  1.00000000 -0.3500579  0.2973247  0.4515257  0.2264080  6.947862e-01  0.9017631  3.043045e-01F  0.44317672 -0.41756097  0.68078073 -0.8057937 -0.35005795  1.0000000 -0.5485788 -0.6745604 -0.8450679 -3.474236e-01 -0.3917673  5.689610e-02G -0.93411169  0.43532253 -0.29272071  0.8364376  0.29732475 -0.5485788  1.0000000  0.8579521  0.7792997  3.536281e-01  0.2771652 -6.892251e-01H -0.73443549  0.27693490 -0.64633635  0.9445312  0.45152567 -0.6745604  0.8579521  1.0000000  0.8767053  2.816941e-01  0.5186044 -3.793407e-01I -0.74978056  0.53224125 -0.53985724  0.9418587  0.22640799 -0.8450679  0.7792997  0.8767053  1.0000000  3.127929e-01  0.3626986 -3.640842e-01J -0.38087228  0.51880702  0.01914220  0.3742554  0.69478622 -0.3474236  0.3536281  0.2816941  0.3127929  1.000000e+00  0.6315628 -8.267543e-05K -0.11989693  0.17937513 -0.49215586  0.4060881  0.90176313 -0.3917673  0.2771652  0.5186044  0.3626986  6.315628e-01  1.0000000  2.884711e-01L  0.80831868 -0.31345469 -0.20444309 -0.3653468  0.30430452  0.0568961 -0.6892251 -0.3793407 -0.3640842 -8.267543e-05  0.2884711  1.000000e+00> correlation_pvalueDat1$p             A            B          C            D            E            F            G            H            I            J            K           LA 0.000000e+00 4.090997e-02 0.89663878 3.717762e-03 7.810452e-01 1.490336e-01 8.749707e-06 6.524667e-03 4.984374e-03 2.219086e-01 7.105239e-01 0.001462577B 4.090997e-02 4.250614e-78 0.39657958 1.800527e-01 8.279739e-01 1.768190e-01 1.572339e-01 3.835336e-01 7.485940e-02 8.393536e-02 5.769666e-01 0.321137811C 8.966388e-01 3.965796e-01 0.00000000 4.551601e-02 1.580397e-01 1.480954e-02 3.558405e-01 2.314921e-02 7.002489e-02 9.529153e-01 1.040909e-01 0.523883036D 3.717762e-03 1.800527e-01 0.04551601 0.000000e+00 2.230453e-01 1.554408e-03 6.957492e-04 3.766304e-06 4.743703e-06 2.307106e-01 1.902444e-01 0.242885049E 7.810452e-01 8.279739e-01 0.15803968 2.230453e-01 0.000000e+00 2.646438e-01 3.479692e-01 1.406229e-01 4.791912e-01 1.215050e-02 6.097575e-05 0.336215639F 1.490336e-01 1.768190e-01 0.01480954 1.554408e-03 2.646438e-01 4.250614e-78 6.475768e-02 1.611867e-02 5.387507e-04 2.685031e-01 2.078626e-01 0.860584854G 8.749707e-06 1.572339e-01 0.35584053 6.957492e-04 3.479692e-01 6.475768e-02 1.328317e-79 3.570559e-04 2.808413e-03 2.594651e-01 3.831218e-01 0.013159937H 6.524667e-03 3.835336e-01 0.02314921 3.766304e-06 1.406229e-01 1.611867e-02 3.570559e-04 0.000000e+00 1.817921e-04 3.750706e-01 8.407771e-02 0.223927653I 4.984374e-03 7.485940e-02 0.07002489 4.743703e-06 4.791912e-01 5.387507e-04 2.808413e-03 1.817921e-04 1.328317e-79 3.222157e-01 2.465757e-01 0.244640498J 2.219086e-01 8.393536e-02 0.95291526 2.307106e-01 1.215050e-02 2.685031e-01 2.594651e-01 3.750706e-01 3.222157e-01 1.328317e-79 2.760873e-02 0.999796541K 7.105239e-01 5.769666e-01 0.10409092 1.902444e-01 6.097575e-05 2.078626e-01 3.831218e-01 8.407771e-02 2.465757e-01 2.760873e-02 0.000000e+00 0.363188744L 1.462577e-03 3.211378e-01 0.52388304 2.428850e-01 3.362156e-01 8.605849e-01 1.315994e-02 2.239277e-01 2.446405e-01 9.997965e-01 3.631887e-01 0.000000000

2、指定矩阵间,不同对象之间计算,譬如增加一个表达矩阵dat2,计算dat1中每一列和dat2每一列之间的关系矩阵,关系矩阵大小和两个表达矩阵的大小相关,N*n

案例数据2

> dat2                  a        b        c       d         e       f         g       h        i       j          k        lCK-WT-1   0.3664077 0.158906 261.9050 62.7705 2.0567778 20.7683  7.716667 2.93546 0.518056 34.6190 1.31144086 235.1950CK-WT-2   2.5206383 2.839320 309.9350 81.5834 1.2001859 13.5200 13.305652 3.78978 2.938810 27.3054 2.61589225 115.6060CK-WT-3   2.1481360 3.394500 367.1380 95.3128 1.4740055 15.9394  6.020028 4.44529 1.802080 34.2856 3.23541287  95.6566CK-tdr1-1 1.8667110 2.059980 203.5430 74.6182 0.9724999 21.5128  8.973298 2.68723 3.896400 33.0009 6.46792884 199.5490CK-tdr1-2 2.7575005 1.870370 155.1830 74.4062 1.3159845 24.0510  7.535809 3.52543 3.442310 26.4773 4.33091660 187.6910CK-tdr1-3 1.4235844 0.976982 169.6500 69.3025 1.8246997 27.4637  9.426074 1.67038 3.108840 24.4855 3.11069900 233.1310NaWT-1    6.2707832 2.722900 202.8050 83.0657 1.2524994 16.3550  6.280126 3.73328 1.925890 25.8537 0.24508389 304.0540NaWT-2    4.4219148 3.893780 191.2740 79.8487 0.7776743 10.1857  6.321488 3.53631 1.016500 25.6810 0.07114720 322.6570NaWT-3    2.5067114 2.505550 236.5250 84.3876 1.3424120 13.8600  7.992223 2.68571 1.086710 25.2199 2.19092550 265.5010Natdr1-1  8.2305000 2.181010  87.1744 31.3708 1.0394537 20.3689  3.763500 3.71247 3.540770 13.9571 0.05223847 528.9090Natdr1-2  6.5484678 2.403690  77.9025 36.0605 1.6192591 21.4447  2.804242 4.20718 3.683380 16.4149 0.29263051 495.8620Natdr1-3  6.9019060 0.957058  82.9502 28.5191 1.7537999 25.2101  3.427119 1.88249 4.067390 14.3850 0.44852888 450.5050

cor:计算dat1和dat2关系矩阵,获得abc....与ABC....两两之间的pearson相关性系数

> correlationDat1_Dat2=cor(dat1,dat2,method = "pearson",use="p")> correlationDat1_Dat2           a           b           c          d           e          f          g           h          i           j           k          lA  0.7459167 -0.24136960 -0.78655322 -0.8824599  0.17742322  0.5196762 -0.6056735 -0.17056393  0.7186029 -0.91460572 -0.41036887  0.7770714B -0.4926932 -0.11679240  0.46330810  0.2952698  0.15056629 -0.4349153  0.2484750 -0.10224860 -0.7517427  0.50163720 -0.01680050 -0.2224608C -0.1349988 -0.49651059 -0.40439381 -0.3221845  0.20345194  0.4804190 -0.2698939 -0.34944659  0.1821813  0.03611212  0.32205123  0.2443374D -0.4470417  0.46321502  0.84006166  0.7670363 -0.21724651 -0.7597254  0.6029082  0.39922064 -0.6650228  0.66305733  0.02854352 -0.6735202E  0.4818952  0.55257199 -0.07180092  0.1380915 -0.49039789 -0.6665837 -0.1167492  0.22591893 -0.3574666 -0.24193267 -0.62594452  0.2767556F  0.2543805 -0.12658907 -0.64016060 -0.4038207 -0.03896878  0.5644352 -0.5238938 -0.20049261  0.6083761 -0.33756962  0.27826251  0.3851291G -0.6119213  0.38961962  0.77990417  0.9410753 -0.30961086 -0.6075029  0.6926354  0.17115670 -0.6442575  0.79251674  0.33895247 -0.7716637H -0.3719534  0.65346000  0.81542226  0.8592102 -0.37566899 -0.8134974  0.5466699  0.41505782 -0.6131757  0.59674642  0.07831966 -0.6806705I -0.5109515  0.31466689  0.91777671  0.7399461 -0.01640227 -0.6843157  0.5486220  0.34573223 -0.7414820  0.69290258  0.02932018 -0.6927339J  0.1226988  0.12057442  0.03235788  0.1237968 -0.08205620 -0.4755465 -0.1882456  0.12871298 -0.6963563  0.13514402 -0.56466856  0.2079076K  0.4110099  0.57928237  0.08557449  0.2039083 -0.37884121 -0.7383462 -0.2207892  0.26160068 -0.5311611 -0.18339463 -0.65504786  0.2028440L  0.7953264 -0.06627007 -0.53006300 -0.7317357  0.09382376  0.1170781 -0.5519596 -0.09422415  0.4025131 -0.78324469 -0.65678340  0.7232087

corAndPvalue: 依然类似,返回两个矩阵列之间的关系矩阵和p值矩阵等等

> correlation_pvalueDat1_Dat2=corAndPvalue(dat1,dat2,method="pearson",use = "p")> correlation_pvalueDat1_Dat2$cor           a           b           c          d           e          f          g           h          i           j           k          lA  0.7459167 -0.24136960 -0.78655322 -0.8824599  0.17742322  0.5196762 -0.6056735 -0.17056393  0.7186029 -0.91460572 -0.41036887  0.7770714B -0.4926932 -0.11679240  0.46330810  0.2952698  0.15056629 -0.4349153  0.2484750 -0.10224860 -0.7517427  0.50163720 -0.01680050 -0.2224608C -0.1349988 -0.49651059 -0.40439381 -0.3221845  0.20345194  0.4804190 -0.2698939 -0.34944659  0.1821813  0.03611212  0.32205123  0.2443374D -0.4470417  0.46321502  0.84006166  0.7670363 -0.21724651 -0.7597254  0.6029082  0.39922064 -0.6650228  0.66305733  0.02854352 -0.6735202E  0.4818952  0.55257199 -0.07180092  0.1380915 -0.49039789 -0.6665837 -0.1167492  0.22591893 -0.3574666 -0.24193267 -0.62594452  0.2767556F  0.2543805 -0.12658907 -0.64016060 -0.4038207 -0.03896878  0.5644352 -0.5238938 -0.20049261  0.6083761 -0.33756962  0.27826251  0.3851291G -0.6119213  0.38961962  0.77990417  0.9410753 -0.30961086 -0.6075029  0.6926354  0.17115670 -0.6442575  0.79251674  0.33895247 -0.7716637H -0.3719534  0.65346000  0.81542226  0.8592102 -0.37566899 -0.8134974  0.5466699  0.41505782 -0.6131757  0.59674642  0.07831966 -0.6806705I -0.5109515  0.31466689  0.91777671  0.7399461 -0.01640227 -0.6843157  0.5486220  0.34573223 -0.7414820  0.69290258  0.02932018 -0.6927339J  0.1226988  0.12057442  0.03235788  0.1237968 -0.08205620 -0.4755465 -0.1882456  0.12871298 -0.6963563  0.13514402 -0.56466856  0.2079076K  0.4110099  0.57928237  0.08557449  0.2039083 -0.37884121 -0.7383462 -0.2207892  0.26160068 -0.5311611 -0.18339463 -0.65504786  0.2028440L  0.7953264 -0.06627007 -0.53006300 -0.7317357  0.09382376  0.1170781 -0.5519596 -0.09422415  0.4025131 -0.78324469 -0.65678340  0.7232087> correlation_pvalueDat1_Dat2$p            a          b            c            d         e           f          g         h           i            j          k           lA 0.005343145 0.44979253 0.0024077537 1.445930e-04 0.5811872 0.083326632 0.03686988 0.5961141 0.008463246 3.094278e-05 0.18516364 0.002941142B 0.103655491 0.71774480 0.1292845040 3.514709e-01 0.6404398 0.157666714 0.43613980 0.7518474 0.004809304 9.658536e-02 0.95867058 0.487090810C 0.675718069 0.10059700 0.1922789248 3.071058e-01 0.5259410 0.113907636 0.39623229 0.2655365 0.570920348 9.112847e-01 0.30731734 0.444065385D 0.145100960 0.12937166 0.0006260246 3.599014e-03 0.4976159 0.004144516 0.03797518 0.1985736 0.018288544 1.876101e-02 0.92983243 0.016345628E 0.112640644 0.06244015 0.8245113950 6.686591e-01 0.1055240 0.017919584 0.71784548 0.4801668 0.253963657 4.487033e-01 0.02945712 0.383854279F 0.424947701 0.69503317 0.0249443469 1.929701e-01 0.9042942 0.055895385 0.08041542 0.5321061 0.035812002 2.832246e-01 0.38116298 0.216354493G 0.034457419 0.21058742 0.0027732109 5.065274e-06 0.3274258 0.036151388 0.01253384 0.5948184 0.023742645 2.112357e-03 0.28113150 0.003283103H 0.233820856 0.02119734 0.0012264521 3.422783e-04 0.2288129 0.001287303 0.06588627 0.1796961 0.033987019 4.052267e-02 0.80882788 0.014832038I 0.089574366 0.31916867 0.0000257490 5.935397e-03 0.9596495 0.014101469 0.06473229 0.2709979 0.005778547 1.248574e-02 0.92792752 0.012516091J 0.704025631 0.70895097 0.9204803450 7.014839e-01 0.7998668 0.118156482 0.55794132 0.6901388 0.011876189 6.753860e-01 0.05577167 0.516716928K 0.184410086 0.04839925 0.7914492547 5.249929e-01 0.2245885 0.006102175 0.49045398 0.4114583 0.075563069 5.683139e-01 0.02077916 0.527205048L 0.001983196 0.83786471 0.0762830738 6.828905e-03 0.7717943 0.717079336 0.06279178 0.7708433 0.194552954 2.584682e-03 0.02032902 0.007860030

以上是"WGCNA如何获取关系矩阵"这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注行业资讯频道!

0