Skip to content

mecfs_bio.build_system.task.pipes.attenuation_ratio_pipe

Classes:

AttenuationRatioPipe

Bases: DataProcessingPipe

Pipe to compute attenuation ratio. Useful for evaluating risk of population stratification

Methods:

Attributes:

intercept_col instance-attribute

intercept_col: str

mean_chi_col instance-attribute

mean_chi_col: str

ratio_col class-attribute instance-attribute

ratio_col: str = 'ratio'

process

process(x: LazyFrame) -> narwhals.LazyFrame
Source code in mecfs_bio/build_system/task/pipes/attenuation_ratio_pipe.py
def process(self, x: narwhals.LazyFrame) -> narwhals.LazyFrame:
    return x.with_columns(
        narwhals.when(
            (narwhals.col(self.mean_chi_col) >= 1.02)
            & (narwhals.col(self.intercept_col) >= 1),
        )
        .then(
            (narwhals.col(self.intercept_col) - 1)
            / (narwhals.col(self.mean_chi_col) - 1)
        )
        .otherwise(float("nan"))
        .alias(self.ratio_col)
    )