Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error saving the output figures in png or pdf format #100

Closed
archanabhardwaj opened this issue Jul 5, 2022 · 1 comment
Closed

Error saving the output figures in png or pdf format #100

archanabhardwaj opened this issue Jul 5, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@archanabhardwaj
Copy link

empty figures
Hi

I am runing NCEM code from the scratch for coupling and cell enrichment analysis. Meanwhile, I wanted to save all the imaging output in png (or pdf) format. But except for the sc.pl.umap output , I am getting empty png file for the remaining analysis. I tried different ways to save the "image output" but still its not working.

import ncem as nc
import numpy as np
import matplotlib.pyplot as plt
import scanpy as sc
import squidpy as sq

sc.settings.set_figure_params(dpi=100)

import warnings
warnings.filterwarnings("ignore")

from ncem.interpretation import InterpreterInteraction
from ncem.data import get_data_custom, customLoader

results_folder = 'test'
run_name = f'{results_folder}/anndata/'
import scanpy as sc

import anndata as an

adata_file = f"{run_name}/sp.h5ad" # sp_cluster
ad = an.read_h5ad(adata_file)
ncem = InterpreterInteraction()

adata_vis = ad

ncem.data = customLoader(
adata=adata_vis, cluster='region_cluster', patient='sampleid', library_id='sample', radius=150
)

get_data_custom(interpreter=ncem)

var_decomp = ncem.data.compute_variance_decomposition()

ncem.data.variance_decomposition(var_decomp, figsize=(5,3))

plt.savefig('test.png')

ncem.data = customLoader(
adata=adata_vis, cluster='region_cluster', patient='sample', library_id='sample', radius=52
)
get_data_custom(interpreter=ncem)

adata_img, adata_vis, log_pval, fold_change = ncem.data.compute_cluster_enrichment(
image_key=['S1_A1_Complete'],
target_cell_type='2',
clip_pvalues=-5,
n_neighbors=50,
n_pcs=None,
)

sc.pl.umap(adata_vis, color='2 substates', palette='tab10')

plt.savefig("subclust_test.png")
plt.show()

I would appreciate your help
Thanks

@archanabhardwaj archanabhardwaj added the bug Something isn't working label Jul 5, 2022
@AnnaChristina
Copy link
Member

Hi @archanabhardwaj ,

thanks for opening this issue and your interest in using ncem.

all ncem plotting functions have a save argument that allow the user to specifiy the path where figures should be stored, e.g.

ncem/ncem/data.py

Lines 900 to 912 in 9b6d3fb

def cluster_enrichment(
self,
pvalues,
fold_change,
figsize: Tuple[float, float] = (4.0, 10.0),
fontsize: Optional[int] = None,
pad: float = 0.15,
pvalues_cmap=None,
linspace: Optional[Tuple[float, float, int]] = None,
save: Union[str, None] = None,
suffix: str = "_cluster_enrichment.pdf",
show: bool = True,
):

I am closing this issue, but feel free to open it again in case of further questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants