Skip to content

FinnGen Meta Analysis Manifest

gentropy.datasource.finngen_meta.FinnGenMetaManifest

FinnGen meta-analysis manifest.

Source code in src/gentropy/datasource/finngen_meta/__init__.py
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
class FinnGenMetaManifest:
    """FinnGen meta-analysis manifest."""

    ukbb_ancestry_cols = {
        "ukbb_n_cases",
        "ukbb_n_controls",
    }

    finngen_ancestry_cols = {
        "fg_n_cases",
        "fg_n_controls",
    }

    required_columns = {
        "fg_phenotype",  # Original Finngen studyId (e.g. "I9_HEARTFAIL")
        "name",  # Finngen phenotype name - used for mapping to EFO
        # Ancestry columns for finngen and UKBB (should be in both meta analyses)
        *finngen_ancestry_cols,
        *ukbb_ancestry_cols,
    }

    mvp_ancestry_columns = {
        "MVP_AFR_n_cases",
        "MVP_AFR_n_controls",
        "MVP_EUR_n_cases",
        "MVP_EUR_n_controls",
        "MVP_AMR_n_cases",
        "MVP_AMR_n_controls",
    }
    sumstat_location_column = "path_bucket"

    def __init__(self, df: DataFrame, meta: MetaAnalysisDataSource) -> None:
        """Initialize the FinnGen meta-analysis manifest.

        Args:
            df (DataFrame): DataFrame containing the manifest data.
            meta (MetaAnalysisDataSource): Meta-analysis data source enum.
        """
        self.meta = meta
        self._df = df

    @property
    def df(self) -> DataFrame:
        """Get the manifest DataFrame.

        The resulting DataFrame has the following schema:
        ```
        |-- studyPhenotype: string (nullable = true)
        |-- traitFromSource: string (nullable = true)
        |-- discoverySamples: array (nullable = true)
            |-- element: struct (containsNull = true)
                |-- sampleSize: integer (nullable = true)
                |-- ancestry: string (nullable = true)
        |-- nSamples: integer (nullable = true)
        |-- nCases: integer (nullable = true)
        |-- nSamplesPerCohort: array (nullable = true)
            |-- element: struct (containsNull = true)
                |-- cohort: string (nullable = true)
                |-- nSamples: integer (nullable = true)
        |-- nCasesPerCohort: array (nullable = true)
            |-- element: struct (containsNull = true)
                |-- cohort: string (nullable = true)
                |-- nCases: integer (nullable = true)
        |-- nControls: integer (nullable = true)
        |-- hasSumstats: boolean (nullable = true)
        |-- summarystatsLocation: string (nullable = true)  # may be null if not provided in the manifest
        ```
        """
        return self._df.select(
            self.study_id.alias("studyId"),
            self.project_id.alias("projectId"),
            self.trait_from_source.alias("traitFromSource"),
            self.discovery_samples.alias("discoverySamples"),
            self.n_samples.alias("nSamples"),
            self.n_samples_per_cohort.alias("nSamplesPerCohort"),
            self.n_cases.alias("nCases"),
            self.n_cases_per_cohort.alias("nCasesPerCohort"),
            self.n_controls.alias("nControls"),
            self.summary_statistics_location.alias("summarystatsLocation"),
            self.has_summary_statistics.alias("hasSumstats"),
        )

    @classmethod
    def from_path(cls, session: Session, manifest_path: str) -> FinnGenMetaManifest:
        """Load the FinnGen meta-analysis manifest from a specified path.

        Note:
            This method asserts that the manifest file is tab-delimited and contains header with following columns:
            ```
            |-- fg_phenotype: string (nullable = true)        # required
            |-- name: string (nullable = true)                # required
            |-- fg_n_cases: integer (nullable = true)         # required
            |-- fg_n_controls: integer (nullable = true)      # required
            |-- ukbb_n_cases: integer (nullable = true)       # required
            |-- ukbb_n_controls: integer (nullable = true)    # required
            |-- MVP_AFR_n_cases: integer (nullable = true)    # optional
            |-- MVP_AFR_n_controls: integer (nullable = true) # optional
            |-- MVP_EUR_n_cases: integer (nullable = true)    # optional
            |-- MVP_EUR_n_controls: integer (nullable = true) # optional
            |-- MVP_AMR_n_cases: integer (nullable = true)    # optional
            |-- MVP_AMR_n_controls: integer (nullable = true) # optional
            |-- path_bucket: string (nullable = true)         # optional
            ```
        Args:
            session (Session): Session object.
            manifest_path (str): Path to the manifest file.

        Returns:
            FinngenMetaManifest: Loaded manifest object.

        Raises:
            AssertionError: If the manifest file does not contain the required columns.
            AssertionError: If the manifest file does not contain the required columns.
        """
        df = (
            session.spark.read.option("header", True)
            .option("sep", "\t")
            .csv(manifest_path)
        )
        assert cls.required_columns.issubset(set(df.columns)), (
            f"Manifest file must contain the following columns: {cls.required_columns}. "
        )

        # By default we assume we are dealing with the FinnGen UKBB meta-analysis
        meta = MetaAnalysisDataSource.FINNGEN_UKBB
        columns = [*cls.required_columns]

        # If we have the MVP ancestry columns, then we are dealing with the FinnGen UKBB MVP meta-analysis
        if cls.mvp_ancestry_columns.issubset(set(df.columns)):
            meta = MetaAnalysisDataSource.FINNGEN_UKBB_MVP
            columns += [*cls.mvp_ancestry_columns]

        column_map = [
            f.col(col).cast(t.IntegerType()).alias(col)
            if "n_cases" in col or "n_controls" in col
            else f.col(col).cast(t.StringType()).alias(col)
            for col in columns
        ]

        # Handle the summary statistics location.
        if cls.sumstat_location_column in df.columns:
            column_map.append(
                f.col(cls.sumstat_location_column)
                .cast(t.StringType())
                .alias(cls.sumstat_location_column)
            )
        else:
            session.logger.warning(
                f"Manifest file does not contain the '{cls.sumstat_location_column}' column. Can not determine summary statistics location."
            )
            column_map.append(f.lit(None).alias(cls.sumstat_location_column))

        df = df.select(*column_map)  # Final contract
        return cls(df=df, meta=meta)

    @property
    def discovery_samples(self) -> Column:
        """Get the discovery samples.

        This method dispatches to the appropriate private method based on the meta-analysis data source.

        Returns:
            Column: Spark Column representing the discovery samples.
        """
        if self.meta == MetaAnalysisDataSource.FINNGEN_UKBB:
            return self._discovery_samples_finngen_ukbb()
        elif self.meta == MetaAnalysisDataSource.FINNGEN_UKBB_MVP:
            return self._discovery_samples_finngen_ukbb_mvp()
        else:
            raise ValueError(f"Unsupported meta-analysis data source: {self.meta}")

    @staticmethod
    def _add(*cols: Column) -> Column:
        """Get the total number of samples from multiple columns.

        Args:
            *cols (Column): Columns to sum.

        Returns:
            Column: Column representing the total number of samples.


        Examples:
            >>> df = spark.createDataFrame([(1, 2, 3), (1, 2, None)], ["a", "b", "c"])
            >>> df.select(FinnGenMetaManifest._add(f.col("a"), f.col("b"), f.col("c")).alias("total")).show()
            +-----+
            |total|
            +-----+
            |    6|
            |    3|
            +-----+
            <BLANKLINE>
        """
        # Coalesce to 0 to handle nulls
        ccols = [f.coalesce(col, f.lit(0)) for col in cols]
        return reduce(operator.add, ccols).cast(t.IntegerType())

    @property
    def ancestry_columns(self) -> set[str]:
        """Find all ancestry number columns in the manifest.

        These columns are used to calculate the total number of samples, cases, and controls.

        Returns:
            set[str]: Set of ancestry number columns.

        Raises:
            ValueError: If the meta-analysis data source is unsupported.

        Examples:
            >>> dummy_df = spark.createDataFrame([(1,2,3), (4,5,6)])
            >>> manifest = FinnGenMetaManifest(df=dummy_df, meta=MetaAnalysisDataSource.FINNGEN_UKBB)
            >>> sorted(manifest.ancestry_columns)
            ['fg_n_cases', 'fg_n_controls', 'ukbb_n_cases', 'ukbb_n_controls']
            >>> manifest = FinnGenMetaManifest(df=dummy_df, meta=MetaAnalysisDataSource.FINNGEN_UKBB_MVP)
            >>> sorted(manifest.ancestry_columns)
            ['MVP_AFR_n_cases', 'MVP_AFR_n_controls', 'MVP_AMR_n_cases', 'MVP_AMR_n_controls', 'MVP_EUR_n_cases', 'MVP_EUR_n_controls', 'fg_n_cases', 'fg_n_controls', 'ukbb_n_cases', 'ukbb_n_controls']
        """
        if self.meta == MetaAnalysisDataSource.FINNGEN_UKBB:
            return self.finngen_ancestry_cols | self.ukbb_ancestry_cols
        elif self.meta == MetaAnalysisDataSource.FINNGEN_UKBB_MVP:
            return (
                self.finngen_ancestry_cols
                | self.ukbb_ancestry_cols
                | self.mvp_ancestry_columns
            )
        else:
            raise ValueError(f"Unsupported meta-analysis data source: {self.meta}")

    @property
    def n_samples(self) -> Column:
        """Get the total number of samples."""
        return self._add(*[f.col(c) for c in self.ancestry_columns]).alias("nSamples")

    @property
    def n_cases(self) -> Column:
        """Get the total number of cases."""
        ancestry_cols = [f.col(c) for c in self.ancestry_columns if "n_cases" in c]
        return self._add(*ancestry_cols).alias("nCases")

    @property
    def n_controls(self) -> Column:
        """Get the total number of cases."""
        ancestry_cols = [f.col(c) for c in self.ancestry_columns if "n_controls" in c]
        return self._add(*ancestry_cols).alias("nControls")

    def _discovery_samples_finngen_ukbb(self) -> Column:
        """Get the discovery samples for FinnGen UKBB meta-analysis.

        This meta analysis includes only two cohorts:
        - Finnish (from FinnGen)
        - Non-Finnish European (from Pan-UKBB European subset)

        All ancestries with sample size > 0 are included.

        Returns:
            Column: Spark Column representing the ancestry cocktail.
        """
        return f.filter(
            f.array(
                f.struct(
                    (
                        f.coalesce(f.col("fg_n_cases"), f.lit(0))
                        + f.coalesce(f.col("fg_n_controls"), f.lit(0))
                    )
                    .cast(t.IntegerType())
                    .alias("sampleSize"),
                    f.lit("fin").alias("ancestry"),
                ),
                f.struct(
                    (
                        f.coalesce(f.col("ukbb_n_cases"), f.lit(0))
                        + f.coalesce(f.col("ukbb_n_controls"), f.lit(0))
                    )
                    .cast(t.IntegerType())
                    .alias("sampleSize"),
                    f.lit("nfe").alias("ancestry"),
                ),
            ),
            lambda x: x.sampleSize > 0.0,
        ).alias("discoverySamples")

    def _discovery_samples_finngen_ukbb_mvp(self) -> Column:
        """Get the discovery samples for FinnGen UKBB MVP meta-analysis.

        This meta analysis includes n of four cohorts:
        - Finnish (from FinnGen)
        - European (from Pan-UKBB European subset and MVP European subset)
        - African (from MVP African subset)
        - American (from MVP American subset)

        All ancestries with sample size > 0 are included.

        Returns:
            Column: Spark Column representing the ancestry cocktail.
        """
        return f.filter(
            f.array(
                f.struct(
                    (
                        f.coalesce(f.col("fg_n_cases"), f.lit(0))
                        + f.coalesce(f.col("fg_n_controls"), f.lit(0))
                    )
                    .cast(t.IntegerType())
                    .alias("sampleSize"),
                    f.lit("Finnish").alias("ancestry"),
                ),
                f.struct(
                    (
                        f.coalesce(f.col("ukbb_n_cases"), f.lit(0))
                        + f.coalesce(f.col("ukbb_n_controls"), f.lit(0))
                        + f.coalesce(f.col("MVP_EUR_n_cases"), f.lit(0))
                        + f.coalesce(f.col("MVP_EUR_n_controls"), f.lit(0))
                    )
                    .cast(t.IntegerType())
                    .alias("sampleSize"),
                    f.lit("European").alias("ancestry"),
                ),
                f.struct(
                    (
                        f.coalesce(f.col("MVP_AFR_n_cases"), f.lit(0))
                        + f.coalesce(f.col("MVP_AFR_n_controls"), f.lit(0))
                    )
                    .cast(t.IntegerType())
                    .alias("sampleSize"),
                    f.lit("African").alias("ancestry"),
                ),
                f.struct(
                    (
                        f.coalesce(f.col("MVP_AMR_n_cases"), f.lit(0))
                        + f.coalesce(f.col("MVP_AMR_n_controls"), f.lit(0))
                    )
                    .cast(t.IntegerType())
                    .alias("sampleSize"),
                    f.lit("Admixed American").alias("ancestry"),
                ),
            ),
            lambda x: x.sampleSize > 0.0,
        ).alias("discoverySamples")

    @property
    def summary_statistics_location(self) -> Column:
        """Get the summary statistics location column.

        Returns:
            Column: Spark Column representing the summary statistics location.
        """
        if self.sumstat_location_column in self._df.columns:
            return (
                f.col(self.sumstat_location_column)
                .cast(t.StringType())
                .alias("summarystatsLocation")
            )
        else:
            return f.lit(None).cast(t.StringType()).alias("summarystatsLocation")

    @property
    def has_summary_statistics(self) -> Column:
        """Get the has summary statistics column.

        Returns:
            Column: Spark Column representing whether the study has summary statistics.
        """
        return f.lit(True).alias("hasSumstats")

    @property
    def study_id(self) -> Column:
        """Get the study ID column.

        Returns:
            Column: Spark Column representing the study ID.
        """
        return f.concat_ws(
            "_",
            f.lit(self.meta.value),
            f.col("fg_phenotype"),
        ).alias("studyId")

    @property
    def project_id(self) -> Column:
        """Get the project ID column.

        Returns:
            Column: Spark Column representing the project ID.
        """
        return f.lit(self.meta.value).alias("projectId")

    @property
    def trait_from_source(self) -> Column:
        """Get the trait from source column.

        Returns:
            Column: Spark Column representing the trait from source.
        """
        return f.col("name").alias("traitFromSource")

    @property
    def n_cases_per_cohort(self) -> Column:
        """Get the number of cases per cohort column.

        Returns:
            Column: Spark Column representing the number of cases per cohort.
        """
        n_cases = [
            f.struct(
                f.lit("FinnGen").alias("cohort"),
                f.coalesce(f.col("fg_n_cases"), f.lit(0)).alias("nCases"),
            ),
            f.struct(
                f.lit("UKBB").alias("cohort"),
                f.coalesce(f.col("ukbb_n_cases"), f.lit(0)).alias("nCases"),
            ),
        ]
        if self.meta == MetaAnalysisDataSource.FINNGEN_UKBB_MVP:
            n_cases += [
                f.struct(
                    f.lit("MVP_EUR").alias("cohort"),
                    f.coalesce(f.col("MVP_EUR_n_cases"), f.lit(0)).alias("nCases"),
                ),
                f.struct(
                    f.lit("MVP_AFR").alias("cohort"),
                    f.coalesce(f.col("MVP_AFR_n_cases"), f.lit(0)).alias("nCases"),
                ),
                f.struct(
                    f.lit("MVP_AMR").alias("cohort"),
                    f.coalesce(f.col("MVP_AMR_n_cases"), f.lit(0)).alias("nCases"),
                ),
            ]

        return f.array(*n_cases).alias("nCasesPerCohort")

    @property
    def n_samples_per_cohort(self) -> Column:
        """Get the number of samples per cohort column.

        Returns:
            Column: Spark Column representing the number of samples per cohort.
        """
        n_samples = [
            f.struct(
                f.lit("FinnGen").alias("cohort"),
                (
                    f.coalesce(f.col("fg_n_cases"), f.lit(0))
                    + f.coalesce(f.col("fg_n_controls"), f.lit(0))
                ).alias("nSamples"),
            ),
            f.struct(
                f.lit("UKBB").alias("cohort"),
                (
                    f.coalesce(f.col("ukbb_n_cases"), f.lit(0))
                    + f.coalesce(f.col("ukbb_n_controls"), f.lit(0))
                ).alias("nSamples"),
            ),
        ]
        if self.meta == MetaAnalysisDataSource.FINNGEN_UKBB_MVP:
            n_samples += [
                f.struct(
                    f.lit("MVP_EUR").alias("cohort"),
                    (
                        f.coalesce(f.col("MVP_EUR_n_cases"), f.lit(0))
                        + f.coalesce(f.col("MVP_EUR_n_controls"), f.lit(0))
                    ).alias("nSamples"),
                ),
                f.struct(
                    f.lit("MVP_AFR").alias("cohort"),
                    (
                        f.coalesce(f.col("MVP_AFR_n_cases"), f.lit(0))
                        + f.coalesce(f.col("MVP_AFR_n_controls"), f.lit(0))
                    ).alias("nSamples"),
                ),
                f.struct(
                    f.lit("MVP_AMR").alias("cohort"),
                    (
                        f.coalesce(f.col("MVP_AMR_n_cases"), f.lit(0))
                        + f.coalesce(f.col("MVP_AMR_n_controls"), f.lit(0))
                    ).alias("nSamples"),
                ),
            ]

        return f.array(*n_samples).alias("nSamplesPerCohort")

