mecfs_bio.build_system.task.protein_coloc.candidate_selection
Candidate (trait locus, protein) pairs for colocalization, and their selection within a budget.
A protein is a candidate at a trait locus when one of its hit segments (from the protein hit table) overlaps the locus window on the same chromosome. Excluded loci get no candidates.
Each candidate is classified by where the protein's gene lies (Sun et al. 2023 ST3, GRCh38): - cis: the gene interval lies within cis_window_bp of the locus window; - trans: the gene is elsewhere; - unknown: the protein has no gene coordinates (for example a multi-gene complex).
Each pair gets a score, and pairs are taken in order of decreasing score: SCORE = SCORE_TRAIT + SCORE_PROTEIN - SCORE_PENALTY SCORE_TRAIT = min(trait lead -log10 p, clip) SCORE_PROTEIN = min(protein lead -log10 p, clip) SCORE_PENALTY = w * log2(1 + N_OTHER_PROTEINS) when the pair is not cis, else 0 N_OTHER_PROTEINS is the number of other proteins with a segment overlapping the same window. The penalty demotes trans pairs at pleiotropic hotspots, where many proteins share a pQTL; cis pairs are never penalized. Unknown is penalized like trans. Strong pairs often tie once both terms are clipped, so ties are broken by GENE_LEAD_DISTANCE_BP (distance from the trait lead to the protein's gene, nearest first, genes on other chromosomes or without coordinates last), then by the unclipped protein -log10 p, then by PROTEIN_ID and LOCUS_ID. A pair is selected while fewer than max_pairs are selected and its locus has fewer than max_per_locus selected pairs.
Classes:
-
SelectionConfig–
Functions:
-
build_candidates–One row per (candidate locus, protein with a segment overlapping its window).
-
select_candidates–Score the candidates and mark each selected or not_selected_budget, in ranked order.
Attributes:
-
CANDIDATE_SCHEMA–
CANDIDATE_SCHEMA
module-attribute
CANDIDATE_SCHEMA = pl.Schema(
{
LOCUS_ID_COL: pl.String,
PROTEIN_ID_COL: pl.String,
HIT_GENE_COL: pl.String,
PROTEIN_MLOG10P_COL: pl.Float64,
CIS_STATUS_COL: pl.String,
N_OTHER_PROTEINS_COL: pl.Int64,
GENE_LEAD_DISTANCE_COL: pl.Int64,
}
)
SelectionConfig
Attributes:
-
cis_window_bp(int) – -
max_pairs(int) – -
max_per_locus(int) – -
mlog10p_clip(float) – -
trans_penalty_weight(float) –
build_candidates
build_candidates(
loci: DataFrame,
hit_segments: DataFrame,
gene_coords: Mapping[ProteinId, GenomicInterval],
cis_window_bp: int,
) -> pl.DataFrame
One row per (candidate locus, protein with a segment overlapping its window).
Source code in mecfs_bio/build_system/task/protein_coloc/candidate_selection.py
select_candidates
select_candidates(
candidates: DataFrame,
loci: DataFrame,
config: SelectionConfig,
) -> pl.DataFrame
Score the candidates and mark each selected or not_selected_budget, in ranked order.