Skip to content

Commit

Permalink
errors_correction4
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiomarco25 committed Dec 19, 2024
1 parent bd5f08c commit 9a1ba0f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
35 changes: 17 additions & 18 deletions src/troutpy/pl/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def sorted_heatmap(celltype_by_feature, output_path:str='',filename:str="Heatmap
plt.ylabel(f'{celltype_by_feature.index.name}')
plt.xlabel(f'{celltype_by_feature.columns.name}')
plt.title(filename)
if save==True:
if save:
plt.savefig(os.path.join(figures_path, f'{filename}.{format}'))

def coupled_scatter(sdata, layer='extracellular_transcripts', output_path:str='', transcript_group='distance_to_source_cell',
Expand Down Expand Up @@ -88,7 +88,7 @@ def coupled_scatter(sdata, layer='extracellular_transcripts', output_path:str=''
Notes:
-----
- The transcript data and cell centroid data are extracted from `sdata`.
- The transcript data and cell centroid data are extracted from `sdata`.
- The `vmax` parameter allows control over the maximum value of the color scale for better visualization control.
- The plot is saved in the specified format and at the specified output path if `save=True`.
"""
Expand Down Expand Up @@ -195,47 +195,47 @@ def plot_crosstab(data, xvar: str = '', yvar: str = '', normalize=True, axis=1,
-----------
data : pd.DataFrame
Input dataset containing the variables for the cross-tabulation.
xvar : str, optional (default: '')
The variable to use on the x-axis for the cross-tabulation.
yvar : str, optional (default: '')
The variable to use on the y-axis for the cross-tabulation.
normalize : bool, optional (default: True)
Whether to normalize the cross-tabulated data (percentages). If True, the data will be normalized.
axis : int, optional (default: 1)
The axis to normalize across. Use `1` for row normalization and `0` for column normalization.
kind : str, optional (default: 'barh')
The kind of plot to generate. Options include:
- 'barh': Horizontal bar plot
- 'bar': Vertical bar plot
- 'heatmap': Heatmap visualization
- 'clustermap': Clustermap visualization
save : bool, optional (default: True)
If True, the plot will be saved to a file.
figures_path : str, optional (default: '')
The directory path where the figure should be saved. If not specified, the plot will be saved in the current directory.
stacked : bool, optional (default: True)
If True, the bar plots will be stacked. Only applicable for 'barh' and 'bar' plot kinds.
figsize : tuple, optional (default: (6, 10))
The size of the figure for the plot (width, height).
cmap : str, optional (default: 'viridis')
The colormap to use for the plot, especially for heatmap and clustermap visualizations.
saving_format : str, optional (default: 'pdf')
The format to save the plot in. Options include 'png', 'pdf', etc.
sortby : str, optional (default: None)
The column or row to sort the cross-tabulated data by before plotting.
Returns:
--------
None
Expand Down Expand Up @@ -350,7 +350,7 @@ def genes_over_noise(sdata, scores_by_genes,layer='extracellular_transcripts', o
)
# Plot the reference line at x = 0
plt.plot([0, 0], [*plt.gca().get_ylim()], "r--")
if save==True:
if save:
# Save the figure
plt.savefig(os.path.join(PATH_FIGURES, f"boxplot_log_fold_change_per_gene{format}"), bbox_inches="tight", pad_inches=0)
# Show the plot
Expand Down Expand Up @@ -456,7 +456,7 @@ def proportion_above_threshold(
figures_path = os.path.join(output_path, 'figures')
os.makedirs(figures_path, exist_ok=True)
filename=f'barplot_distant_from_source_min{bottom_percentile}_max{top_percentile}_{bar_color}'
if save==True:
if save:
plt.savefig(os.path.join(figures_path, f'{filename}.{format}'))
plt.show()

Expand Down Expand Up @@ -604,8 +604,7 @@ def paired_nmf_factors(
title=f'NMF Factor cell-red/exRNa-blue {factor + 1}',
ax=axs, show=False, spot_size=spot_size_cells, vmax=vmax_cells
)
if save==True:
if save:
if save:
figures_path = os.path.join(output_path, 'figures')
os.makedirs(figures_path, exist_ok=True)
file_name = os.path.join(figures_path, f'Spatial_NMF Factor {factor + 1}.{format}')
Expand Down
2 changes: 1 addition & 1 deletion src/troutpy/tl/NMF.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def apply_nmf_to_adata(adata, n_components=20, subsample_percentage=1.0,save=Fal
# Add NMF results to the AnnData object
adata.obsm['W_nmf'] = W # Add the cell factors to the AnnData object
adata.uns['H_nmf'] = H
if save==True:
if save:
H=pd.DataFrame(adata.uns['H_nmf'],columns=adata.var.index)
H.to_parquet(os.path.join(output_path,'factor_loadings_H_per_gene.parquet'))
W=pd.DataFrame(adata.obsm['W_nmf'],index=adata.obs.index)
Expand Down
2 changes: 1 addition & 1 deletion src/troutpy/tl/estimate_density.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def colocalization_proportion(
os.makedirs(outpath, exist_ok=True)

# Save the DataFrame as a Parquet file
if save==True:
if save:
filepath = os.path.join(outpath, filename)
coloc.to_parquet(filepath)

Expand Down

0 comments on commit 9a1ba0f

Please sign in to comment.