Skip to content

FinnGen Study Index generation

gentropy.finngen_studies.FinnGenStudiesStep

FinnGen study index generation step.

Source code in src/gentropy/finngen_studies.py
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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
class FinnGenStudiesStep:
    """FinnGen study index generation step."""

    def __init__(
        self,
        session: Session,
        finngen_study_index_out: str,
        finngen_phenotype_table_url: str = FinngenStudiesConfig().finngen_phenotype_table_url,
        finngen_release_prefix: str = FinngenStudiesConfig().finngen_release_prefix,
        finngen_summary_stats_url_prefix: str = FinngenStudiesConfig().finngen_summary_stats_url_prefix,
        finngen_summary_stats_url_suffix: str = FinngenStudiesConfig().finngen_summary_stats_url_suffix,
        efo_curation_mapping_url: str = FinngenStudiesConfig().efo_curation_mapping_url,
        sample_size: int = FinngenStudiesConfig().sample_size,
    ) -> None:
        """Run FinnGen study index generation step.

        Args:
            session (Session): Session object.
            finngen_study_index_out (str): Output FinnGen study index path.
            finngen_phenotype_table_url (str): URL to the FinnGen phenotype table.
            finngen_release_prefix (str): FinnGen release prefix.
            finngen_summary_stats_url_prefix (str): FinnGen summary stats URL prefix.
            finngen_summary_stats_url_suffix (str): FinnGen summary stats URL suffix.
            efo_curation_mapping_url (str): URL to the EFO curation mapping file
            sample_size (int): Number of individuals that participated in sample collection, derived from finngen release metadata.
        """
        _match = FinnGenStudyIndex.validate_release_prefix(finngen_release_prefix)
        release_prefix = _match["prefix"]
        release = _match["release"]

        efo_mapping = EFOMapping.from_path(session, efo_curation_mapping_url)
        study_index = FinnGenStudyIndex.from_source(
            session.spark,
            finngen_phenotype_table_url,
            release_prefix,
            finngen_summary_stats_url_prefix,
            finngen_summary_stats_url_suffix,
            sample_size,
        )
        study_index_with_efo = efo_mapping.annotate_study_index(study_index, release)
        study_index_with_efo.df.coalesce(session.output_partitions).write.mode(
            session.write_mode
        ).parquet(finngen_study_index_out)