Skip to content

Commit

Permalink
version 0.3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Rongtingting committed Jun 16, 2024
1 parent 503363a commit eeda1e8
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 21 deletions.
108 changes: 96 additions & 12 deletions docs/FAQ.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,95 @@ CNA Modules
Parameters
----------

Version 0.3.4 specific issues
-----------------------------
Not support python >3.7.
Recommend XClone version 0.3.6 for Python >3.7 environment.

Python Environment
------------------

For detailed information about Python environments, refer to the `Python environments issue <https://github.com/single-cell-genetics/XClone/issues/6>`_.

XClone versions 0.3.4 and 0.3.5 perform optimally on Python 3.7 (not >3.7 due to dependency issues). We recommend using conda to manage the environment.
You can use the following environment files to create a suitable conda environment for running XClone:

- [xclone0.3.4Python3.7_env.yml](https://github.com/Rongtingting/xclone-data/blob/main/XClone_env/xclone0.3.4Python3.7_env.yml)
- [xclone0.3.5Python3.7_env.yml](https://github.com/Rongtingting/xclone-data/blob/main/XClone_env/xclone0.3.5Python3.7_env.yml)


XClone version 0.3.6 works well with Python 3.7 and Python >=3.9 (excluding 3.8 due to dependency issues).

We strongly recommend using Python >=3.9 for XClone versions >=0.3.6.

You can refer to the [xclone0.3.6Python3.9_env.yml](https://github.com/Rongtingting/xclone-data/blob/main/XClone_env/xclone0.3.6Python3.9_env.yml).

Creating a Conda environment from a `.yml` file is straightforward. Below are the steps to create an environment using the provided `xclone0.3.6Python3.9_env.yml` file.

Steps to Create a Conda Environment from a `.yml` File
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

1. **Download the `.yml` file:**

First, download the `xclone0.3.6Python3.9_env.yml` file from the GitHub repository or ensure it's available locally.

2. **Open a terminal or command prompt:**

Ensure you have Conda installed. If not, you can download it from the `Anaconda website <https://www.anaconda.com/products/distribution>`__ or use `Miniconda <https://docs.conda.io/en/latest/miniconda.html>`__ for a lighter version.

3. **Navigate to the directory containing the `.yml` file:**

.. code-block:: sh
cd path/to/your/yml/file
4. **Create the Conda environment:**

Use the `conda env create` command to create an environment from the `.yml` file:

.. code-block:: sh
conda env create -f xclone0.3.6Python3.9_env.yml
5. **Activate the environment:**

After the environment is created, activate it using:

.. code-block:: sh
conda activate xclone_advancepy39
The name of the environment (`xclone_advancepy39`) is derived from the `name` field in the `.yml` file.

### Verification

After creating and activating the environment, you can verify the installation by checking the installed packages:

.. code-block:: sh
conda list
This command will display all the packages and their versions installed in your Conda environment.

By following these steps, you should be able to create and activate a Conda environment based on the specifications provided in the `xclone0.3.6Python3.9_env.yml` file.


Dependency requirements
~~~~~~~~~~~~~~~~~~~~~~~~

For dependency requirements recommended by Poetry, see [xclone0.3.6Python3.9Project.toml](https://github.com/Rongtingting/xclone-data/blob/main/XClone_env/xclone0.3.6Python3.9Project.toml).


XClone Version 0.3.5 specific issues
------------------------------------

Only support python == 3.7.
Recommend XClone version 0.3.6 for Python >=3.9 environment.
No other issues reproted so far.



XClone Version 0.3.4 specific issues
------------------------------------
Only support python == 3.7.
Recommend XClone version 0.3.6 for Python >=3.7 environment.

FileNotFoundError
~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -73,12 +158,6 @@ You may download the `anno_data` from the following URL and place the files unde
`https://github.com/single-cell-genetics/XClone/tree/master/xclone/data/anno_data`


Version 0.3.5 specific issues
-----------------------------

Not support python >3.7.
Recommend XClone version 0.3.6 for Python >3.7 environment.
No other issues reproted so far.


Dependency
Expand All @@ -93,7 +172,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.
This Dependency issues solved in XClone version >=0.3.6.


ModuleNotFoundError: No module named 'importlib.metadata'
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -184,4 +264,8 @@ The most import step you may try is:
pip install scanpy
This Dependency issues solved in XClone version 0.3.6.
This Dependency issues solved in XClone version >=0.3.6 (for Python >=3.9).

For XClone version 0.3.6 (Python ==3.7), the ModuleNotFoundError: No module named 'importlib.metadata' error indicates that the importlib.metadata module is not found,
which is unexpected given that importlib-metadata is included in setup.py and installed. This issue is likely due to the importlib.metadata module being available only in Python 3.8 and later.
Since you are using Python 3.7, you need to install the backport package importlib-metadata.
8 changes: 6 additions & 2 deletions docs/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ Release History

Version 0.3.6
-------------
- update Dependency for installation
- [Python version supporting] XClone support Python >3.7
- [installation] update Dependency for installation
- [FAQ] Comprehensive tutorials on installation and Dependency
- [Python version supporting] XClone support Python "==3.7 or >=3.9"
adding a nonzero scalar to a sparse array is not supported by `scipy` in Python > 3.7 (which exists in RDR_smothing functions).
- [analysis] minor update in Clone function `XClustering`
-




Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
xclone - Inference of clonal Copy Number Variation in single cells
xclone - Inference of clonal Copy Number Alterations in single cells
See: https://github.com/single-cell-genetics/XClone
"""

Expand Down Expand Up @@ -31,7 +31,7 @@
# https://packaging.python.org/en/latest/single_source_version.html
version=__version__,

description='Inference of clonal Copy Number Variation in single cells',
description='Inference of clonal Copy Number Alterations in single cells',
long_description=long_description,

# The project's main homepage.
Expand Down
1 change: 1 addition & 0 deletions xclone/analysis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
from .evaluation import change_res_resolution

from ._clustering import XClustering, Cluster_mapping
from ._clustering import XClustering2

from ._spatial import CalculateSampleCNVProb, CalculateSampleBAF
61 changes: 56 additions & 5 deletions xclone/analysis/_clustering.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,65 @@
"""Base functions for XClone clustering analysis.
"""

def XClustering(Xdata, Xlayer, PCA_comp = 30, n_clusters = 5, method = "k-means"):
def XClustering(Xdata,
Xlayer,
n_clusters = 5,
method = "k-means",
reshape = True,
argmaxprob = False,
PCA = True,
PCA_comp = 30):
"""
"""
from sklearn.decomposition import PCA
from sklearn.cluster import KMeans
from sklearn.cluster import AgglomerativeClustering
import umap

cell_num = Xdata.shape[0]
X_use = Xdata.layers[Xlayer].reshape(cell_num, -1)

if reshape:
cell_num = Xdata.shape[0]
X_use = Xdata.layers[Xlayer].reshape(cell_num, -1)
elif argmaxprob:
X_use = np.argmax(Xdata.layers[Xlayer], axis=2)
else:
X_use = Xdata.layers[Xlayer]


## PCA
reduced_data = PCA(n_components=PCA_comp).fit_transform(X_use)
if PCA:
data = PCA(n_components=PCA_comp).fit_transform(X_use)
else:
data = X_use.copy()


## Clustering
if method == "k-means":
kmeans = KMeans(init="k-means++", n_clusters=n_clusters, n_init=4)
kmeans.fit(data)
Z = kmeans.predict(data)

if method == "Hierarchical":
clustering = AgglomerativeClustering(n_clusters = n_clusters).fit(data)
Z = clustering.labels_

## UMAP
reducer = umap.UMAP()
embedding = reducer.fit_transform(data)


return Z, embedding



def XClustering2(Xdata, Xlayer, PCA_comp = 30, n_clusters = 5, method = "k-means"):
from sklearn.cluster import KMeans
from sklearn.cluster import AgglomerativeClustering
import umap
import numpy as np

X_use = np.argmax(Xdata.layers[Xlayer], axis=2)
reduced_data = X_use.copy()

## Clustering
if method == "k-means":
Expand All @@ -32,6 +78,11 @@ def XClustering(Xdata, Xlayer, PCA_comp = 30, n_clusters = 5, method = "k-means"

return Z, embedding






def Cluster_mapping(Xdata,
pre_anno,
after_anno,
Expand Down

0 comments on commit eeda1e8

Please sign in to comment.