Skip to content

finngen_studies

gentropy.finngen_studies.FinnGenStudiesStep

FinnGen study index generation step.

Source code in src/gentropy/finngen_studies.py
10
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
54
55
56
57
58
59
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_curation_df = FinnGenStudyIndex.read_efo_curation(
            session.spark,
            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 = FinnGenStudyIndex.join_efo_mapping(
            study_index,
            efo_curation_df,
            release,
        )
        study_index_with_efo.df.write.mode(session.write_mode).parquet(
            finngen_study_index_out
        )

__init__(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.

Parameters:

Name Type Description Default
session Session

Session object.

required
finngen_study_index_out str

Output FinnGen study index path.

required
finngen_phenotype_table_url str

URL to the FinnGen phenotype table.

finngen_phenotype_table_url
finngen_release_prefix str

FinnGen release prefix.

finngen_release_prefix
finngen_summary_stats_url_prefix str

FinnGen summary stats URL prefix.

finngen_summary_stats_url_prefix
finngen_summary_stats_url_suffix str

FinnGen summary stats URL suffix.

finngen_summary_stats_url_suffix
efo_curation_mapping_url str

URL to the EFO curation mapping file

efo_curation_mapping_url
sample_size int

Number of individuals that participated in sample collection, derived from finngen release metadata.

sample_size
Source code in src/gentropy/finngen_studies.py
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
54
55
56
57
58
59
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_curation_df = FinnGenStudyIndex.read_efo_curation(
        session.spark,
        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 = FinnGenStudyIndex.join_efo_mapping(
        study_index,
        efo_curation_df,
        release,
    )
    study_index_with_efo.df.write.mode(session.write_mode).parquet(
        finngen_study_index_out
    )