From 503363aa1be9bf89a03e10f020c5e273d6bf4852 Mon Sep 17 00:00:00 2001 From: Rongting Date: Sat, 15 Jun 2024 15:22:10 +0800 Subject: [PATCH] enviroment and installation --- docs/FAQ.rst | 12 +++++++++--- docs/release.rst | 8 ++++++++ setup.py | 2 +- xclone/model/_RDR_smoothing.py | 35 ++++++++++++++++++++++++++++++---- xclone/version.py | 2 +- 5 files changed, 50 insertions(+), 9 deletions(-) diff --git a/docs/FAQ.rst b/docs/FAQ.rst index b39bc65..a2698d3 100644 --- a/docs/FAQ.rst +++ b/docs/FAQ.rst @@ -11,7 +11,7 @@ Top Questions Input and Output ---------------- -CNV Modules +CNA Modules ----------- Parameters @@ -19,6 +19,8 @@ Parameters Version 0.3.4 specific issues ----------------------------- +Not support python >3.7. +Recommend XClone version 0.3.6 for Python >3.7 environment. FileNotFoundError ~~~~~~~~~~~~~~~~~ @@ -74,7 +76,9 @@ You may download the `anno_data` from the following URL and place the files unde Version 0.3.5 specific issues ----------------------------- -Not reproted so far. +Not support python >3.7. +Recommend XClone version 0.3.6 for Python >3.7 environment. +No other issues reproted so far. Dependency @@ -89,6 +93,8 @@ You may encounter an error indicating that the `requests` module is not found (i pip install requests +This Dependency issues solved in XClone version 0.3.6. + ModuleNotFoundError: No module named 'importlib.metadata' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -178,4 +184,4 @@ The most import step you may try is: pip install scanpy - +This Dependency issues solved in XClone version 0.3.6. diff --git a/docs/release.rst b/docs/release.rst index 96eabae..3820baf 100644 --- a/docs/release.rst +++ b/docs/release.rst @@ -1,6 +1,14 @@ Release History =============== +Version 0.3.6 +------------- +- update Dependency for installation +- [Python version supporting] XClone support Python >3.7 + adding a nonzero scalar to a sparse array is not supported by `scipy` in Python > 3.7 (which exists in RDR_smothing functions). + + + Version 0.3.5 ------------- - [BAF] add allele flip status for each gene in Local phasing and Global phasing diff --git a/setup.py b/setup.py index d74cd9e..b45f8cf 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ long_description = f.read() reqs = ['numpy>=1.18', 'scipy', 'matplotlib', 'anndata', - 'statsmodels', 'scanpy', 'h5py', 'palettable'] + 'statsmodels', 'scanpy', 'h5py', 'palettable', 'requests', 'importlib-metadata'] # seaborn diff --git a/xclone/model/_RDR_smoothing.py b/xclone/model/_RDR_smoothing.py index d3afe92..a992c5e 100644 --- a/xclone/model/_RDR_smoothing.py +++ b/xclone/model/_RDR_smoothing.py @@ -5,6 +5,8 @@ # update: 2022/07/26 import numpy as np +import scanpy as sc +import scipy.sparse as sp from .smoothing import WMA_smooth, KNN_smooth ## Smoothing strategy @@ -25,12 +27,37 @@ def RDR_smoothing_base(Xdata, """ ## preprocess ## normalization [follow scanpy pipeline] + # Xdata_norm.X = np.log(Xdata_norm.X/Xdata_norm.X.sum(1) * 10000 + 1) + # Notes: this only supported by python<3.7 if issparse + # sc.pp.normalize_total from the Scanpy library supports both dense and sparse matrices. + Xdata_norm = Xdata.copy() - Xdata_norm.X = np.log(Xdata_norm.X/Xdata_norm.X.sum(1) * 10000 + 1) - _is_ref = Xdata_norm.obs[cell_anno_key] == ref_celltype - Xdata_norm.var['ref_mean'] = Xdata_norm[_is_ref, :].X.mean(0) - Xdata_norm.var['ref_var'] = Xdata_norm[_is_ref, :].X.var(0) + + # Normalize and log transform using scanpy functions + sc.pp.normalize_total(Xdata_norm, target_sum=10000) + sc.pp.log1p(Xdata_norm) + + # Check if Xdata_norm.X is a sparse matrix + if sp.issparse(Xdata_norm.X): + # # Perform operations in a way that supports sparse matrices + # sums = np.array(Xdata_norm.X.sum(axis=1)).flatten() + # Xdata_norm.X = Xdata_norm.X.multiply(1 / sums[:, None]) + # Xdata_norm.X = Xdata_norm.X.multiply(10000) + # # Create a sparse matrix of ones with the same shape + # ones_sparse = sp.csr_matrix(np.ones(Xdata_norm.X.shape)) + # # Add the sparse matrix of ones to the original sparse matrix + # Xdata_norm.X = Xdata_norm.X + ones_sparse + # Xdata_norm.X.data = np.log(Xdata_norm.X.data) + + Xdata_norm.var['ref_mean'] = np.array(Xdata_norm[_is_ref, :].X.mean(axis=0)).flatten() + ref_data_dense = Xdata_norm[_is_ref, :].X.toarray() + Xdata_norm.var['ref_var'] = ref_data_dense.var(axis=0) + else: + # Xdata_norm.X = np.log(Xdata_norm.X / Xdata_norm.X.sum(axis=1) * 10000 + 1) + Xdata_norm.var['ref_mean'] = Xdata_norm[_is_ref, :].X.mean(0) + Xdata_norm.var['ref_var'] = Xdata_norm[_is_ref, :].X.var(0) + adata_tmp = Xdata_norm.copy() adata_tmp.X = adata_tmp.X - Xdata_norm.var['ref_mean'].values.reshape(1, -1) diff --git a/xclone/version.py b/xclone/version.py index a8d4557..d7b30e1 100644 --- a/xclone/version.py +++ b/xclone/version.py @@ -1 +1 @@ -__version__ = "0.3.5" +__version__ = "0.3.6"