a b/tests/diffexp/test_meta.py
1
import unittest
2
3
import numpy as np
4
import pandas as pd
5
import patsy
6
7
from inmoose.deseq2 import DESeq, makeExampleDESeqDataSet
8
from inmoose.diffexp import DEResults, meta_de
9
from inmoose.edgepy import (
10
    DGEList,
11
    exactTest,
12
    glmLRT,
13
    glmQLFTest,
14
)
15
from inmoose.utils import Factor
16
17
18
class Test(unittest.TestCase):
19
    def test_meta_de(self):
20
        # test contrasts
21
        dds = makeExampleDESeqDataSet(n=200, m=12, seed=42)
22
        dds.obs["condition"] = Factor(np.repeat([1, 2, 3], 4))
23
        dds.obs["group"] = Factor(np.repeat([[1, 2]], 6, axis=0).flatten())
24
        dds.counts()[:, 0] = np.repeat([100, 200, 800], 4)
25
26
        dds.design = "~ group + condition"
27
28
        # DE with deseq
29
        dds = DESeq(dds)
30
        deseq_res = dds.results()
31
32
        # DE with edgepy
33
        d = DGEList(counts=dds.X.T, group=dds.obs["group"])
34
        d.design = patsy.dmatrix("~ group + condition", data=dds.obs)
35
        d = d.estimateGLMCommonDisp()
36
37
        # DE with edgepy (LRT)
38
        edgepy_lrt_res = glmLRT(d.glmFit())
39
40
        # DE with edgepy (QL FTest)
41
        edgepy_ql_res = glmQLFTest(d.glmQLFit())
42
43
        # DE with edgepy (exactTest)
44
        edgepy_et_res = exactTest(d)
45
46
        # meta-analysis
47
        des = [deseq_res, edgepy_lrt_res, edgepy_ql_res, edgepy_et_res]
48
        res = meta_de(des)
49
50
        # combined logFC and confidence intervals are controlled against metafor
51
        # adjusted p-values have no external control, and are tested for non-regression
