mecfs_bio.build_system.task.gene_manhattan_plot_task
Task to produce an interactive gene-level Manhattan plot as an HTML file.
Supports two source types:
- :class:
MagmaGeneSource: read a MAGMA gene-level analysis output directory (the.genes.outfile produced by :class:MagmaGeneAnalysisTask) and join a gene thesaurus to translate Ensembl IDs into human-readable gene names. - :class:
GenePValueTableSource: read an arbitrary table of(gene_ensembl_id, p_value)rows and look up chromosomal locations and human-readable gene names from a gene-locations reference (such asMAGMA_ENSEMBL_GENE_LOCATION_REFERENCE_DATA_BUILD_37_RAW). Intended for rare-variant test output or any other gene-level result table.
The plot uses Plotly's WebGL Scattergl renderer for performance with
20k-30k gene points and exposes hover text containing the gene name, Ensembl
ID, chromosome, genomic midpoint position (labelled Position (hg19) or
Position (hg38) according to the source's declared genome_build), and
-log10(p).
Classes:
-
GeneManhattanData–The genes to plot plus the multiple-testing count for the significance line.
-
GeneManhattanPlotTask–Create an interactive HTML gene-level Manhattan plot.
-
GeneManhattanSource–A source that yields rows of (chrom, pos, ensembl_id, gene_name, p) for a Manhattan plot.
-
GenePValueTableSource–Load a Manhattan-plot table from an arbitrary (gene, p-value) table.
-
MagmaGeneSource–Load a Manhattan-plot table from a :class:
MagmaGeneAnalysisTask.
Functions:
-
build_manhattan_plot–Construct a Plotly figure containing a gene-level Manhattan plot.
Attributes:
-
GeneIdKind– -
logger–
GeneManhattanData
The genes to plot plus the multiple-testing count for the significance line.
df holds the rows to plot, after any max_p_value filtering.
num_genes_for_correction is the number of genes with a valid (positive, non-null) p-value before max_p_value filtering. It drives the default Bonferroni threshold so that the significance line stays invariant to the purely visual max_p_value filter.
Attributes:
-
df(DataFrame) – -
num_genes_for_correction(int) –
GeneManhattanPlotTask
Bases: Task
Create an interactive HTML gene-level Manhattan plot.
Backed by Plotly's WebGL renderer (Scattergl) so that hover stays responsive at gene-scale point counts (~20k-30k).
Methods:
Attributes:
-
colors(tuple[str, str]) – -
deps(list[Task]) – -
hla_marker_symbol(str | None) – -
meta(Meta) – -
plotly_js_mode(bool | PlotlyWriteMode) – -
point_size(int) – -
sig_line_color(str) – -
sig_threshold(float | None) – -
source(GeneManhattanSource) – -
title(str | None) –
create
classmethod
create(
asset_id: str,
source: GeneManhattanSource,
sig_threshold: float | None = None,
title: str | None = None,
) -> GeneManhattanPlotTask
Source code in mecfs_bio/build_system/task/gene_manhattan_plot_task.py
execute
Source code in mecfs_bio/build_system/task/gene_manhattan_plot_task.py
GeneManhattanSource
Bases: ABC
A source that yields rows of (chrom, pos, ensembl_id, gene_name, p) for a Manhattan plot.
Methods:
-
load_df–Load the full table, then apply the optional max_p_value filter.
Attributes:
-
deps(list[Task]) – -
genome_build(GenomeBuild) –Genome build of the chromosomal positions exposed by load_df.
-
max_p_value(float | None) –Drop genes whose p-value is at or above this before plotting.
-
project(str) –The project label inherited from the primary input task's metadata.
-
trait(str) –The trait label inherited from the primary input task's metadata.
genome_build
abstractmethod
property
Genome build of the chromosomal positions exposed by load_df.
Drives the hover-text position label (pos_hg19 vs pos_hg38).
max_p_value
abstractmethod
property
Drop genes whose p-value is at or above this before plotting.
None disables filtering. Filtering is purely a visual simplification: it does not affect the Bonferroni significance threshold, which is based on the gene count before filtering.
project
abstractmethod
property
The project label inherited from the primary input task's metadata.
trait
abstractmethod
property
The trait label inherited from the primary input task's metadata.
load_df
Load the full table, then apply the optional max_p_value filter.
The multiple-testing count is taken before filtering so that the significance threshold is unaffected by max_p_value.
Source code in mecfs_bio/build_system/task/gene_manhattan_plot_task.py
GenePValueTableSource
Bases: GeneManhattanSource
Load a Manhattan-plot table from an arbitrary (gene, p-value) table.
Chromosomal positions and the complementary gene identifier (Ensembl ID or
human-readable gene name) are looked up from gene_locations_task
(e.g. the MAGMA Ensembl gene-locations reference) by inner join. Genes
missing from the locations file are dropped because they cannot be placed
on the x-axis.
gene_id_kind declares which identifier the input table uses in
gene_col. The locations reference must contain a matching column:
Ensembl IDs ("ensembl_id") join on the reference's Ensembl-ID column,
gene symbols ("gene_name") join on the reference's gene-name column.
max_p_value, when not None, drops genes whose p-value is at or above it before plotting, keeping the figure free of the many uninformative high-p-value points. The default of 0.1 retains only the nominally interesting tail. Filtering does not affect the significance threshold.
Attributes:
-
deps(list[Task]) – -
gene_col(str) – -
gene_id_kind(GeneIdKind) – -
gene_locations_task(Task) – -
genome_build(GenomeBuild) – -
max_p_value(float | None) – -
p_col(str) – -
project(str) – -
table_task(Task) – -
trait(str) –
MagmaGeneSource
Bases: GeneManhattanSource
Load a Manhattan-plot table from a :class:MagmaGeneAnalysisTask.
Chromosomal positions come from the MAGMA output itself. Human-readable
gene names are joined in from gene_thesaurus_task by Ensembl ID. When
a gene is missing from the thesaurus, the Ensembl ID is used as the
display name.
max_p_value, when not None, drops genes whose p-value is at or above it before plotting, keeping the figure free of the many uninformative high-p-value points. The default of 0.1 retains only the nominally interesting tail. Filtering does not affect the significance threshold.
Attributes:
-
deps(list[Task]) – -
gene_thesaurus_task(Task) – -
genome_build(GenomeBuild) – -
magma_task(Task) – -
max_p_value(float | None) – -
project(str) – -
trait(str) –
build_manhattan_plot
build_manhattan_plot(
df: DataFrame,
sig_threshold: float | None,
point_size: int,
colors: tuple[str, str],
sig_line_color: str,
title: str | None,
genome_build: GenomeBuild,
num_genes_for_correction: int | None = None,
y_axis_start: float | None = None,
hla_interval: GenomicInterval | None = None,
hla_marker_symbol: str | None = "diamond",
plot_area_height_px: float = 700.0,
) -> go.Figure
Construct a Plotly figure containing a gene-level Manhattan plot.
Genes with non-positive or null p-values are dropped (-log10 is undefined). If sig_threshold is None, a Bonferroni-corrected threshold 0.05 / num_genes_for_correction is used and a dashed horizontal line is drawn at the corresponding -log10(p). num_genes_for_correction should be the number of genes tested, counted before any p-value filtering of df, so that the threshold is invariant to such filtering; it falls back to the number of plotted rows when not supplied.
genome_build selects the hover label for the gene's midpoint position (Position (hg19) for build 37, Position (hg38) for build 38). Positions in df are assumed to already be in the declared build.
y_axis_start, when not None, anchors the lower bound of the -log10(p) axis (drawn vertically). It is intended to be -log10(max_p_value) so that a p-value-filtered plot uses its full vertical extent instead of leaving empty space below the lowest surviving point. One marker diameter is subtracted so points sitting right at the cutoff clear the x-axis instead of being sliced; the upper bound stays data-driven. plot_area_height_px is the assumed rendered plotting-area height in pixels, used only to convert the marker's pixel diameter into that data-unit padding (the docs embed iframe is ~775px tall).
hla_interval, when not None, marks genes falling inside it (matched on chromosome and midpoint position) with hla_marker_symbol instead of the default circle, so that extended-HLA/MHC-region genes stand out. Those genes keep their chromosome's color; only the symbol changes. hla_marker_symbol must be a valid Plotly symbol whenever hla_interval is given.
Source code in mecfs_bio/build_system/task/gene_manhattan_plot_task.py
376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 | |