Skip to content

Commit

Permalink
Merge pull request #100 from KrishnaswamyLab/dev
Browse files Browse the repository at this point in the history
fix mendeley link
  • Loading branch information
scottgigante committed Jan 19, 2021
2 parents b450114 + b59b486 commit 1045d7e
Show file tree
Hide file tree
Showing 8 changed files with 189 additions and 19 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Publish Python 🐍 distributions 📦 to PyPI

on:
push:
branches:
- 'master'
- 'test_deploy'
tags:
- '*'

jobs:
build-n-publish:
name: Build and publish Python 🐍 distributions 📦 to PyPI
runs-on: ubuntu-18.04

steps:
- uses: actions/checkout@master

- name: Set up Python 3.7
uses: actions/setup-python@v2
with:
python-version: 3.7

- name: Install pypa/build
run: |
cd Python
python -m pip install build --user
- name: Build a binary wheel and a source tarball
run: |
python -m build --sdist --wheel --outdir dist/ .
- name: Publish distribution 📦 to Test PyPI
uses: pypa/gh-action-pypi-publish@master
with:
skip_existing: true
password: ${{ secrets.test_pypi_password }}
repository_url: https://test.pypi.org/legacy/

- name: Publish distribution 📦 to PyPI
if: startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{ secrets.pypi_password }}
113 changes: 113 additions & 0 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
name: Unit Tests

on:
push:
branches-ignore:
- 'test_deploy'
pull_request:
branches:
- '*'

jobs:
run_linter:
runs-on: ${{ matrix.config.os }}
if: "!contains(github.event.head_commit.message, 'ci skip')"

strategy:
fail-fast: false
matrix:
config:
- {name: 'current', os: ubuntu-latest, python: '3.8' }

steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.6.0
with:
access_token: ${{ github.token }}

- uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.config.python }}

- name: Install tools
run: |
python -m pip install --upgrade "pip<=21.0"
pip install --use-deprecated=legacy-resolver -U wheel setuptools
pip install --use-deprecated=legacy-resolver -U black flake8
- name: Lint with Black
run: |
cd Python
black . --check --diff
- name: Lint with flake8
run: |
flake8 phate || true
run_tester:
runs-on: ${{ matrix.config.os }}
if: "!contains(github.event.head_commit.message, 'ci skip')"

strategy:
fail-fast: false
matrix:
config:
- {name: 'current', os: ubuntu-latest, python: '3.8' }
- {name: 'prev', os: ubuntu-latest, python: '3.7' }
- {name: 'old', os: ubuntu-latest, python: '3.6' }

steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.6.0
with:
access_token: ${{ github.token }}

- uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Install system dependencies
if: runner.os == 'Linux'
run: |
sudo apt-get update -qq
sudo apt-get install -y libhdf5-dev libhdf5-serial-dev pandoc gfortran libblas-dev liblapack-dev libedit-dev llvm-dev libcurl4-openssl-dev ffmpeg
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.config.python }}

- name: Cache Python packages
uses: actions/cache@v2
with:
path: ${{ env.pythonLocation }}
key: ${{runner.os}}-pip-${{ env.pythonLocation }}-${{ hashFiles('setup.py') }}
restore-keys: ${{runner.os}}-pip-${{ env.pythonLocation }}-

- name: Install package & dependencies
run: |
cd Python
python -m pip install --upgrade "pip<=21.0"
pip install --use-deprecated=legacy-resolver -U wheel setuptools
pip install --use-deprecated=legacy-resolver -U .[test]
python -c "import phate"
- name: Run tests
run: |
nose2 -vvv
- name: Coveralls
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_SERVICE_NAME: github
run: |
coveralls
- name: Upload check results on fail
if: failure()
uses: actions/upload-artifact@master
with:
name: ${{ matrix.config.name }}_results
path: check
29 changes: 19 additions & 10 deletions Python/phate/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import numpy as np
from .phate import PHATE


def silhouette_score(phate_op, n_clusters, random_state=None, **kwargs):
"""Compute the Silhouette score on KMeans on the PHATE potential
Expand All @@ -19,12 +20,15 @@ def silhouette_score(phate_op, n_clusters, random_state=None, **kwargs):
-------
score : float
"""
cluster_labels = kmeans(phate_op, n_clusters=n_clusters, random_state=random_state, **kwargs)
cluster_labels = kmeans(
phate_op, n_clusters=n_clusters, random_state=random_state, **kwargs
)
return metrics.silhouette_score(phate_op.diff_potential, cluster_labels)



def kmeans(phate_op, n_clusters='auto', max_clusters=10, random_state=None, k=None, **kwargs):