52
        ref = pd.DataFrame(
53
            {
54
                "combined logFC (CI_L)": [
55
                    0.6660151964096146,
56
                    -2.6386163106710177,
57
                    -2.4294256191695074,
58
                    -0.6488512767501585,
59
                    -2.91706443340857,
60
                    -3.521554387539502,
61
                    -0.013715570856962955,
62
                    -2.44433271322974,
63
                    -3.0287062069792716,
64
                    -1.2632361321964904,
65
                    -0.4565657144319961,
66
                    -1.050526185309593,
67
                    -2.898567141180949,
68
                    -0.5981094405745551,
69
                    0.542876997367387,
70
                    -2.5842836601101418,
71
                    -1.4881728468777093,
72
                    0.2816630199971988,
73
                    -1.621914242625586,
74
                    -2.175531983553664,
75
                    -2.426621491203676,
76
                    -2.2862239530712416,
77
                    0.6061652115075944,
78
                    -1.7988866511533614,
79
                    -1.3911906679104926,
80
                    -1.6781046771044665,
81
                    -1.5607619003814168,
82
                    -2.7313354443639586,
83
                    -1.819587410152225,
84
                    -1.8461737799605058,
85
                    -2.396354475817337,
86
                    -4.150733072719027,
87
                    -0.866612921109145,
88
                    -1.6209230508004846,
89
                    -1.3932528679807576,
90
                    0.06535739301240662,
91
                    -0.8614695037171913,
92
                    -0.8949387070851511,
93
                    -0.1885094288572462,
94
                    -2.32066999356063,
95
                    -1.077924632221578,
96
                    0.37794895248328375,
97
                    -0.5536367454374285,
98
                    -0.21445770439079448,
99
                    -1.037823547101704,
100
                    -2.0371872963903646,
101
                    -2.4346661814814206,
102
                    -0.4321573992340394,
103
                    -0.2907332240528021,
104
                    -0.8539476086445773,
105
                    -1.234310858262552,
106
                    -2.7156517079926124,
107
                    -2.8582388336368183,
108
                    -1.2745838405371699,
109
                    -2.231898985996819,
110
                    -1.8279970283385685,
111
                    -4.480837497725425,
112
                    -0.8011169122478685,
113
                    -1.9799835053398835,
114
                    -1.0525039883843812,
115
                    -0.11662674646446902,
116
                    -2.544956075527203,
117
                    -1.064065093263388,
118
                    -0.8655309481531789,
119
                    -3.13762536071928,
120
                    -0.10540785386966345,
121
                    -2.518975904098701,
122
                    -2.0158475722803484,
123
                    -1.6728430608728435,
124
                    -0.5029904144572839,
125
                    -2.7112359453355257,
126
                    -1.608063992292449,
127
                    -0.12750004447413454,
128
                    -0.8225585773011765,
129
                    -1.772440064055683,
130
                    -0.9260166010678244,
131
                    -2.313239524972868,
132
                    -2.2068757891973796,
133
                    -1.786675849820731,
134
                    -1.0262766837558557,
135
                    -1.642001176385648,
136
                    0.2736409499254513,
137
                    -1.6755199304028023,
138
                    -2.4188282013360873,
139
                    -1.1577393065221067,
140
                    -2.243289671608783,
141
                    -1.5618172554069623,
142
                    -2.954474402652569,
143
                    -1.4590021786483582,
144
                    -2.371121434638752,
145
                    0.4108524092617336,
146
                    0.7039471918836333,
147
                    -1.773048451498628,
148
                    -0.3511337912563779,
149
                    -2.29667638756921,
150
                    -1.4953656452894795,
151
                    0.4109470746831836,
152
                    -1.620862282034234,
153
                    -4.385686353557798,
154
                    -1.264780589472257,
155
                    -1.0905046361675372,
156
                    -1.0403768171893486,
157
                    -1.9921809567227817,
158
                    -1.0215481046788315,
159
                    -1.6201315863839372,
160
                    -2.3497397485281812,
161
                    -0.9990128404438292,
162
                    -5.336487545760831,
163
                    -1.0623709246799449,
164
                    -0.4845713539981751,
165
                    -1.1092279063453114,
166
                    -3.022406150569415,
167
                    -0.7788181579284017,
168
                    -1.7145383153607154,
169
                    -1.3029315696858457,
170
                    -3.635458688461912,
171
                    -1.7449955806992654,
172
                    -0.37369875378310724,
173
                    -1.0063648668773697,
174
                    -3.121738602010506,
175
                    -0.9469631938814649,
176
                    -1.106923489229556,
177
                    -1.497550281217571,
178
                    -2.515290508312053,
179
                    -0.9689865181728943,
180
                    -0.04387428241650848,
181
                    -0.37155469916385075,
182
                    0.2678112004933926,
183
                    -2.385590578613881,
184
                    -0.9158592706903643,
185
                    -1.8301813463727143,
186
                    0.07460142020882277,
187
                    -1.8353686638038753,
188
                    -3.390945408814847,
189
                    0.02301767559765966,
190
                    -1.9324366910144262,
191
                    -0.678599506709188,
192
                    -2.309748259623439,
193
                    -1.2948255656204237,
194
                    0.35319753181102975,
195
                    -1.0127834932344837,
196
                    -2.176779495718015,
197
                    -1.5315051529282733,
198
                    0.6836811923317061,
199
                    -2.23977305266835,
200
                    -1.891197146518215,
201
                    -4.784144827741974,
202
                    -1.8037230037715726,
203
                    -1.9295223989664199,
204
                    -0.7340126641402587,
205
                    -1.8476750640373827,
206
                    -2.3842945946277867,
207
                    -1.2424865760658015,
208
                    -1.245280551728335,
209
                    -1.215932212899843,
210
                    -1.9632263729514479,
211
                    -1.801494956920078,
212
                    -0.2662585394490714,
213
                    -1.5599833295880043,
214
                    -4.881835644107957,
215
                    -3.7493825881515503,
216
                    -2.67304198399075,
217
                    -1.536839751850891,
218
                    -2.19184090843123,
219
                    -1.94974510590935,
220
                    -0.12555539343831423,
221
                    -2.7007627007566892,
222
                    -1.4724196092118091,
223
                    -1.1455256591450884,
224
                    -3.115445854154167,
225
                    -1.0084793313977904,
226
                    -0.3940975540315449,
227
                    0.2856517318181431,
228
                    -1.9711379193519085,
229
                    -3.7499696990142724,
230
                    -2.2126112079601503,
231
                    -0.8543495093303507,
232
                    -1.9283857091263117,
233
                    -2.264787656888103,
234
                    -3.7275147424298174,
235
                    -0.554008090864221,
236
                    -2.474562426499207,
237
                    -0.9685815584803881,
238
                    -0.989172560751711,
239
                    -0.7884366564329295,
240
                    -1.6045380562019598,
241
                    -0.7654273118624542,
242
                    -4.289165687959561,
243
                    -3.5234762679288174,
244
                    -1.3877715238168173,
245
                    -0.4356219067620921,
246
                    -0.4168421506416269,
247
                    0.1318434023527142,
248
                    -0.020915214579250163,
249
                    -0.9953178311101134,
250
                    -0.09157891037095012,
251
                    -0.43160817845695565,
252
                    -2.8193999937632803,
253
                    -0.9965176866672529,
254
                    -1.3939413540076844,
255
                ],
256
                "combined logFC (CI_R)": [
257
                    3.354872058019537,
258
                    -0.34054646318095894,
259
                    0.35083068561892405,
260
                    1.2758758057915247,
261
                    0.987419819649228,
262
                    -0.43883016404534936,
263
                    2.1355572315208398,
264
                    0.5080118956718125,
265
                    -0.534349148975036,
266
                    3.472246864111826,
267
                    1.536101548350488,
268
                    0.8515220599803147,
269
                    -0.8176581829870475,
270
                    1.447354013999258,
271
                    2.6303737680491617,
272
                    -0.036105150077430315,
273
                    0.49647965833900265,
274
                    3.0187769587400037,
275
                    0.38285920569357956,
276
                    -0.02243840495832705,
277
                    0.7756234225826169,
278
                    -0.03228481757257251,
279
                    2.56069239477196,
280
                    0.42803292672457405,
281
                    0.6664263638908428,
282
                    1.0336396693493475,
283
                    0.4703412064756911,
284
                    -0.7449809664746245,
285
                    1.2827268308386777,
286
                    0.22347520052144698,
287
                    -0.42579173099623957,
288
                    -1.0378149913948602,
289
                    1.474202085650837,
290
                    0.9832345898694661,
291
                    0.5979839574608838,
292
                    1.9537523108751609,
293
                    1.4094483690114512,
294
                    1.3045573581800696,
295
                    2.076718012172452,
296
                    -0.28070340978151154,
297
                    0.9447694039293841,
298
                    2.3437117766301405,
299
                    1.8183642690425976,
300
                    1.8861062700963296,
301
                    1.0774997747736272,
302
                    0.014536046442994888,
303
                    -0.3734987169876831,
304
                    1.6657293834968137,
305
                    1.7371529269569606,
306
                    1.6934459447290249,
307
                    0.7288005882108818,
308
                    -0.4582096934338016,
309
                    0.47222573634692555,
310
                    0.7525448340628036,
311
                    -0.05053394143011802,
312
                    0.666381149024404,
313
                    -0.3611533539173757,
314
                    1.1327677959957496,
315
                    1.9093349096061205,
316
                    1.6224956915201059,
317
                    2.8092931584641434,
318
                    -0.4675924133882219,
319
                    0.9556382394675933,
320
                    1.1537936002185782,
321
                    0.4719726272864868,
322
                    1.8940426428930035,
323
                    -0.370165159637702,
324
                    0.5148047144587685,
325
                    0.37474384949352624,
326
                    3.582528610121325,
327
                    1.266931510128373,
328
                    2.2158467226115492,
329
                    3.071101744852342,
330
                    1.1813346784457122,
331
                    0.18990362116929815,
332
                    1.1106002066088052,
333
                    -0.12768912119813525,
334
                    -0.1844407501803229,
335
                    0.25835875418293686,
336
                    1.1774869629070284,
337
                    0.3507702603130787,
338
                    2.7960199923829494,
339
                    0.6503959195118854,
340
                    -0.02699953769695007,
341
                    1.5711833206054435,
342
                    0.4520306257582095,
343
                    0.5672425711692818,
344
                    0.766116704264352,
345
                    0.5643657171094311,
346
                    -0.27795639060702126,
347
                    2.366747950705241,
348
                    2.77534421368124,
349
                    0.41134113503556835,
350
                    1.969588958548259,
351
                    1.2844090294384958,
352
                    0.9380549081602017,
353
                    3.274251586886894,
354
                    0.6590123200119615,
355
                    0.750549465611706,
356
                    2.018855699691608,
357
                    1.0562073319536494,
358
                    0.950802281270808,
359
                    0.5938590357378501,
360
                    1.0494322805270517,
361
                    1.5076695060610152,
362
                    0.9887948817674262,
363
                    4.264921321686238,
364
                    1.0328063734921642,
365
                    0.8621704647652939,
366
                    4.993500038553787,
367
                    0.9499110359553256,
368
                    -0.8997966342353689,
369
                    1.4795464281564392,
370
                    0.874904298760736,
371
                    0.7724717737068273,
372
                    0.8436676453709686,
373
                    0.38875016354958924,
374
                    1.6996550100286307,
375
                    1.0180844678588887,
376
                    -0.8432083259898191,
377
                    1.814332444242015,
378
                    0.89595219174541,
379
                    0.47768062281587376,
380
                    -0.6122504151106485,
381
                    0.9676127377450849,
382
                    1.9942096848086273,
383
                    2.5322997447126463,
384
                    2.6138264680652976,
385
                    0.06389822388153621,
386
                    1.3473614017305102,
387
                    0.2707537486533764,
388
                    4.160256742758929,
389
                    0.3225311846941912,
390
                    -0.916644886148936,
391
                    2.691811189135298,
392
                    0.5218401717051796,
393
                    1.2741589329453422,
394
                    0.12126997384548743,
395
                    0.5949804141792554,
396
                    2.316820003047362,
397
                    1.0110795928142386,
398
                    0.6586624521693996,
399
                    3.422985512826824,
400
                    2.7421890347062328,
401
                    1.5513174592326577,
402
                    0.25964239369840003,
403
                    0.20181520548352871,
404
                    0.9264018383524469,
405
                    0.015928832730718212,
406
                    1.28513806241418,
407
                    0.7355117760711144,
408
                    0.8107859106491883,
409
                    2.436102208526566,
410
                    1.0699877757552179,
411
                    0.8751364190659427,
412
                    0.05081803315723321,
413
                    0.22775593873046085,
414
                    1.6470249080421566,
415
                    1.8052433343747047,
416
                    -0.6862411763247649,
417
                    0.7657421312167374,
418
                    -0.48935736430145216,
419
                    0.3473665242861057,
420
                    0.9672738541238843,
421
                    0.37303455240566996,
422
                    2.348076008955688,
423
                    0.22513005048675083,
424
                    0.6067512405141617,
425
                    0.8955766331258332,
426
                    -0.6949808575425094,
427
                    1.313934433369968,
428
                    1.6405906148006886,
429
                    2.68193589852294,
430
                    0.7671934502323494,
431
                    2.818888058186232,
432
                    -0.18521862612875628,
433
                    1.0476709254412027,
434
                    0.5922832182532727,
435
                    -0.08490117418915877,
436
                    -0.7311606079226332,
437
                    1.3351236101816348,
438
                    -0.4398791608381776,
439
                    1.151171699680487,
440
                    1.743948784448906,
441
                    1.2591808745192232,
442
                    0.4065967359112883,
443
                    1.2607500621625511,
444
                    -1.182757686341431,
445
                    -0.9549093767155574,
446
                    0.5752653648553867,
447
                    1.4776432917947777,
448
                    1.8303526779984838,
449
                    2.45286628466279,
450
                    1.9298533345564415,
451
                    1.351808248409464,
452
                    2.2091228037508985,
453
                    1.5322246498088472,
454
                    -0.5191787229012983,
455
                    1.0055531958855577,
456
                    0.8993415317328557,
457
                ],
458
                "combined logFC": [
459
                    2.010443627214576,
460
                    -1.4895813869259882,
461
                    -1.0392974667752917,
462
                    0.31351226452068304,
463
                    -0.964822306879671,
464
                    -1.9801922757924255,
465
                    1.0609208303319384,
466
                    -0.9681604087789637,
467
                    -1.7815276779771538,
468
                    1.1045053659576676,
469
                    0.539767916959246,
470
                    -0.09950206266463923,
471
                    -1.8581126620839983,
472
                    0.4246222867123514,
473
                    1.5866253827082744,
474
                    -1.3101944050937862,
475
                    -0.4958465942693533,
476
                    1.6502199893686014,
477
                    -0.6195275184660032,
478
                    -1.0989851942559956,
479
                    -0.8254990343105295,
480
                    -1.159254385321907,
481
                    1.5834288031397772,
482
                    -0.6854268622143936,
483
                    -0.36238215200982493,
484
                    -0.32223250387755953,
485
                    -0.5452103469528629,
486
                    -1.7381582054192914,
487
                    -0.2684302896567735,
488
                    -0.8113492897195295,
489
                    -1.4110731034067885,
490
                    -2.5942740320569437,
491
                    0.303794582270846,
492
                    -0.3188442304655092,
493
                    -0.39763445525993685,
494
                    1.0095548519437838,
495
                    0.27398943264712994,
496
                    0.2048093255474592,
497
                    0.944104291657603,
498
                    -1.3006867016710706,
499
                    -0.06657761414609703,
500
                    1.3608303645567121,
501
                    0.6323637618025846,
502
                    0.8358242828527676,
503
                    0.019838113835961624,
504
                    -1.0113256249736848,
505
                    -1.4040824492345518,
506
                    0.6167859921313871,
507
                    0.7232098514520792,
508
                    0.41974916804222373,
509
                    -0.252755135025835,
510
                    -1.586930700713207,
511
                    -1.1930065486449464,
512
                    -0.26101950323718315,
513
                    -1.1412164637134685,
514
                    -0.5808079396570822,
515
                    -2.4209954258214,
516
                    0.1658254418739405,
517
                    -0.03532429786688163,
518
                    0.2849958515678623,
519
                    1.3463332059998372,
520
                    -1.5062742444577124,
521
                    -0.05421342689789732,
522
                    0.14413132603269962,
523
                    -1.3328263667163966,
524
                    0.89431739451167,
525
                    -1.4445705318682016,
526
                    -0.7505214289107899,
527
                    -0.6490496056896586,
528
                    1.5397690978320207,
529
                    -0.7221522176035764,
530
                    0.30389136515955006,
531
                    1.4718008501891038,
532
                    0.1793880505722678,
533
                    -0.7912682214431924,
534
                    0.0922918027704904,
535
                    -1.2204643230855017,
536
                    -1.1956582696888511,
537
                    -0.764158547818897,
538
                    0.07560513957558634,
539
                    -0.6456154580362846,
540
                    1.5348304711542002,
541
                    -0.5125620054454585,
542
                    -1.2229138695165187,
543
                    0.20672200704166846,
544
                    -0.8956295229252867,
545
                    -0.4972873421188403,
546
                    -1.0941788491941085,
547
                    -0.44731823076946353,
548
                    -1.3245389126228866,
549
                    1.3888001799834873,
550
                    1.7396457027824366,
551
                    -0.6808536582315298,
552
                    0.8092275836459406,
553
                    -0.5061336790653573,
554
                    -0.27865536856463896,
555
                    1.842599330785039,
556
                    -0.4809249810111363,
557
                    -1.817568443973046,
558
                    0.3770375551096756,
559
                    -0.017148652106944023,
560
                    -0.044787267959270266,
561
                    -0.6991609604924658,
562
                    0.01394208792411003,
563
                    -0.056231040161460966,
564
                    -0.6804724333803774,
565
                    1.6329542406212045,
566
                    -2.1518405861343335,
567
                    -0.10010022995732543,
568
                    2.2544643422778057,
569
                    -0.07965843519499288,
570
                    -1.961101392402392,
571
                    0.3503641351140188,
572
                    -0.41981700829998975,
573
                    -0.26522989798950924,
574
                    -1.3958955215454716,
575
                    -0.6781227085748381,
576
                    0.6629781281227617,
577
                    0.005859800490759473,
578
                    -1.9824734640001627,
579
                    0.43368462518027506,
580
                    -0.10548564874207311,
581
                    -0.5099348292008486,
582
                    -1.5637704617113508,
583
                    -0.0006868902139046985,
584
                    0.9751677011960594,
585
                    1.0803725227743979,
586
                    1.440818834279345,
587
                    -1.1608461773661722,
588
                    0.21575106552007295,
589
                    -0.779713798859669,
590
                    2.117429081483876,
591
                    -0.7564187395548421,
592
                    -2.1537951474818917,
593
                    1.357414432366479,
594
                    -0.7052982596546232,
595
                    0.29777971311807716,
596
                    -1.094239142888976,
597
                    -0.3499225757205842,
598
                    1.3350087674291957,
599
                    -0.0008519502101226178,
600
                    -0.7590585217743078,
601
                    0.9457401799492752,
602
                    1.7129351135189694,
603
                    -0.3442277967178461,
604
                    -0.8157773764099074,
605
                    -2.2911648111292227,
606
                    -0.43866058270956276,
607
                    -0.9567967831178508,
608
                    0.2755626991369606,
609
                    -0.5560816439831341,
610
                    -0.7867543419892992,
611
                    0.5968078162303823,
612
                    -0.08764638798655852,
613
                    -0.17039789691695012,
614
                    -0.9562041698971073,
615
                    -0.7868695090948086,
616
                    0.6903831842965426,
617
                    0.12263000239335031,
618
                    -2.7840384102163607,
619
                    -1.4918202284674065,
620
                    -1.5811996741461012,
621
                    -0.5947366137823926,
622
                    -0.6122835271536728,
623
                    -0.78835527675184,
624
                    1.111260307758687,
625
                    -1.2378163251349692,
626
                    -0.4328341843488237,
627
                    -0.12497451300962753,
628
                    -1.9052133558483382,
629
                    0.15272755098608884,
630
                    0.6232465303845719,
631
                    1.4837938151705414,
632
                    -0.6019722345597796,
633
                    -0.4655408204140199,
634
                    -1.1989149170444533,
635
                    0.09666070805542601,
636
                    -0.6680512454365195,
637
                    -1.1748444155386308,
638
                    -2.2293376751762253,
639
                    0.390557759658707,
640
                    -1.4572207936686923,
641
                    0.09129507060004953,
642
                    0.37738811184859755,
643
                    0.23537210904314693,
644
                    -0.5989706601453357,
645
                    0.2476613751500485,
646
                    -2.735961687150496,
647
                    -2.2391928223221873,
648
                    -0.4062530794807153,
649
                    0.5210106925163428,
650
                    0.7067552636784284,
651
                    1.292354843507752,
652
                    0.9544690599885957,
653
                    0.1782452086496753,
654
                    1.0587719466899743,
655
                    0.5503082356759458,
656
                    -1.6692893583322892,
657
                    0.00451775460915238,
658
                    -0.24729991113741429,
659
                ],
660
                "adjusted combined pval": [
661
                    0.002710867577467824,
662
                    0.5286922590236601,
663
                    0.3635268253933128,
664
                    0.9999997373138294,
665
                    0.9999997373138294,
666
                    0.40841535987809763,
667
                    0.8552303143709908,
668
                    0.45397729003343607,
669
                    0.249091508520245,
670
                    0.2061819814543404,
671
                    0.9999997373138294,
672
                    0.9999997373138294,
673
                    0.249091508520245,
674
                    0.9999997373138294,
675
                    0.40841535987809763,
676
                    0.7200961165080368,
677
                    0.9999997373138294,
678
                    0.5115953505542589,
679
                    0.9999997373138294,
680
                    0.845756654704669,
681
                    0.5676481671711865,
682
                    0.8395655047552425,
683
                    0.36422621419559664,
684
                    0.9999997373138294,
685
                    0.9999997373138294,
686
                    0.9239752719474906,
687
                    0.9999997373138294,
688
                    0.2321774685303417,
689
                    0.5115953505542589,
690
                    0.9239752719474906,
691
                    0.5070330046729763,
692
                    0.09174034333551025,
693
                    0.9999997373138294,
694
                    0.9999997373138294,
695
                    0.9999997373138294,
696
                    0.7200961165080368,
697
                    0.9999997373138294,
698
                    0.9999997373138294,
699
                    0.9999997373138294,
700
                    0.6847287526005329,
701
                    0.9999997373138294,
702
                    0.5442138166006407,
703
                    0.9999997373138294,
704
                    0.9999997373138294,
705
                    0.9999997373138294,
706
                    0.9658912215110148,
707
                    0.5892132685871182,
708
                    0.9999997373138294,
709
                    0.9999997373138294,
710
                    0.8063836512383536,
711
                    0.9999997373138294,
712
                    0.3635268253933128,
713
                    0.878906678789298,
714
                    0.9999997373138294,
715
                    0.845756654704669,
716
                    0.9999997373138294,
717
                    0.02353676743785122,
718
                    0.9999997373138294,
719
                    0.4372483768805375,
720
                    0.6899654596418524,
721
                    0.9239752719474906,
722
                    0.5115953505542589,
723
                    0.9999997373138294,
724
                    0.9999997373138294,
725
                    0.19158373821572414,
726
                    0.9999997373138294,
727
                    0.6681718367617152,
728
                    0.7139678179747181,
729
                    0.9999997373138294,
730
                    0.14361191965472642,
731
                    0.5626777439383062,
732
                    0.9999997373138294,
733
                    0.5115953505542589,
734
                    0.9999997373138294,
735
                    0.9999997373138294,
736
                    0.9999997373138294,
737
                    0.8395655047552425,
738
                    0.6847287526005329,
739
                    0.9999997373138294,
740
                    0.9999997373138294,
741
                    0.9999997373138294,
742
                    0.6847287526005329,
743
                    0.9999997373138294,
744
                    0.45397729003343607,
745
                    0.9999997373138294,
746
                    0.5115953505542589,
747
                    0.9999997373138294,
748
                    0.19266295410826276,
749
                    0.9999997373138294,
750
                    0.6847287526005329,
751
                    0.5274203426647385,
752
                    0.33573852446575575,
753
                    0.9999997373138294,
754
                    0.9999997373138294,
755
                    0.9999997373138294,
756
                    0.9999997373138294,
757
                    0.5115953505542589,
758
                    0.9999997373138294,
759
                    0.01737015553722674,
760
                    0.9999997373138294,
761
                    0.9999997373138294,
762
                    0.9999997373138294,
763
                    0.9999997373138294,
764
                    0.9999997373138294,
765
                    0.845756654704669,
766
                    0.5306621528598132,
767
                    0.13720519336046125,
768
                    0.014432955706249317,
769
                    0.9999997373138294,
770
                    0.249091508520245,
771
                    0.9999997373138294,
772
                    0.29234617948435815,
773
                    0.9999997373138294,
774
                    0.9999997373138294,
775
                    0.9999997373138294,
776
                    0.18171356404052635,
777
                    0.9999997373138294,
778
                    0.9999997373138294,
779
                    0.9999997373138294,
780
                    0.249091508520245,
781
                    0.9999997373138294,
782
                    0.9999997373138294,
783
                    0.9999997373138294,
784
                    0.249091508520245,
785
                    0.9999997373138294,
786
                    0.9550708068178158,
787
                    0.45143711607921805,
788
                    0.6761159592036801,
789
                    0.9999997373138294,
790
                    0.9999997373138294,
791
                    0.9999997373138294,
792
                    0.14764567543600687,
793
                    0.8655808208804949,
794
                    0.13720519336046125,
795
                    0.7952134754914685,
796
                    0.9999997373138294,
797
                    0.9999997373138294,
798
                    0.4372483768805375,
799
                    0.9999997373138294,
800
                    0.5442138166006407,
801
                    0.9999997373138294,
802
                    0.7200961165080368,
803
                    0.9999997373138294,
804
                    0.4372483768805375,
805
                    0.9999997373138294,
806
                    0.9999997373138294,
807
                    0.04693144675687698,
808
                    0.8395655047552425,
809
                    0.8395655047552425,
810
                    0.9999997373138294,
811
                    0.8395655047552425,
812
                    0.6210330306914035,
813
                    0.9999997373138294,
814
                    0.9999997373138294,
815
                    0.9999997373138294,
816
                    0.9681522788336918,
817
                    0.9999997373138294,
818
                    0.9999997373138294,
819
                    0.7223703085727059,
820
                    0.02353676743785122,
821
                    0.19266295410826276,
822
                    0.4993454158594806,
823
                    0.9999997373138294,
824
                    0.878906678789298,
825
                    0.5115953505542589,
826
                    0.9999997373138294,
827
                    0.29234617948435815,
828
                    0.9999997373138294,
829
                    0.9999997373138294,
830
                    0.19266295410826276,
831
                    0.9999997373138294,
832
                    0.9999997373138294,
833
                    0.7200961165080368,
834
                    0.9999997373138294,
835
                    0.03371060943211578,
836
                    0.7200961165080368,
837
                    0.9999997373138294,
838
                    0.7200961165080368,
839
                    0.9550708068178158,
840
                    0.18171356404052635,
841
                    0.9999997373138294,
842
                    0.5306621528598132,
843
                    0.9999997373138294,
844
                    0.7200961165080368,
845
                    0.9999997373138294,
846
                    0.9850862188123334,
847
                    0.9999997373138294,
848
                    0.04693144675687698,
849
                    0.19266295410826276,
850
                    0.9999997373138294,
851
                    0.9999997373138294,
852
                    0.9999997373138294,
853
                    0.8280732314616722,
854
                    0.9327511393735692,
855
                    0.9999997373138294,
856
                    0.9999997373138294,
857
                    0.9999997373138294,
858
                    0.5115953505542589,
859
                    0.9999997373138294,
860
                    0.9999997373138294,
861
                ],
862
            },
863
            index=[f"gene{i}" for i in range(200)],
864
        )
