Skip to content

Update phenopacket

create_updated_phenopacket(gene_identifier, phenopacket_path, output_dir, identifier_map=None)

Update the gene context within the interpretations for a Phenopacket and writes the updated Phenopacket.

Parameters:

Name Type Description Default
gene_identifier str

Identifier used to update the gene context.

required
phenopacket_path Path

The path to the input Phenopacket file.

required
output_dir Path

The directory where the updated Phenopacket will be written.

required
identifier_map DataFrame

The gene identifier map used for updating.

None

Notes: The gene_identifier parameter should be chosen from ensembl_id, hgnc_id, or entrez_id to update to the current gene identifier in the Phenopacket. We recommend using the ENSEMBL namespace to describe the gene identifiers.

Source code in src/pheval/prepare/update_phenopacket.py
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
def create_updated_phenopacket(
    gene_identifier: str,
    phenopacket_path: Path,
    output_dir: Path,
    identifier_map: pl.DataFrame = None,
) -> None:
    """
    Update the gene context within the interpretations for a Phenopacket and writes the updated Phenopacket.

    Args:
        gene_identifier (str): Identifier used to update the gene context.
        phenopacket_path (Path): The path to the input Phenopacket file.
        output_dir (Path): The directory where the updated Phenopacket will be written.
        identifier_map (pl.DataFrame): The gene identifier map used for updating.
    Notes:
        The gene_identifier parameter should be chosen from ensembl_id, hgnc_id, or entrez_id
        to update to the current gene identifier in the Phenopacket. We recommend using the ENSEMBL namespace
        to describe the gene identifiers.
    """
    identifier_map = create_gene_identifier_map() if identifier_map is None else identifier_map
    updated_phenopacket = update_outdated_gene_context(phenopacket_path, gene_identifier, identifier_map)
    write_phenopacket(updated_phenopacket, output_dir.joinpath(phenopacket_path.name))

create_updated_phenopackets(gene_identifier, phenopacket_dir, output_dir)

Update the gene context within the interpretations for a directory of Phenopackets and writes the updated Phenopackets.

Parameters:

Name Type Description Default
gene_identifier str

Identifier used to update the gene context.

required
phenopacket_dir Path

The path to the input Phenopacket directory.

required
output_dir Path

The directory where the updated Phenopackets will be written.

required

Notes: The gene_identifier parameter should be chosen from ensembl_id, hgnc_id, or entrez_id to update to the current gene identifier in the Phenopacket. We recommend using the ENSEMBL namespace to describe the gene identifiers.

Source code in src/pheval/prepare/update_phenopacket.py
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
def create_updated_phenopackets(gene_identifier: str, phenopacket_dir: Path, output_dir: Path) -> None:
    """
    Update the gene context within the interpretations for a directory of Phenopackets
    and writes the updated Phenopackets.

    Args:
        gene_identifier (str): Identifier used to update the gene context.
        phenopacket_dir (Path): The path to the input Phenopacket directory.
        output_dir (Path): The directory where the updated Phenopackets will be written.
    Notes:
        The gene_identifier parameter should be chosen from ensembl_id, hgnc_id, or entrez_id
        to update to the current gene identifier in the Phenopacket. We recommend using the ENSEMBL namespace
        to describe the gene identifiers.
    """
    identifier_map = create_gene_identifier_map()
    for phenopacket_path in all_files(phenopacket_dir):
        logger.info(f"Updating gene context for: {phenopacket_path.name}")
        updated_phenopacket = update_outdated_gene_context(phenopacket_path, gene_identifier, identifier_map)
        write_phenopacket(updated_phenopacket, output_dir.joinpath(phenopacket_path.name))

update_outdated_gene_context(phenopacket_path, gene_identifier, identifier_map)

Update the gene context of the Phenopacket.

Parameters:

Name Type Description Default
phenopacket_path Path

The path to the Phenopacket file.

required
gene_identifier str

Identifier to update the gene context.

required
identifier_map DataFrame

The gene identifier map used for updating.

