Skip to content

Commit

Permalink
Creat sphinx documentation architechture
Browse files Browse the repository at this point in the history
  • Loading branch information
mvfki committed Oct 9, 2023
1 parent c14f4ae commit 264372f
Show file tree
Hide file tree
Showing 45 changed files with 1,960 additions and 582 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pyNote.py
test.h5ad

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
32 changes: 32 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# .readthedocs.yaml
# Read the Docs configuration file
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

# Set the OS, Python version and other tools you might need
build:
os: ubuntu-22.04
tools:
python: "3.11"
# You can also specify other tool versions:
# nodejs: "19"
# rust: "1.64"
# golang: "1.19"

# Build documentation in the "docs/" directory with Sphinx
sphinx:
configuration: docs/conf.py

# Optionally build your docs in additional formats such as PDF and ePub
# formats:
# - pdf
# - epub

# Optional but recommended, declare the Python requirements required
# to build your documentation
# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
# python:
# install:
# - requirements: docs/requirements.txt
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<img src="docs/logo.png" align="right" width="120" />
<img src="docs/images/logo.png" align="right" width="120" />

# CytoSimplex
# CytoSimplex
[![Python3_10_test](https://github.com/mvfki/pyCytoSimplex/actions/workflows/python-package.yml/badge.svg)](https://github.com/mvfki/pyCytoSimplex/actions/workflows/python-package.yml)[![codecov](https://codecov.io/gh/mvfki/pyCytoSimplex/branch/main/graph/badge.svg?token=L839lYPVon)](https://codecov.io/gh/mvfki/pyCytoSimplex)[![AnnData-0.9.1](https://img.shields.io/badge/AnnData-0.9.1-blue)](https://pypi.org/project/anndata/)

"CytoSimplex" is a Python module that creates simplex plot showing similarity between single-cells and terminals represented by clusters of cells.
Expand Down
13 changes: 13 additions & 0 deletions cleanup
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
rm -rf build
rm -rf dist
rm -rf htmlcov
rm -rf src/CytoSimplex.egg-info
rm -rf src/CytoSimplex/__pycache__
rm -rf src/CytoSimplex/tests/__pycache__
rm src/CytoSimplex/tests/.coverage
rm -rf .pytest_cache

cd docs
make clean
cd ..

2 changes: 2 additions & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test.h5ad

20 changes: 20 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
124 changes: 124 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
from sphinx.application import Sphinx


# Configuration file for the Sphinx documentation builder.
#
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

project = 'CytoSimplex'
copyright = '2023, Yichen Wang, Jialin Liu, Joshua D. Welch'
author = 'Yichen Wang, Jialin Liu, Joshua D. Welch'
release = '0.1.0'
repository_url = "https://github.com/mvfki/pyCytoSimplex"

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

nitpicky = True # Warn about broken links. This is here for a reason: Do not change.
nitpick_ignore = [('py:class', 'type')]
needs_sphinx = '4.0' # Nicer param docs


def setup(app: Sphinx):
"""App setup hook."""
app.add_config_value(
"recommonmark_config",
{
"auto_toc_tree_section": "Contents",
"enable_auto_toc_tree": True,
"enable_math": True,
"enable_inline_math": False,
"enable_eval_rst": True,
},
True,
)


extensions = [
'myst_nb',
'sphinx_copybutton',
'sphinx.ext.autodoc',
'sphinx.ext.intersphinx',
'sphinx.ext.doctest',
'sphinx.ext.coverage',
'sphinx.ext.mathjax',
'sphinx.ext.napoleon',
'sphinx.ext.autosummary',
'sphinx.ext.extlinks',
'matplotlib.sphinxext.plot_directive',
'sphinx_autodoc_typehints', # needs to be after napoleon
# 'git_ref', # needs to be before scanpydoc.rtd_github_links
'sphinx_design',
'sphinxext.opengraph',
'sphinx.ext.viewcode',
'nbsphinx'
]
napoleon_attr_annotations = True
# Generate the API documentation when building
autosummary_generate = True
autodoc_member_order = 'bysource'
# autodoc_default_flags = ['members']
napoleon_google_docstring = False
napoleon_numpy_docstring = True
napoleon_include_init_with_doc = False
napoleon_use_rtype = True # having a separate entry generally helps readability
napoleon_use_param = True
napoleon_custom_sections = [('Params', 'Parameters')]
todo_include_todos = False
# api_dir = HERE / 'api' # function_images
myst_enable_extensions = [
"amsmath",
"colon_fence",
"deflist",
"dollarmath",
"html_image",
"html_admonition",
]
myst_url_schemes = ("http", "https", "mailto")
nb_output_stderr = "remove"
nb_execution_mode = "off"
nb_merge_streams = True
templates_path = ['_templates']
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']

plot_include_source = True
plot_formats = [("png", 90)]
plot_html_show_formats = False
plot_html_show_source_link = False

# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

html_theme = 'sphinx_book_theme'
html_theme_options = {
"repository_url": repository_url,
"use_repository_button": True,
}
# html_css_files = ["css/override.css"]
html_show_sphinx = False
# html_logo = 'images/logo_bright.svg'
html_theme_options = {
"logo": {
"image_light": "images/logo_bright.png",
"image_dark": "images/logo_dark.png",
}
}
html_title = "CytoSimplex"
html_static_path = ['_static']
html_css_files = ["css/override.css"]
master_doc = 'source/index'

intersphinx_mapping = dict(
anndata=('https://anndata.readthedocs.io/en/stable/', None),
matplotlib=('https://matplotlib.org/stable/', None),
numpy=('https://numpy.org/doc/stable/', None),
pandas=('https://pandas.pydata.org/pandas-docs/stable/', None),
pytest=('https://docs.pytest.org/en/latest/', None),
python=('https://docs.python.org/3', None),
scipy=('https://docs.scipy.org/doc/scipy/', None),
sklearn=('https://scikit-learn.org/stable/', None),
)
Binary file added docs/images/.DS_Store
Binary file not shown.
Binary file added docs/images/bmmc_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/logo_bright.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/logo_dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/logo.png
Binary file not shown.
35 changes: 35 additions & 0 deletions docs/make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@ECHO OFF

pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=.
set BUILDDIR=_build

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.https://www.sphinx-doc.org/
exit /b 1
)

if "%1" == "" goto help

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end

:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%

:end
popd
16 changes: 16 additions & 0 deletions docs/source/api/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
========================================================================
API
========================================================================

To use CytoSimplex functions, import the package in Python script:

.. code-block:: python
import CytoSimplex as csx
.. toctree::
:maxdepth: 2

preprocessing
visualization
10 changes: 10 additions & 0 deletions docs/source/api/preprocessing.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

Preprocessing
^^^^^^^^^^^^^

.. currentmodule:: CytoSimplex
.. autosummary::
:toctree: ../generated/

row_normalize
select_top_features
11 changes: 11 additions & 0 deletions docs/source/api/visualization.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

Visualization
^^^^^^^^^^^^^

.. currentmodule:: CytoSimplex
.. autosummary::
:toctree: ../generated/

plot_binary
plot_ternary
plot_quaternary
78 changes: 78 additions & 0 deletions docs/source/example/binary.ipynb

Large diffs are not rendered by default.

46 changes: 46 additions & 0 deletions docs/source/example/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
=======
Example
=======

This package use simplex barycentric coordinate approach to assist exploration in the similarity between single cells
between selected cell clusters. We denote a number (2-4) of selected clusters, or groups of clusters, as vertices.
We calculate the similarity between each single cell and the average point of each vertex. By normalizing the similarity
between each single cell and all specified vertices to a unit sum, we can derive the barycentric coordinates for each single cell.
Visualization method for binary (ended line), ternary (equilateral triangle) and quaternary (tetrahedron) simplex are developed.
The main plotting functions are :func:`~CytoSimplex.plot_binary`, :func:`~CytoSimplex.plot_ternary` and :func:`~CytoSimplex.plot_quaternary`, respectively.

Test Dataset
^^^^^^^^^^^^

The dataset used in all example can be found on `figshare <https://figshare.com/ndownloader/files/41034857>`_.
This is a small subset of publicly available single cell RNA-seq data from the human bone marrow mononuclear cells (BMMC)
generated in our previous study [1]_. The data is stored in a ``.h5ad`` file format, which can be read by the
`AnnData <https://anndata.readthedocs.io/en/stable/index.html>`_ package. Users can load the dataset following the code below.

.. code-block:: python
import CytoSimplex as csx
import anndata
adata = anndata.read(filename='test.h5ad',
backup_url="https://figshare.com/ndownloader/files/41034857")
The contents included in the ``adata`` object include:

- ``adata.X``: A CSR sparse matrix of 250 rows (cells) by 20,243 columns (genes) containing the raw gene count matrix.
- ``adata.obs["cluster"]``: A categorical annotation of cell clusters. There are totally 12 clusters which can be viewed via ``adata.obs["cluster"].cat.categories``.
Namingly, 'Chondrocyte_1', 'Chondrocyte_2', 'Chondrocyte_3', 'OCT_Stem', 'ORT_1', 'ORT_2', 'ORT_3', 'Osteoblast_1', 'Osteoblast_2', 'Osteoblast_3', 'Reticular_1' and 'Reticular_2'.
- ``adata.uns["velo"]``: A 250 by 250 CSR sparse matrix of velocity neighbor graph. This is derived with `veloVAE <https://github.com/welch-lab/VeloVAE>`_ [2]_.
We will have more introduction to this in detailed examples.


.. toctree::
:maxdepth: 2
:caption: Contents:

select_top_features
ternary
binary
quaternary

.. [1] Matsushita, Y., Liu, J., Chu, A.K.Y. et al. Bone marrow endosteal stem cells dictate active osteogenesis and aggressive tumorigenesis. Nat Commun 14, 2383 (2023). https://doi.org/10.1038/s41467-023-38034-2
.. [2] Gu, Y., Blaauw, D., Welch, J. D.. Bayesian Inference of RNA Velocity from Multi-Lineage Single-Cell Data. bioRxiv (2022). https://doi.org/10.1101/2022.07.08.499381
196 changes: 196 additions & 0 deletions docs/source/example/quaternary.ipynb

Large diffs are not rendered by default.

Loading

0 comments on commit 264372f

Please sign in to comment.