Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/dimet/config/analysis/method/pca_plot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ impute_values: # how to impute zeroes
mean_enrichment: "min"
isotopologues: "min"
isotopologue_proportions: "min"

width: !!float 6.2
height: !!float 4.0
8 changes: 6 additions & 2 deletions src/dimet/processing/differential_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,13 @@ def compute_span_incomparison(df: pd.DataFrame, groups: List) -> pd.DataFrame:
the computed differences.
"""
for i in df.index.values:
all_values = list(df.loc[i, groups[0]]) + list(df.loc[i, groups[1]])
group1_values = df.loc[i, groups[0]].to_numpy()
group2_values = df.loc[i, groups[1]].to_numpy()

all_values = np.concatenate([group1_values, group2_values])

interval = np.nanmax(all_values) - np.nanmin(all_values)

interval = max(all_values) - min(all_values)
df.loc[i, "span_allsamples"] = interval

return df
Expand Down
21 changes: 18 additions & 3 deletions src/dimet/visualization/abundance_bars.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

cs = ConfigStore.instance()

matplotlib.rcParams['svg.fonttype'] = 'none'

def pile_up_abundance(df: pd.DataFrame,
metada_sel: pd.DataFrame) -> pd.DataFrame:
Expand Down Expand Up @@ -69,6 +70,9 @@ def plot_one_metabolite(df: pd.DataFrame,
)
if do_stripplot:
np.random.seed(123) # to force the jitter not to randomly change
dodge_bool = True
if axisx_var == hue_var:
dodge_bool = False
try:
sns.stripplot(
ax=curr_ax,
Expand All @@ -77,7 +81,7 @@ def plot_one_metabolite(df: pd.DataFrame,
hue=str(hue_var),
data=df,
palette=palette_choice,
dodge=True,
dodge=dodge_bool,
edgecolor="black",
linewidth=1.5,
alpha=1,
Expand Down Expand Up @@ -132,7 +136,10 @@ def plot_abundance_bars_no_grid(
axs_k = apply_advanced_param_custom_x_labs(cfg, axs_k)
if k == 0: # collect the legend, which is same for any plot
thehandles, thelabels = axs_k.get_legend_handles_labels()
axs_k.legend_.remove()
try:
axs_k.legend_.remove()
except AttributeError:
pass # no legend is generated when xaxis and barcolor are equal
plt.tight_layout(pad=0.01, w_pad=-2, h_pad=0.1)
plt.savefig(output_path_k,
bbox_inches="tight",
Expand All @@ -141,6 +148,8 @@ def plot_abundance_bars_no_grid(

plt.legend(handles=thehandles, labels=thelabels, loc="upper right")
plt.axis("off")
if hue_var == axisx_var:
plt.figtext(0.1, 0.7, "No legend:\n xaxis equal to barcolor")
plt.savefig(os.path.join(
output_directory,
f"legend.{cfg.analysis.method.figure_format}"),
Expand Down Expand Up @@ -198,7 +207,10 @@ def plot_as_grid_of_bars(

thehandles, thelabels = axs[-1].get_legend_handles_labels()
for i in range(len(selected_metabolites)):
axs[i].legend_.remove()
try:
axs[i].legend_.remove()
except AttributeError:
pass # no legend is generated when xaxis and barcolor are equal

plt.subplots_adjust(left=0.2, top=0.76, bottom=0.2,
hspace=corrector_factor)
Expand All @@ -211,7 +223,10 @@ def plot_as_grid_of_bars(
plt.close()

plt.legend(handles=thehandles, labels=thelabels, loc="upper right")
if hue_var == axisx_var:
plt.figtext(0.1, 0.7, "No legend:\n xaxis equal to barcolor")
plt.axis("off")

plt.savefig(os.path.join(
output_directory,
f"legend.{cfg.analysis.method.figure_format}"),
Expand Down
2 changes: 2 additions & 0 deletions src/dimet/visualization/isotopologue_proportions.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

cs = ConfigStore.instance()

matplotlib.rcParams['svg.fonttype'] = 'none'


def isotopologue_proportions_2piled_df(
compartment_df: pd.DataFrame,
Expand Down
2 changes: 2 additions & 0 deletions src/dimet/visualization/mean_enrichment_line_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

cs = ConfigStore.instance()

matplotlib.rcParams['svg.fonttype'] = 'none'


def melt_data_metadata_2df(compartment_df: pd.DataFrame,
metadata_co_df: pd.DataFrame) -> pd.DataFrame:
Expand Down
2 changes: 2 additions & 0 deletions src/dimet/visualization/metabologram.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

logger = logging.getLogger(__name__)

matplotlib.rcParams['svg.fonttype'] = 'none'


def get_differential_results_dict(file_name: str,
data_integration: DataIntegration,
Expand Down
23 changes: 20 additions & 3 deletions src/dimet/visualization/pca_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
from typing import List, Union

import matplotlib
import matplotlib.figure as figure
import matplotlib.pyplot as plt
import numpy as np
Expand All @@ -18,6 +19,8 @@

cs = ConfigStore.instance()

matplotlib.rcParams['svg.fonttype'] = 'none'


def variance_expl_plot(var_explained_df: pd.DataFrame) -> figure.Figure:
"""
Expand Down Expand Up @@ -47,18 +50,28 @@ def pca_scatter_plot(pc_df: pd.DataFrame,
var_explained_df: pd.DataFrame,
col1: str, col2: str,
labels_column: str,
ellipses_column: Union[str, None]) -> figure.Figure:
ellipses_column: Union[str, None],
width: float=6.0, height: float=4.0) -> figure.Figure:
"""
returns the scatter plot (a seaborn matplotlib figure)
"""
fig, ax = plt.subplots()
fig, ax = plt.subplots(figsize=(width, height))
sns.scatterplot(x="PC1", y="PC2",
ax=ax,
data=pc_df,
hue=col1,
style=col2,
legend=True,
s=80, zorder=3)
handles, labels = ax.get_legend_handles_labels()
ax.legend(
handles,
labels,
bbox_to_anchor=(1.05, 1), # Places legend outside the top-right corner
loc='upper left',
borderaxespad=0.0
)
plt.tight_layout() # Ensures the legend is not clipped
ax.axhline(0, ls="--", color="gray", zorder=1)
ax.axvline(0, ls="--", color="gray", zorder=1)
if labels_column != "":
Expand Down Expand Up @@ -149,6 +162,7 @@ def run_pca_plot(pca_results_dict: dict, cfg: DictConfig,

color_dot = cfg.analysis.method.color
style_dot = cfg.analysis.method.style

options_labels = {'label-y': "name_to_plot",
'label-n': ""} # when empty string, no dot labels

Expand All @@ -159,7 +173,10 @@ def run_pca_plot(pca_results_dict: dict, cfg: DictConfig,
scatter_fig: figure.Figure = pca_scatter_plot(
pc_df, var_explained_df, color_dot,
style_dot, labels_column,
ellipses_column=cfg.analysis.method.draw_ellipses)
ellipses_column=cfg.analysis.method.draw_ellipses,
width=cfg.analysis.method.width,
height=cfg.analysis.method.height
)
pca_scatter_2_file(scatter_fig, name_elements, out_plot_dir,
cfg.analysis.method.figure_format)
plt.close()
Expand Down
Loading