Skip to content

Commit

Permalink
add data type transformation for integer X input
Browse files Browse the repository at this point in the history
  • Loading branch information
Sichao25 committed Oct 31, 2023
1 parent 203400c commit d2fed88
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions dynamo/preprocessing/normalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ def normalize(
recalc_sz: bool = False,
sz_method: Literal["mean-geometric-mean-total", "geometric", "median"] = "median",
scale_to: Union[float, None] = None,
transform_int_to_float: bool = True,
) -> anndata.AnnData:
"""Normalize the gene expression value for the AnnData object.
Expand All @@ -270,6 +271,8 @@ def normalize(
used, `locfunc` will be replaced with `np.nanmedian`. When `mean` is used, `locfunc` will be replaced with
`np.nanmean`. Defaults to "median".
scale_to: the final total expression for each cell that will be scaled to. Defaults to None.
transform_int_to_float: whether to transform the adata.X from int to float32 for normalization. Defaults to
True.
Returns:
An updated anndata object that are updated with normalized expression values for different layers.
Expand Down Expand Up @@ -301,6 +304,11 @@ def normalize(
splicing_total_layers=splicing_total_layers,
)

if "X" in layers and transform_int_to_float and adata.X.dtype == "int":
main_warning("Transforming adata.X from int to float32 for normalization. If you want to disable this, set "
"`transform_int_to_float` to False.")
adata.X = adata.X.astype("float32")

main_debug("size factor normalize following layers: " + str(layers))
for layer in layers:
if layer in excluded_layers:
Expand Down

0 comments on commit d2fed88

Please sign in to comment.