ancestry_columns: set[str] property

Find all ancestry number columns in the manifest.

These columns are used to calculate the total number of samples, cases, and controls.

Returns:

Type Description
set[str]

set[str]: Set of ancestry number columns.

Raises:

Type Description
ValueError

If the meta-analysis data source is unsupported.

Examples:

>>> dummy_df = spark.createDataFrame([(1,2,3), (4,5,6)])
>>> manifest = FinnGenMetaManifest(df=dummy_df, meta=MetaAnalysisDataSource.FINNGEN_UKBB)
>>> sorted(manifest.ancestry_columns)
['fg_n_cases', 'fg_n_controls', 'ukbb_n_cases', 'ukbb_n_controls']
>>> manifest = FinnGenMetaManifest(df=dummy_df, meta=MetaAnalysisDataSource.FINNGEN_UKBB_MVP)
>>> sorted(manifest.ancestry_columns)
['MVP_AFR_n_cases', 'MVP_AFR_n_controls', 'MVP_AMR_n_cases', 'MVP_AMR_n_controls', 'MVP_EUR_n_cases', 'MVP_EUR_n_controls', 'fg_n_cases', 'fg_n_controls', 'ukbb_n_cases', 'ukbb_n_controls']

df: DataFrame property

Get the manifest DataFrame.

