Skip to content

Commit

Permalink
Merge pull request #78 from PixelgenTechnologies/chore/fix-a-bunch-of…
Browse files Browse the repository at this point in the history
…-warnings

Fix a bunch of warnings generated in the tests
  • Loading branch information
johandahlberg authored Feb 2, 2024
2 parents a92335d + 86fb81b commit 6a7adf5
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 67 deletions.
33 changes: 17 additions & 16 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pyarrow = ">=13,<15"
semver = "^3.0.0"
ruamel-yaml = "^0.17.21"
pydantic = "^1.10.7"
polars = "^0.19"
polars = "^0.20"
importlib-resources = "^5.12.0"
fsspec = "^2023.9.0"
fastparquet = "^2023.8.0"
Expand Down
8 changes: 6 additions & 2 deletions src/pixelator/analysis/colocalization/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ def colocalization_from_component_edgelist(
graph = Graph.from_edgelist(
edgelist=edgelist,
add_marker_counts=True,
simplify=False,
# If we do A-node projection, we will simplify anyway.
# This just removes the warning.
simplify=False if use_full_bipartite else True,
use_full_bipartite=use_full_bipartite,
)
return colocalization_from_component_graph(
Expand Down Expand Up @@ -244,7 +246,9 @@ def data():
graph = Graph.from_edgelist(
edgelist=component_df,
add_marker_counts=True,
simplify=False,
# If we do A-node projection, we will simplify anyway.
# This just removes the warning.
simplify=False if use_full_bipartite else True,
use_full_bipartite=use_full_bipartite,
)
if len(graph.vs) < 2:
Expand Down
4 changes: 3 additions & 1 deletion src/pixelator/analysis/colocalization/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ def prepare_from_edgelist(
.groupby(by=group_by)["marker"]
.value_counts()
.reset_index()
).pivot_table(index=group_by, columns="marker", values="count", fill_value=0)
).pivot_table(
index=group_by, columns="marker", values="count", fill_value=0, observed=False
)
markers_per_pixel.columns.name = "markers"
markers_per_pixel.index.name = "node"
markers_per_pixel.index = markers_per_pixel.index.astype("string[pyarrow]")
Expand Down
2 changes: 1 addition & 1 deletion src/pixelator/analysis/colocalization/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def _wide_correlation_matrix_to_long_correlation_results(
df_lower_tri = df.mask(~lower_triangle)
df_lower_tri.index.set_names(["marker_cols"], inplace=True)
df_lower_tri.columns.set_names(["marker_rows"], inplace=True)
correlation_values = df_lower_tri.stack(dropna=True).reset_index()
correlation_values = df_lower_tri.stack(future_stack=True).dropna().reset_index()
correlation_values.columns = ["marker_1", "marker_2", stat_name]
correlation_values.set_index(["marker_1", "marker_2"], inplace=True)
correlation_values.index.rename(["marker_1", "marker_2"])
Expand Down
32 changes: 17 additions & 15 deletions src/pixelator/config/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,23 +183,25 @@ def _transform_legacy_panels(cls, df: pd.DataFrame) -> pd.DataFrame:
:param df: DataFrame with data of the panel to validate
:returns pd.DataFrame: The in-place modified input dataframe
"""
new_df = df.copy()

# update control and nuclear column to boolean
TR_TABLE = {"(?i)no": "False", "(?i)yes": "True"}

new_df.replace(
{
"control": TR_TABLE,
"nuclear": TR_TABLE,
},
regex=True,
inplace=True,
TR_TABLE = {"(?i)yes": "True", "(?i)no": "False"}

df["control"] = (
df["control"]
.astype("string[pyarrow]")
.fillna("")
.replace(TR_TABLE, regex=True)
.astype(bool)
)
df["nuclear"] = (
df["nuclear"]
.astype("string[pyarrow]")
.fillna("")
.replace(TR_TABLE, regex=True)
.astype(bool)
)
new_df.fillna({"control": "False", "nuclear": "False"}, inplace=True)
new_df["control"] = new_df["control"].map({"True": True, "False": False})
new_df["nuclear"] = new_df["nuclear"].map({"True": True, "False": False})
return new_df

return df

@classmethod
def _parse_header(cls, file: Path) -> AntibodyPanelMetadata:
Expand Down
4 changes: 2 additions & 2 deletions src/pixelator/report/qcreport/collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ def collect_reads_per_umi_frequency(dataset: PixelDataset) -> str:

freq = freq.with_columns(
pl.col("reads_per_umi"),
frequency=pl.col("counts") / pl.col("counts").sum(),
frequency=pl.col("count") / pl.col("count").sum(),
)
pd_freq = freq.rename({"counts": "count"}).sort(by="reads_per_umi").to_pandas()
pd_freq = freq.sort(by="reads_per_umi").to_pandas()

return pd_freq.to_csv(index=False)

Expand Down
12 changes: 5 additions & 7 deletions tests/data/param_files/test_data_pe_T1.amplicon.meta.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{
"cli": {
"command": "pixelator single-cell amplicon",
"options": {
"--input1-pattern": "_R1",
"--input2-pattern": "_R2",
"--output": "."
}
"cli": {
"command": "pixelator single-cell amplicon",
"options": {
"--output": "."
}
}
}
12 changes: 0 additions & 12 deletions tests/data/report/info_and_metrics.json
Original file line number Diff line number Diff line change
Expand Up @@ -364,18 +364,6 @@
{
"command": "pixelator single-cell amplicon",
"options": [
{
"name": "--input1-pattern",
"value": "_R1",
"default_value": "_R1",
"description": "The string pattern to use to identify forward (R1) files"
},
{
"name": "--input2-pattern",
"value": "_R2",
"default_value": "_R2",
"description": "The string pattern to use to identify reverse (R2) files"
},
{
"name": "--output",
"value": ".",
Expand Down
4 changes: 2 additions & 2 deletions tests/graph/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ def create_simple_edge_list_from_graph(

df = graph.get_edge_dataframe()
df_vert = graph.get_vertex_dataframe()
df["source"].replace(df_vert["name"], inplace=True)
df["target"].replace(df_vert["name"], inplace=True)
df["source"] = df["source"].replace(df_vert["name"])
df["target"] = df["target"].replace(df_vert["name"])

# rename source/target columns
df = df.rename(columns={"source": "upib", "target": "upia"})
Expand Down
23 changes: 15 additions & 8 deletions tests/plot/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
Copyright (c) 2023 Pixelgen Technologies AB.
"""


import numpy as np
import pytest
from numpy.testing import assert_almost_equal
from pixelator.graph import Graph
from pixelator.plot import (
Expand Down Expand Up @@ -460,10 +460,17 @@ def test_plot_3d_heatmap(edgelist):
simplify=True,
use_full_bipartite=False,
)
# For now, just making sure that this doesn't crash when running.
_ = plot_3d_heatmap(
graph,
layout_algorithm="fruchterman_reingold_3d",
marker="CD3",
distance_cutoff=0.4,
)
with pytest.warns(
UserWarning,
match=(
"The function `plot_3d_heatmap` is experimental, "
"it might be removed or the API might change without notice."
),
):
# For now, just making sure that this doesn't crash when running.
_ = plot_3d_heatmap(
graph,
layout_algorithm="fruchterman_reingold_3d",
marker="CD3",
distance_cutoff=0.4,
)

0 comments on commit 6a7adf5

Please sign in to comment.