Skip to content

Commit

Permalink
Merge pull request #581 from Sichao25/upgrade
Browse files Browse the repository at this point in the history
Debug the pp/transform
  • Loading branch information
Xiaojieqiu authored Oct 6, 2023
2 parents 153f5b7 + e09a966 commit dcfa5e0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
20 changes: 11 additions & 9 deletions dynamo/preprocessing/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ def _Freeman_Tukey(X: np.ndarray, inverse=False) -> np.ndarray:
"""

if inverse:
res = np.sqrt(X) + np.sqrt((X + 1))
else:
res = (X**2 - 1) ** 2 / (4 * X**2)
else:
res = np.sqrt(X) + np.sqrt((X + 1))

return res

Expand Down Expand Up @@ -87,12 +87,11 @@ def Freeman_Tukey_inplace(adata: AnnData, layer: str = DKM.X_LAYER) -> None:
if is_integer_arr(mat.data):
mat = mat.asfptype()
DKM.set_layer_data(adata, layer, mat)
_Freeman_Tukey(mat.data)
mat.data = _Freeman_Tukey(mat.data)
else:
mat = mat.astype(np.float)
_Freeman_Tukey(mat)
mat = mat.astype(np.float64)
mat = _Freeman_Tukey(mat)

mat.data -= 1
DKM.set_layer_data(adata, layer, mat)


Expand All @@ -111,8 +110,9 @@ def log_inplace(adata: AnnData, layer: str = DKM.X_LAYER) -> None:
DKM.set_layer_data(adata, layer, mat)
_log_inplace(mat.data)
else:
mat = mat.astype(np.float)
mat = mat.astype(np.float64)
_log_inplace(mat)
DKM.set_layer_data(adata, layer, mat)


def log1p_inplace(adata: AnnData, layer: str = DKM.X_LAYER) -> None:
Expand All @@ -130,8 +130,9 @@ def log1p_inplace(adata: AnnData, layer: str = DKM.X_LAYER) -> None:
DKM.set_layer_data(adata, layer, mat)
_log1p_inplace(mat.data)
else:
mat = mat.astype(np.float)
mat = mat.astype(np.float64)
_log1p_inplace(mat)
DKM.set_layer_data(adata, layer, mat)


def log2_inplace(adata: AnnData, layer: str = DKM.X_LAYER) -> None:
Expand All @@ -149,8 +150,9 @@ def log2_inplace(adata: AnnData, layer: str = DKM.X_LAYER) -> None:
DKM.set_layer_data(adata, layer, mat)
_log2_inplace(mat.data)
else:
mat = mat.astype(np.float)
mat = mat.astype(np.float64)
_log2_inplace(mat)
DKM.set_layer_data(adata, layer, mat)


def is_log1p_transformed_adata(adata: anndata.AnnData) -> bool:
Expand Down
2 changes: 1 addition & 1 deletion dynamo/tools/markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ def glm_degs(
if adata.uns["pp"][norm_method_key] == "log2"
else np.exp(X_data.data) - 1
if adata.uns["pp"][norm_method_key] == "log"
else _Freeman_Tukey(X_data.data + 1, inverse=True)
else _Freeman_Tukey(X_data.data + 1, inverse=True) - 1
if adata.uns["pp"][norm_method_key] == "Freeman_Tukey"
else X_data.data
)
Expand Down
2 changes: 1 addition & 1 deletion dynamo/tools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,7 @@ def inverse_norm(adata: AnnData, layer_x: Union[np.ndarray, sp.csr_matrix]) -> n
if adata.uns["pp"]["layers_norm_method"] == "log2"
else np.exp(layer_x.data) - 1
if adata.uns["pp"]["layers_norm_method"] == "log"
else _Freeman_Tukey(layer_x.data + 1, inverse=True)
else _Freeman_Tukey(layer_x.data + 1, inverse=True) - 1
if adata.uns["pp"]["layers_norm_method"] == "Freeman_Tukey"
else layer_x.data
)
Expand Down

0 comments on commit dcfa5e0

Please sign in to comment.