The resulting DataFrame has the following schema:

|-- studyPhenotype: string (nullable = true)
|-- traitFromSource: string (nullable = true)
|-- discoverySamples: array (nullable = true)
    |-- element: struct (containsNull = true)
        |-- sampleSize: integer (nullable = true)
        |-- ancestry: string (nullable = true)
|-- nSamples: integer (nullable = true)
|-- nCases: integer (nullable = true)
|-- nSamplesPerCohort: array (nullable = true)
    |-- element: struct (containsNull = true)
        |-- cohort: string (nullable = true)
        |-- nSamples: integer (nullable = true)
|-- nCasesPerCohort: array (nullable = true)
    |-- element: struct (containsNull = true)
        |-- cohort: string (nullable = true)
        |-- nCases: integer (nullable = true)
|-- nControls: integer (nullable = true)
|-- hasSumstats: boolean (nullable = true)
|-- summarystatsLocation: string (nullable = true)  # may be null if not provided in the manifest

discovery_samples: Column property

Get the discovery samples.

This method dispatches to the appropriate private method based on the meta-analysis data source.

Returns:

Name Type Description
Column Column

Spark Column representing the discovery samples.

has_summary_statistics: Column property

Get the has summary statistics column.

Returns:

Name Type Description
Column Column

Spark Column representing whether the study has summary statistics.

