Skip to content

mecfs_bio.build_system.task.gwaslab.sldsc_scatter_plot_task

Classes:

  • SLDSCScatterPlotTask

    Generate a plot from the resulting of applying S-LDSC to GWAS summary statistics

SLDSCScatterPlotTask

Bases: Task

Generate a plot from the resulting of applying S-LDSC to GWAS summary statistics using GTEx and Franke lab reference data.

Intended to mimic the appearance of the plots in Finucane, Hilary K., et al. "Heritability enrichment of specifically expressed genes identifies disease-relevant tissues and cell types." Nature genetics 50.4 (2018): 621-629.

Methods:

Attributes:

deps property

deps: list[Task]

df_source_task instance-attribute

df_source_task: Task

meta property

meta: Meta

create classmethod

create(asset_id: str, source_task: Task)
Source code in mecfs_bio/build_system/task/gwaslab/sldsc_scatter_plot_task.py
@classmethod
def create(cls, asset_id: str, source_task: Task):
    source_meta = source_task.meta
    assert isinstance(source_meta, ResultTableMeta)
    meta = GWASPlotDirectoryMeta(
        trait=source_meta.trait,
        project=source_meta.project,
        id=AssetId(asset_id),
    )
    return cls(
        meta=meta,
        df_source_task=source_task,
    )

execute

execute(scratch_dir: Path, fetch: Fetch, wf: WF) -> Asset
Source code in mecfs_bio/build_system/task/gwaslab/sldsc_scatter_plot_task.py
def execute(self, scratch_dir: Path, fetch: Fetch, wf: WF) -> Asset:
    df_asset = fetch(self._source_id)
    df = (
        scan_dataframe_asset(df_asset, meta=self._source_meta).collect().to_pandas()
    )
    df = df.sort_values(by=["Category", "Name"])
    df["mlog10p"] = -np.log10(df["Coefficient_P_value"])
    df["tissue_or_cell"] = np.arange(len(df))
    df["Category"] = df["Category"].str.title()
    df["Category"] = df["Category"].str.replace("Cns", "CNS")
    df["marker_size"] = 4.5 * df[REJECT_NULL_LABEL] + 0.5
    fig = px.scatter(
        df,
        x="tissue_or_cell",
        y="mlog10p",
        color="Category",
        hover_name="Name",
        size="marker_size",
        hover_data={
            "Name": True,
            "Category": True,
            "mlog10p": True,
            "marker_size": False,
            "tissue_or_cell": False,
        },
        template="plotly_white",
        labels={"mlog10p": "-log\u2081\u2080p", "tissue_or_cell": "Tissue or Cell"},
    )
    fig = fig.update_layout(
        font=dict(size=17),
        legend=dict(
            orientation="h",
            yanchor="bottom",
            y=0,
            xanchor="center",
            x=0.5,
            yref="container",
            title=dict(
                side="top",
            ),
        ),
        margin=dict(l=0, r=0, t=2, b=2),
    )
    fig = fig.update_xaxes(showticklabels=False, showgrid=False, zeroline=False)
    fig = fig.update_yaxes(showgrid=False)
    figs = {}
    figs["sldsc_scatter"] = fig
    out_dir = scratch_dir / "scatter_plots"
    write_plots_to_dir(out_dir, figs)
    return DirectoryAsset(out_dir)