Skip to content

ped

Read and write ped file.

from_lazyframe

from_lazyframe(lf: LazyFrame, output_path: Path) -> None

Write pedigree polars.LazyFrame in ped format.

Warning: This function performs polars.LazyFrame.collect before write csv, this can have a significant impact on memory usage

Parameters:

  • lf (LazyFrame) –

    LazyFrame contains pedigree information.

  • output_path (Path) –

    Path where write pedigree information.

Returns:

  • None

    None

Source code in src/variantplaner/io/ped.py
50
51
52
53
54
55
56
57
58
59
60
61
62
def from_lazyframe(lf: polars.LazyFrame, output_path: pathlib.Path) -> None:
    """Write pedigree [polars.LazyFrame](https://pola-rs.github.io/polars/py-polars/html/reference/lazyframe/index.html) in ped format.

    Warning: This function performs [polars.LazyFrame.collect][] before write csv, this can have a significant impact on memory usage

    Args:
        lf: LazyFrame contains pedigree information.
        output_path: Path where write pedigree information.

    Returns:
        None
    """
    lf.collect().write_csv(output_path, include_header=False, separator="\t")

into_lazyframe

into_lazyframe(input_path: Path) -> LazyFrame

Read a pedigree file in polars.LazyFrame.

Parameters:

  • input_path (Path) –

    Path to pedigree file.

Returns:

  • LazyFrame

    A polars.LazyFrame that contains ped information ('family_id', 'personal_id', 'father_id', 'mother_id', 'sex', 'affected')

Source code in src/variantplaner/io/ped.py
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
def into_lazyframe(input_path: pathlib.Path) -> polars.LazyFrame:
    """Read a pedigree file in [polars.LazyFrame](https://pola-rs.github.io/polars/py-polars/html/reference/lazyframe/index.html).

    Args:
        input_path: Path to pedigree file.

    Returns:
        A [polars.LazyFrame](https://pola-rs.github.io/polars/py-polars/html/reference/lazyframe/index.html) that contains ped information ('family_id', 'personal_id', 'father_id', 'mother_id', 'sex', 'affected')
    """
    return polars.scan_csv(
        input_path,
        separator="\t",
        has_header=False,
        null_values="None",
        new_columns=[
            "family_id",
            "personal_id",
            "father_id",
            "mother_id",
            "sex",
            "affected",
        ],
        dtypes={
            "family_id": polars.Utf8,
            "personal_id": polars.Utf8,
            "father_id": polars.Utf8,
            "mother_id": polars.Utf8,
            "sex": polars.Utf8,
            "affected": polars.Boolean,
        },
    )