n_cases: Column property

Get the total number of cases.

n_cases_per_cohort: Column property

Get the number of cases per cohort column.

Returns:

Name Type Description
Column Column

Spark Column representing the number of cases per cohort.

n_controls: Column property

Get the total number of cases.

n_samples: Column property

Get the total number of samples.

n_samples_per_cohort: Column property

Get the number of samples per cohort column.

Returns:

Name Type Description
Column Column

Spark Column representing the number of samples per cohort.

project_id: Column property

Get the project ID column.

Returns:

Name Type Description
Column Column

Spark Column representing the project ID.

study_id: Column property

Get the study ID column.

Returns:

Name Type Description
Column Column

Spark Column representing the study ID.

summary_statistics_location: Column property

Get the summary statistics location column.

Returns:

Name Type Description
Column Column

Spark Column representing the summary statistics location.

trait_from_source: Column property

Get the trait from source column.

Returns:

Name Type Description
Column Column

Spark Column representing the trait from source.

__init__(df: DataFrame, meta: MetaAnalysisDataSource) -> None

Initialize the FinnGen meta-analysis manifest.

Parameters:

Name Type Description Default
df DataFrame

DataFrame containing the manifest data.

required
meta MetaAnalysisDataSource

Meta-analysis data source enum.

required
Source code in src/gentropy/datasource/finngen_meta/__init__.py
59
60
61
62
63
64
65
66
67
def __init__(self, df: DataFrame, meta: MetaAnalysisDataSource) -> None:
    """Initialize the FinnGen meta-analysis manifest.

    Args:
        df (DataFrame): DataFrame containing the manifest data.
        meta (MetaAnalysisDataSource): Meta-analysis data source enum.
    """
    self.meta = meta
    self._df = df

