Skip to content

Commit

Permalink
fix(plots): add option to save gene ranking plot
Browse files Browse the repository at this point in the history
Signed-off-by: Cameron Smith <cameron.ray.smith@gmail.com>
  • Loading branch information
cameronraysmith committed Aug 3, 2024
1 parent 7ca0f0d commit 50a71cf
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/pyrovelocity/plots/_genes.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from typing import Dict
from typing import List
from typing import Optional
from typing import Tuple
from pathlib import Path
from typing import Dict, List, Optional, Tuple

import matplotlib.pyplot as plt
import numpy as np
Expand All @@ -12,15 +10,13 @@
from matplotlib import gridspec
from matplotlib.axes import Axes
from matplotlib.figure import FigureBase
from matplotlib.patches import ArrowStyle
from matplotlib.patches import ConnectionStyle
from matplotlib.patches import ArrowStyle, ConnectionStyle
from numpy import ndarray
from pandas import DataFrame

from pyrovelocity.analysis.analyze import compute_volcano_data
from pyrovelocity.logging import configure_logging


__all__ = ["plot_gene_ranking"]

logger = configure_logging(__name__)
Expand All @@ -36,6 +32,8 @@ def plot_gene_ranking(
assemble: bool = False,
negative: bool = False,
show_marginal_histograms: bool = False,
save_volcano_plot: bool = False,
volcano_plot_path: str | Path = "volcano.pdf",
) -> Tuple[DataFrame, Optional[FigureBase]]:
if selected_genes is not None:
assert isinstance(selected_genes, (tuple, list))
Expand Down Expand Up @@ -178,6 +176,18 @@ def plot_gene_ranking(
),
)

if save_volcano_plot:
fig.subplots_adjust(wspace=0.1, hspace=0.1)
for ext in ["", ".png"]:
fig.savefig(
f"{volcano_plot_path}{ext}",
facecolor=fig.get_facecolor(),
bbox_inches="tight",
edgecolor="none",
dpi=300,
)
plt.close(fig)

return volcano_data, fig


Expand Down

0 comments on commit 50a71cf

Please sign in to comment.