865
        pd.testing.assert_frame_equal(res, ref, rtol=1e-4)
866
867
    def test_meta_de_nan(self):
868
        """check robustness of meta_de to NaN values"""
869
        idx = ["gene1", "gene2", "gene3"]
870
        res1 = DEResults(
871
            {
872
                "log2FoldChange": [1.0, np.nan, 3.0],
873
                "lfcSE": [0.5, np.nan, 0.5],
874
                "pvalue": [0.1, np.nan, 0.2],
875
            },
876
            index=idx,
877
        )
878
        res2 = DEResults(
879
            {
880
                "log2FoldChange": [2.0, 3.0, 4.0],
881
                "lfcSE": [0.5, 0.5, 0.5],
882
                "pvalue": [0.1, 0.15, 0.2],
883
            },
884
            index=idx,
885
        )
886
        res3 = DEResults(
887
            {
888
                "log2FoldChange": [3.0, np.nan, 5.0],
889
                "lfcSE": [0.5, np.nan, 0.5],
890
                "pvalue": [0.2, np.nan, 0.1],
891
            },
892
            index=idx,
893
        )
894
        meta1 = meta_de([res1, res2, res3])
895
        meta2 = meta_de([res1, res3])
896
        ref1 = pd.DataFrame(
897
            {
898
                "combined logFC (CI_L)": [
899
                    0.8684142716330685,
900
                    np.nan,
901
                    2.868414271633068,
902
                ],
903
                "combined logFC (CI_R)": [
904
                    3.1315857283669315,
905
                    np.nan,
906
                    5.131585728366931,
907
                ],
908
                "combined logFC": [2, np.nan, 4],
909
                "adjusted combined pval": [
910
                    0.13058835750961412,
911
                    0.15,
912
                    0.13058835750961412,
913
                ],
914
            },
915
            index=idx,
916
        )
917
        ref2 = pd.DataFrame(
918
            {
919
                "combined logFC (CI_L)": [
920
                    0.0400360524639638,
921
                    np.nan,
922
                    2.0400360524639636,
923
                ],
924
                "combined logFC (CI_R)": [
925
                    3.9599639475360364,
926
                    np.nan,
927
                    5.959963947536036,
928
                ],
929
                "combined logFC": [2, np.nan, 4],
930
                "adjusted combined pval": [
931
                    0.09824046010856295,
932
                    np.nan,
933
                    0.09824046010856295,
934
                ],
935
            },
936
            index=idx,
937
        )
938
        pd.testing.assert_frame_equal(meta1, ref1)
939
        pd.testing.assert_frame_equal(meta2, ref2)