from_path(session: Session, manifest_path: str) -> FinnGenMetaManifest classmethod

Load the FinnGen meta-analysis manifest from a specified path.

Note

This method asserts that the manifest file is tab-delimited and contains header with following columns:

|-- fg_phenotype: string (nullable = true)        # required
|-- name: string (nullable = true)                # required
|-- fg_n_cases: integer (nullable = true)         # required
|-- fg_n_controls: integer (nullable = true)      # required
|-- ukbb_n_cases: integer (nullable = true)       # required
|-- ukbb_n_controls: integer (nullable = true)    # required
|-- MVP_AFR_n_cases: integer (nullable = true)    # optional
|-- MVP_AFR_n_controls: integer (nullable = true) # optional
|-- MVP_EUR_n_cases: integer (nullable = true)    # optional
|-- MVP_EUR_n_controls: integer (nullable = true) # optional
|-- MVP_AMR_n_cases: integer (nullable = true)    # optional
|-- MVP_AMR_n_controls: integer (nullable = true) # optional
|-- path_bucket: string (nullable = true)         # optional

Args: session (Session): Session object. manifest_path (str): Path to the manifest file.

Returns:

Name Type Description
FinngenMetaManifest FinnGenMetaManifest

Loaded manifest object.

Raises:

Type Description
AssertionError

