Source code for modalysis.server.plot

"""FastAPI routes for plot generation operations."""

import logging

from fastapi import APIRouter

from modalysis.core.plots.dmr_dotplot import (
    plot_dmr_dotplot as core_plot_dmr_dotplot,
)
from modalysis.core.plots.common_genes_venn import (
    plot_common_genes_venn as core_plot_common_genes_venn,
)
from modalysis.core.plots.gene_heatmap import (
    plot_gene_heatmap as core_plot_gene_heatmap,
)
from modalysis.core.plots.mean_methylation import (
    plot_mean_methylation as core_plot_mean_methylation,
)
from modalysis.server.models import (
    PlotCommonGenesVennRequest,
    PlotDmrDotplotRequest,
    PlotGeneHeatmapRequest,
    PlotMeanMethylationRequest,
)

logger = logging.getLogger(__name__)

router = APIRouter(prefix="/plot")


[docs] @router.post("/mean-methylation") def plot_mean_methylation(request: PlotMeanMethylationRequest) -> dict[str, str]: """Handle POST `/plot/mean-methylation` and generate mean methylation plot.""" logger.info("Server received plot mean-methylation request: %s", request) core_plot_mean_methylation( gff_path=request.gff_path, merged_pileup_paths=request.merged_pileup_paths, labels=request.labels, output_path=request.output_path, output_name=request.output_name, y_min=request.y_min, y_max=request.y_max, chromosome_order=request.chromosome_order, plot_title=request.plot_title, ) return {"status": "success"}
[docs] @router.post("/gene-heatmap") def plot_gene_heatmap(request: PlotGeneHeatmapRequest) -> dict[str, str]: """Handle POST `/plot/gene-heatmap` and generate heatmap plots.""" logger.info("Server received plot gene-heatmap request: %s", request) core_plot_gene_heatmap( annotated_dmr_paths=request.annotated_dmr_paths, manifestations=request.manifestations, modifications=request.modifications, manifestation_labels=request.manifestation_labels, expression_labels=request.expression_labels, annotated_gff_path=request.annotated_gff_path, gff_path=request.gff_path, merged_pileup_paths=request.merged_pileup_paths, pileup_manifestations=request.pileup_manifestations, pileup_modifications=request.pileup_modifications, output_path=request.output_path, output_name=request.output_name, show_gene_labels=request.show_gene_labels, effect_signs=request.effect_signs, ) return {"status": "success"}
[docs] @router.post("/dmr-dotplot") def plot_dmr_dotplot(request: PlotDmrDotplotRequest) -> dict[str, str]: """Handle POST `/plot/dmr-dotplot` and generate dotplot panels.""" logger.info("Server received plot dmr-dotplot request: %s", request) core_plot_dmr_dotplot( annotated_dmr_paths=request.annotated_dmr_paths, manifestations=request.manifestations, modifications=request.modifications, manifestation_labels=request.manifestation_labels, expression_labels=request.expression_labels, annotated_gff_path=request.annotated_gff_path, gff_path=request.gff_path, output_path=request.output_path, output_name=request.output_name, show_gene_labels=request.show_gene_labels, effect_signs=request.effect_signs, ) return {"status": "success"}
[docs] @router.post("/common-genes-venn") def plot_common_genes_venn(request: PlotCommonGenesVennRequest) -> dict[str, str]: """Handle POST `/plot/common-genes-venn` and generate Venn figure.""" logger.info("Server received plot common-genes-venn request: %s", request) core_plot_common_genes_venn( annotated_dmr_paths=request.annotated_dmr_paths, manifestations=request.manifestations, modifications=request.modifications, modification_a=request.modification_a, modification_b=request.modification_b, output_path=request.output_path, output_name=request.output_name, ) return {"status": "success"}