required

Returns:

Type Description
Phenopacket | Family

Union[Phenopacket, Family]: The updated Phenopacket or Family.

Notes: This function updates the gene context within the Phenopacket or Family instance. The gene_identifier parameter should be chosen from ensembl_id, hgnc_id, or entrez_id to update to the current gene identifier in the Phenopacket. We recommend using the ENSEMBL namespace to describe the gene identifiers.

Source code in src/pheval/prepare/update_phenopacket.py
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
def update_outdated_gene_context(
    phenopacket_path: Path, gene_identifier: str, identifier_map: pl.DataFrame
) -> Phenopacket | Family:
    """
    Update the gene context of the Phenopacket.

    Args:
        phenopacket_path (Path): The path to the Phenopacket file.
        gene_identifier (str): Identifier to update the gene context.
        identifier_map (pl.DataFrame): The gene identifier map used for updating.

    Returns:
        Union[Phenopacket, Family]: The updated Phenopacket or Family.
    Notes:
        This function updates the gene context within the Phenopacket or Family instance.
        The gene_identifier parameter should be chosen from ensembl_id, hgnc_id, or entrez_id
        to update to the current gene identifier in the Phenopacket. We recommend using the ENSEMBL namespace
        to describe the gene identifiers.
    """
    phenopacket = phenopacket_reader(phenopacket_path)
    interpretations = PhenopacketUtil(phenopacket).interpretations()
    updated_interpretations = GeneIdentifierUpdater(
        identifier_map=identifier_map, gene_identifier=gene_identifier
    ).update_genomic_interpretations_gene_identifier(interpretations, phenopacket_path)
    return PhenopacketRebuilder(phenopacket).update_interpretations(updated_interpretations)

update_phenopackets(gene_identifier, phenopacket_path, phenopacket_dir, output_dir)

Update the gene identifiers in either a single phenopacket or a directory of phenopackets.

Parameters:

Name Type Description Default
gene_identifier str

The gene identifier to be updated.

required
phenopacket_path Path

The path to a single Phenopacket file.

required
phenopacket_dir Path

The directory containing multiple Phenopacket files.

required
output_dir Path

The output directory to save the updated Phenopacket files.

required

Notes: The gene_identifier parameter should be chosen from ensembl_id, hgnc_id, or entrez_id to update to the current gene identifier in the Phenopacket. We recommend using the ENSEMBL namespace to describe the gene identifiers.

Source code in src/pheval/prepare/update_phenopacket.py
 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
def update_phenopackets(gene_identifier: str, phenopacket_path: Path, phenopacket_dir: Path, output_dir: Path) -> None:
    """
    Update the gene identifiers in either a single phenopacket or a directory of phenopackets.

    Args:
        gene_identifier (str): The gene identifier to be updated.
        phenopacket_path (Path): The path to a single Phenopacket file.
        phenopacket_dir (Path): The directory containing multiple Phenopacket files.
        output_dir (Path): The output directory to save the updated Phenopacket files.
    Notes:
        The gene_identifier parameter should be chosen from ensembl_id, hgnc_id, or entrez_id
        to update to the current gene identifier in the Phenopacket. We recommend using the ENSEMBL namespace
        to describe the gene identifiers.
    """
    start_time = time.perf_counter()
    logger.info("Updating phenopackets.")
    output_dir.mkdir(exist_ok=True)
    logger.info(f"Created directory {output_dir}.")
    logger.info(f"Gene identifier set to: {gene_identifier}.")
    if phenopacket_path is not None:
        logger.info(f"Updating {phenopacket_path}.")
        create_updated_phenopacket(gene_identifier, phenopacket_path, output_dir)
    elif phenopacket_dir is not None:
        logger.info(f"Updating {len(all_files(phenopacket_dir))} phenopackets in {phenopacket_dir}.")
        create_updated_phenopackets(gene_identifier, phenopacket_dir, output_dir)
    logger.info(f"Updating finished! Total time: {time.perf_counter() - start_time:.2f} seconds.")