Skip to content

mecfs_bio.build_system.task.pipes.compute_mlog10p_pipe

Classes:

ComputeMlog10pIfNeededPipe

Bases: DataProcessingPipe

Methods:

Attributes:

min_p_value class-attribute instance-attribute

min_p_value: float = 1e-250

process

process(x: LazyFrame) -> narwhals.LazyFrame
Source code in mecfs_bio/build_system/task/pipes/compute_mlog10p_pipe.py
def process(self, x: narwhals.LazyFrame) -> narwhals.LazyFrame:
    schema = x.collect_schema()
    if GWASLAB_MLOG10P_COL in schema:
        return x
    assert GWASLAB_P_COL in schema
    result = x.with_columns(
        (
            -1
            * (
                narwhals.max_horizontal(
                    narwhals.col(GWASLAB_P_COL),
                    narwhals.lit(self.min_p_value),  # avoid taking the log of 0
                ).log(
                    base=10,
                )
            )
        ).alias(GWASLAB_MLOG10P_COL)
    )
    return result