If the manifest file does not contain the required columns.

AssertionError

If the manifest file does not contain the required columns.

Source code in src/gentropy/datasource/finngen_meta/__init__.py
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
@classmethod
def from_path(cls, session: Session, manifest_path: str) -> FinnGenMetaManifest:
    """Load the FinnGen meta-analysis manifest from a specified path.

    Note:
        This method asserts that the manifest file is tab-delimited and contains header with following columns:
        ```
        |-- fg_phenotype: string (nullable = true)        # required
        |-- name: string (nullable = true)                # required
        |-- fg_n_cases: integer (nullable = true)         # required
        |-- fg_n_controls: integer (nullable = true)      # required
        |-- ukbb_n_cases: integer (nullable = true)       # required
        |-- ukbb_n_controls: integer (nullable = true)    # required
        |-- MVP_AFR_n_cases: integer (nullable = true)    # optional
        |-- MVP_AFR_n_controls: integer (nullable = true) # optional
        |-- MVP_EUR_n_cases: integer (nullable = true)    # optional
        |-- MVP_EUR_n_controls: integer (nullable = true) # optional
        |-- MVP_AMR_n_cases: integer (nullable = true)    # optional
        |-- MVP_AMR_n_controls: integer (nullable = true) # optional
        |-- path_bucket: string (nullable = true)         # optional
        ```
    Args:
        session (Session): Session object.
        manifest_path (str): Path to the manifest file.

    Returns:
        FinngenMetaManifest: Loaded manifest object.

    Raises:
        AssertionError: If the manifest file does not contain the required columns.
        AssertionError: If the manifest file does not contain the required columns.
    """
    df = (
        session.spark.read.option("header", True)
        .option("sep", "\t")
        .csv(manifest_path)
    )
    assert cls.required_columns.issubset(set(df.columns)), (
        f"Manifest file must contain the following columns: {cls.required_columns}. "
    )

    # By default we assume we are dealing with the FinnGen UKBB meta-analysis
    meta = MetaAnalysisDataSource.FINNGEN_UKBB
    columns = [*cls.required_columns]

    # If we have the MVP ancestry columns, then we are dealing with the FinnGen UKBB MVP meta-analysis
    if cls.mvp_ancestry_columns.issubset(set(df.columns)):
        meta = MetaAnalysisDataSource.FINNGEN_UKBB_MVP
        columns += [*cls.mvp_ancestry_columns]

    column_map = [
        f.col(col).cast(t.IntegerType()).alias(col)
        if "n_cases" in col or "n_controls" in col
        else f.col(col).cast(t.StringType()).alias(col)
        for col in columns
    ]

    # Handle the summary statistics location.
    if cls.sumstat_location_column in df.columns:
        column_map.append(
            f.col(cls.sumstat_location_column)
            .cast(t.StringType())
            .alias(cls.sumstat_location_column)
        )
    else:
        session.logger.warning(
            f"Manifest file does not contain the '{cls.sumstat_location_column}' column. Can not determine summary statistics location."
        )
        column_map.append(f.lit(None).alias(cls.sumstat_location_column))

    df = df.select(*column_map)  # Final contract
    return cls(df=df, meta=meta)

gentropy.datasource.finngen_meta.MetaAnalysisDataSource

Bases: str, Enum

Enum for meta-analysis data sources.

Source code in src/gentropy/datasource/finngen_meta/__init__.py
21
22
23
24
25
class MetaAnalysisDataSource(str, Enum):
    """Enum for meta-analysis data sources."""

    FINNGEN_UKBB_MVP = "FINNGEN_R12_UKB_MVP_META"
    FINNGEN_UKBB = "FINNGEN_R12_UKB_META"