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
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand All @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion destvi_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

__all__ = [
"automatic_proportion_threshold",
"explore_gamma_space",
"de_genes",
"explore_gamma_space",
"plot_de_genes",
]
38 changes: 14 additions & 24 deletions destvi_utils/_destvi_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -151,17 +149,15 @@ def plot_proportions_xy(ax, threshold):
tmpfile = BytesIO()
plt.savefig(tmpfile, format="png")
encoded = base64.b64encode(tmpfile.getvalue()).decode("utf-8")
html += "<img src='data:image/png;base64,{}'>".format(encoded)
html += f"<img src='data:image/png;base64,{encoded}'>"
plt.close()
else:
plt.show()

# 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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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])

Expand All @@ -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 += "<img src='data:image/png;base64,{}'>".format(encoded)
html += f"<img src='data:image/png;base64,{encoded}'>"
else:
plt.show()

Expand All @@ -332,7 +328,7 @@ def explore_gamma_space(
if output_file is not None:
html += f"<h4>Genes associated with SpatialPC{d + 1}</h4>"
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)
Expand All @@ -356,7 +352,7 @@ def explore_gamma_space(
html += "<p>" + ", ".join(text_signatures) + "</p>"
else:
print("\n")
print("[italic]{}[/italic]".format(mode))
print(f"[italic]{mode}[/italic]")
print(
"---------------------------------------------------------------------------------------"
)
Expand All @@ -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)
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ---------------------------------------------

Expand Down
6 changes: 4 additions & 2 deletions tests/test_destvi_utils.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down
Loading