def kmeans(
phate_op, n_clusters="auto", max_clusters=10, random_state=None, k=None, **kwargs
):
"""KMeans on the PHATE potential
Clustering on the PHATE operator as introduced in Moon et al.
Expand Down Expand Up @@ -55,15 +59,20 @@ def kmeans(phate_op, n_clusters='auto', max_clusters=10, random_state=None, k=No
)
n_clusters = k
if not isinstance(phate_op, PHATE):
raise TypeError("Expected phate_op to be of type PHATE. Got {}".format(phate_op))
raise TypeError(
"Expected phate_op to be of type PHATE. Got {}".format(phate_op)
)
if phate_op.graph is not None:
if n_clusters == 'auto':
if n_clusters == "auto":
n_clusters = np.arange(2, max_clusters)
silhouette_scores = [silhouette_score(phate_op, k, random_state=random_state, **kwargs) for k in n_clusters]
silhouette_scores = [
silhouette_score(phate_op, k, random_state=random_state, **kwargs)
for k in n_clusters
]
n_clusters = n_clusters[np.argmax(silhouette_scores)]
return cluster.KMeans(n_clusters, random_state=random_state, **kwargs).fit_predict(
phate_op.diff_potential
)
return cluster.KMeans(
n_clusters, random_state=random_state, **kwargs
).fit_predict(phate_op.diff_potential)
else:
raise exceptions.NotFittedError(
"This PHATE instance is not fitted yet. Call "
Expand Down
2 changes: 1 addition & 1 deletion Python/phate/mds.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def smacof(
n_components : int, optional (default: 2)
number of dimensions in which to embed `D`
metric : bool, optional (default: True)
Use metric MDS. If False, uses non-metric MDS
Expand Down
6 changes: 4 additions & 2 deletions Python/phate/phate.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def __init__(
@property
def diff_op(self):
"""diff_op : array-like, shape=[n_samples, n_samples] or [n_landmark, n_landmark]
The diffusion operator built from the graph
The diffusion operator built from the graph
"""
if self.graph is not None:
if isinstance(self.graph, graphtools.graphs.LandmarkGraph):
Expand Down Expand Up @@ -794,7 +794,9 @@ def fit(self, X):

if precomputed is None:
_logger.info(
"Running PHATE on {} observations and {} variables.".format(X.shape[0], X.shape[1])
"Running PHATE on {} observations and {} variables.".format(
X.shape[0], X.shape[1]
)
)
else:
_logger.info(
Expand Down
2 changes: 1 addition & 1 deletion Python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"s_gd2>=1.5",
]

test_requires = ["nose2", "anndata"]
test_requires = ["nose2", "anndata", "coverage", "coveralls"]

doc_requires = ["sphinx", "sphinxcontrib-napoleon"]

Expand Down
6 changes: 4 additions & 2 deletions Python/test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_simple():
phate_operator = phate.PHATE(knn=15, t=100, verbose=False)
tree_phate = phate_operator.fit_transform(tree_data)
assert tree_phate.shape == (tree_data.shape[0], 2)
clusters = phate.cluster.kmeans(phate_operator, n_clusters='auto')
clusters = phate.cluster.kmeans(phate_operator, n_clusters="auto")
assert np.issubdtype(clusters.dtype, np.signedinteger)
assert len(np.unique(clusters)) >= 2
assert len(clusters.shape) == 1
Expand All @@ -57,7 +57,9 @@ def test_simple():
G = pygsp.graphs.Graph(G.W)
phate_operator.fit(G)
phate_operator.fit(anndata.AnnData(tree_data))
with assert_raises_message(TypeError, "Expected phate_op to be of type PHATE. Got 1"):
with assert_raises_message(
TypeError, "Expected phate_op to be of type PHATE. Got 1"
):
phate.cluster.kmeans(1)


Expand Down
6 changes: 3 additions & 3 deletions Python/tutorial/EmbryoidBody.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@
"if not os.path.isdir(os.path.join(download_path, \"scRNAseq\", \"T0_1A\")):\n",
" # need to download the data\n",
" scprep.io.download.download_and_extract_zip(\n",
" \"https://data.mendeley.com/datasets/v6n743h5ng\"\n",
" \"/1/files/7489a88f-9ef6-4dff-a8f8-1381d046afe3/scRNAseq.zip?dl=1\",\n",
" \"https://md-datasets-public-files-prod.s3.eu-west-1.amazonaws.com/\"\n",
" \"5739738f-d4dd-49f7-b8d1-5841abdbeb1e\",\n",
" download_path)"
]
},
Expand Down Expand Up @@ -114793,7 +114793,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.8.5"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 1045d7e

Please sign in to comment.