diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 146cc2a..3ab8978 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -31,7 +31,7 @@ repos: )$ - repo: https://github.com/igorshubovych/markdownlint-cli - rev: v0.48.0 + rev: v0.49.1 hooks: - id: markdownlint-fix exclude: | @@ -41,7 +41,7 @@ repos: )$ - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.15.9 + rev: v0.16.3 hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] diff --git a/destvi_utils/__init__.py b/destvi_utils/__init__.py index e662381..d29636d 100755 --- a/destvi_utils/__init__.py +++ b/destvi_utils/__init__.py @@ -38,7 +38,7 @@ __all__ = [ "automatic_proportion_threshold", - "explore_gamma_space", "de_genes", + "explore_gamma_space", "plot_de_genes", ] diff --git a/destvi_utils/_destvi_utils.py b/destvi_utils/_destvi_utils.py index d9705f4..35aab12 100755 --- a/destvi_utils/_destvi_utils.py +++ b/destvi_utils/_destvi_utils.py @@ -100,9 +100,7 @@ def automatic_proportion_threshold( ct_thresholds[name_ct] = ipoints[0] else: raise ArgumentError( - 'Kind threshold {} is not defined. Use "secondary" or "primary"'.format( - kind_threshold - ) + f'Kind threshold {kind_threshold} is not defined. Use "secondary" or "primary"' ) # PLOT 1 shows proportions in spatial dimensions without thresholding @@ -117,7 +115,7 @@ def plot_proportions_xy(ax, threshold): cmap="Reds", ) plt.colorbar() - plt.title("name_ct, threshold: t={:0.3f}".format(threshold)) + plt.title(f"name_ct, threshold: t={threshold:0.3f}") plt.tight_layout(rect=[0, 0.03, 1, 0.9]) return ax @@ -151,7 +149,7 @@ def plot_proportions_xy(ax, threshold): tmpfile = BytesIO() plt.savefig(tmpfile, format="png") encoded = base64.b64encode(tmpfile.getvalue()).decode("utf-8") - html += "".format(encoded) + html += f"" plt.close() else: plt.show() @@ -159,9 +157,7 @@ def plot_proportions_xy(ax, threshold): # dump+write to HTML if output_file is not None: logging.warning( - "Saving output to {}. Set output_file=None to display results.".format( - output_file - ) + f"Saving output to {output_file}. Set output_file=None to display results." ) with open(output_file, "w") as f: f.write(html) @@ -266,8 +262,8 @@ def explore_gamma_space( # variance and explained variance total_var = np.sum(np.diag(np.cov(data.T))) explained_var = 100 * np.diag(np.cov(projection.T)) / total_var - plt.xlabel("SpatialPC1 ({:.1f}% explained var)".format(explained_var[0])) - plt.ylabel("SpatialPC2 ({:.1f}% explained var)".format(explained_var[1])) + plt.xlabel(f"SpatialPC1 ({explained_var[0]:.1f}% explained var)") + plt.ylabel(f"SpatialPC2 ({explained_var[1]:.1f}% explained var)") plt.title("Projection of the spatial data") ax3 = plt.subplot(131) @@ -312,8 +308,8 @@ def explore_gamma_space( # variance and explained variance total_var = np.sum(np.diag(np.cov(sc_latent.T))) explained_var = 100 * np.diag(np.cov(sc_projection.T)) / total_var - plt.xlabel("SpatialPC1 ({:.1f}% explained var)".format(explained_var[0])) - plt.ylabel("SpatialPC2 ({:.1f}% explained var)".format(explained_var[1])) + plt.xlabel(f"SpatialPC1 ({explained_var[0]:.1f}% explained var)") + plt.ylabel(f"SpatialPC2 ({explained_var[1]:.1f}% explained var)") plt.title("Projection of the scRNA-seq data") plt.tight_layout(rect=[0, 0.03, 1, 0.9]) @@ -322,7 +318,7 @@ def explore_gamma_space( plt.savefig(tmpfile, dpi="figure", format="png") encoded = base64.b64encode(tmpfile.getvalue()).decode("utf-8") if output_file is not None: - html += "".format(encoded) + html += f"" else: plt.show() @@ -332,7 +328,7 @@ def explore_gamma_space( if output_file is not None: html += f"

Genes associated with SpatialPC{d + 1}

" else: - print("[bold]Genes associated with SpatialPC{}[/bold]".format(d + 1)) + print(f"[bold]Genes associated with SpatialPC{d + 1}[/bold]") r = _utils._vcorrcoef(normalized_counts.T, sc_projection[:, d]) for mode in ["Positively", "Negatively"]: ranking = np.argsort(r) @@ -356,7 +352,7 @@ def explore_gamma_space( html += "

" + ", ".join(text_signatures) + "

" else: print("\n") - print("[italic]{}[/italic]".format(mode)) + print(f"[italic]{mode}[/italic]") print( "---------------------------------------------------------------------------------------" ) @@ -372,9 +368,7 @@ def explore_gamma_space( # write HTML if output_file is not None: logging.warning( - "Saving output to {}. Set output_file=None to display results.".format( - output_file - ) + f"Saving output to {output_file}. Set output_file=None to display results." ) with open(output_file, "w") as f: f.write(html) @@ -541,9 +535,7 @@ def plot_de_genes( if not matching_genes.all(): missing_genes = np.array(interesting_genes)[~matching_genes] raise ValueError( - "{} are not in st_adata.var_names. Remove these genes from interesting_genes.".format( - missing_genes - ) + f"{missing_genes} are not in st_adata.var_names. Remove these genes from interesting_genes." ) locations = st_adata.obsm[key_spatial] @@ -612,9 +604,7 @@ def plot_de_genes( plt.tight_layout() if output_file is not None: logging.warning( - "Saving output to {}. Set output_file=None to display results.".format( - output_file - ) + f"Saving output to {output_file}. Set output_file=None to display results." ) plt.savefig(output_file, dpi=300) plt.close() diff --git a/docs/conf.py b/docs/conf.py index cf1d49a..ccb3707 100755 --- a/docs/conf.py +++ b/docs/conf.py @@ -12,7 +12,7 @@ HERE = Path(__file__).parent sys.path[:0] = [str(HERE.parent), str(HERE / "extensions")] -import destvi_utils # noqa +import destvi_utils # -- General configuration --------------------------------------------- diff --git a/tests/test_destvi_utils.py b/tests/test_destvi_utils.py index 1a5d8fa..d092557 100644 --- a/tests/test_destvi_utils.py +++ b/tests/test_destvi_utils.py @@ -1,8 +1,10 @@ +from unittest.mock import MagicMock, patch + import numpy as np +import pandas as pd from scvi.data import synthetic_iid from scvi.model import CondSCVI, DestVI -from unittest.mock import patch, MagicMock -import pandas as pd + import destvi_utils