Skip to content

Commit

Permalink
Merge pull request #28 from pinellolab/add_api
Browse files Browse the repository at this point in the history
Add API page to readthedocs
  • Loading branch information
huidongchen authored Sep 8, 2023
2 parents 4f8158e + 6f7b01d commit b1cc64d
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 97 deletions.
74 changes: 73 additions & 1 deletion docs/source/API.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,74 @@
.. automodule:: stream2

API
===
===

Import stream2 as::

import stream2 as st2

Configuration for STREAM2
~~~~~~~~~~~~~~~~~~~~~~~~~
.. autosummary::
:toctree: _autosummary

settings.set_figure_params
settings.set_workdir


Reading
~~~~~~~
.. autosummary::
:toctree: _autosummary

read_csv
read_h5ad
read_10X_output
read_mtx


See more at `anndata <https://anndata.readthedocs.io/en/latest/api.html#reading>`_


Preprocessing
~~~~~~~~~~~~~
.. autosummary::
:toctree: _autosummary

pp.log_transform
pp.normalize
pp.cal_qc_rna
pp.filter_genes
pp.pca
pp.select_variable_genes


Tools
~~~~~
.. autosummary::
:toctree: _autosummary

tl.dimension_reduction
tl.seed_graph
tl.learn_graph
tl.infer_pseudotime
tl.add_path
tl.del_path
tl.get_weights
tl.extend_leaves
tl.refit_graph
tl.project_graph


Plotting
~~~~~~~~
.. autosummary::
:toctree: _autosummary

pl.pca_variance_ratio
pl.variable_genes
pl.violin
pl.graph
pl.dimension_reduction
pl.stream_sc
pl.stream
4 changes: 4 additions & 0 deletions stream2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@
from .readwrite import *

__version__ = "0.1a"

import sys
sys.modules.update(
{f'{__name__}.{m}': globals()[m] for m in ['tl', 'pp', 'pl']})
6 changes: 5 additions & 1 deletion stream2/_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ def set_figure_params(
rc=None,
):
"""Set global parameters for figures. Modified from sns.set()
Parameters
----------
context : string or dict
Plotting context parameters, see seaborn :func:`plotting_context
Plotting context parameters, see seaborn :func:`plotting_context`
style: `string`,optional (default: 'white')
Axes style parameters, see seaborn :func:`axes_style`
palette : string or sequence
Expand All @@ -51,6 +52,9 @@ def set_figure_params(
rc settings properties.
Parameter mappings to override the values in the preset style.
Please see https://matplotlib.org/tutorials/introductory/customizing.html#a-sample-matplotlibrc-file # noqa
Returns
-------
"""
# mpl.rcParams.update(mpl.rcParamsDefault)
sns.set(
Expand Down
24 changes: 12 additions & 12 deletions stream2/plotting/_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def violin(
plt.savefig(
os.path.join(fig_path, fig_name),
pad_inches=1,
bbox_inches="tight",dpi=300,
bbox_inches="tight", dpi=300,
)
plt.close(fig)
if len(list_var) > 0:
Expand Down Expand Up @@ -144,7 +144,7 @@ def violin(
plt.savefig(
os.path.join(fig_path, fig_name),
pad_inches=1,
bbox_inches="tight",dpi=300,
bbox_inches="tight", dpi=300,
)
plt.close(fig)

Expand Down Expand Up @@ -211,7 +211,7 @@ def hist(
plt.savefig(
os.path.join(fig_path, fig_name),
pad_inches=1,
bbox_inches="tight",dpi=300,
bbox_inches="tight", dpi=300,
)
plt.close(fig)
if len(list_var) > 0:
Expand Down Expand Up @@ -240,7 +240,7 @@ def hist(
plt.savefig(
os.path.join(fig_path, fig_name),
pad_inches=1,
bbox_inches="tight",dpi=300,
bbox_inches="tight", dpi=300,
)
plt.close(fig)

Expand Down Expand Up @@ -290,7 +290,7 @@ def pca_variance_ratio(
plt.savefig(
os.path.join(fig_path, fig_name),
pad_inches=1,
bbox_inches="tight",dpi=300,
bbox_inches="tight", dpi=300,
)
plt.close(fig)

Expand Down Expand Up @@ -366,7 +366,7 @@ def pcs_features(
plt.savefig(
os.path.join(fig_path, fig_name),
pad_inches=1,
bbox_inches="tight",dpi=300,
bbox_inches="tight", dpi=300,
)
plt.close(fig)

Expand Down Expand Up @@ -435,7 +435,7 @@ def variable_genes(
fig.savefig(
os.path.join(fig_path, fig_name),
pad_inches=1,
bbox_inches="tight",dpi=300,
bbox_inches="tight", dpi=300,
)
plt.close(fig)

Expand Down Expand Up @@ -659,7 +659,7 @@ def _scatterplot2d(
plt.savefig(
os.path.join(fig_path, fig_name),
pad_inches=1,
bbox_inches="tight",dpi=300,
bbox_inches="tight", dpi=300,
)
plt.close(fig)
if copy:
Expand Down Expand Up @@ -1199,7 +1199,7 @@ def graph(
fig.savefig(
os.path.join(fig_path, fig_name),
pad_inches=1,
bbox_inches="tight",dpi=300,
bbox_inches="tight", dpi=300,
)
plt.close(fig)

Expand Down Expand Up @@ -1592,7 +1592,7 @@ def stream(
color: `list` optional (default: None)
Column names of observations (adata.obs.columns)
or variable names(adata.var_names)
A list of names to be plotted.
A list of names to be plotted.
preference: `list`, optional (default: None):
The preference of nodes. The branch with speficied nodes are preferred
and will be put on the upper part of stream plot.
Expand Down Expand Up @@ -1832,10 +1832,10 @@ def stream(
if color is None:
plt.savefig(os.path.join(
file_path_S, 'plot_stream.' + fig_format),
pad_inches=1, bbox_inches='tight',dpi=300)
pad_inches=1, bbox_inches='tight', dpi=300)
else:
plt.savefig(os.path.join(
file_path_S,
'plot_stream_' + slugify(ann) + '.' + fig_format),
pad_inches=1, bbox_inches='tight',dpi=300)
pad_inches=1, bbox_inches='tight', dpi=300)
plt.close(fig)
11 changes: 7 additions & 4 deletions stream2/preprocessing/_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

def log_transform(adata):
"""Return the natural logarithm of one plus the input array, element-wise.
Parameters
----------
adata: AnnData
Expand All @@ -25,22 +26,24 @@ def log_transform(adata):

def normalize(adata, method="lib_size", scale_factor=1e4, save_raw=True):
"""Normalize count matrix.
Parameters
----------
adata: AnnData
Annotated data matrix.
method: `str`, optional (default: 'lib_size')
Choose from {{'lib_size','tf_idf'}}
Method used for dimension reduction.
'lib_size': Total-count normalize (library-size correct)
Choose from {{'lib_size','tf_idf'}}.
Method used for dimension reduction.\n
'lib_size': Total-count normalize (library-size correct).\n
'tf_idf': TF-IDF (term frequency–inverse document frequency)
transformation
transformation.
Returns
-------
updates `adata` with the following fields.
X: `numpy.ndarray` (`adata.X`)
Store #observations × #var_genes normalized data matrix.
"""

if method not in ["lib_size", "tf_idf"]:
raise ValueError("unrecognized method '%s'" % method)
if save_raw:
Expand Down
1 change: 1 addition & 0 deletions stream2/preprocessing/_pca.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def pca(
**kwargs,
):
"""perform Principal Component Analysis (PCA)
Parameters
----------
adata: AnnData
Expand Down
6 changes: 6 additions & 0 deletions stream2/preprocessing/_qc.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ def filter_samples(
expr_cutoff=1,
):
"""Filter out samples based on different metrics.
Parameters
----------
adata: AnnData
Expand Down Expand Up @@ -286,6 +287,7 @@ def filter_cells_rna(
expr_cutoff=1,
):
"""Filter out cells for RNA-seq based on different metrics.
Parameters
----------
adata: AnnData
Expand Down Expand Up @@ -394,6 +396,7 @@ def filter_cells_atac(
expr_cutoff=1,
):
"""Filter out cells for ATAC-seq based on different metrics.
Parameters
----------
adata: AnnData
Expand Down Expand Up @@ -502,6 +505,7 @@ def filter_genes(
expr_cutoff=1,
):
"""Filter out features based on different metrics.
Parameters
----------
adata: AnnData
Expand Down Expand Up @@ -616,6 +620,7 @@ def filter_peaks(
expr_cutoff=1,
):
"""Filter out features based on different metrics.
Parameters
----------
adata: AnnData
Expand Down Expand Up @@ -730,6 +735,7 @@ def filter_features(
expr_cutoff=1,
):
"""Filter out features based on different metrics.
Parameters
----------
adata: AnnData
Expand Down
78 changes: 0 additions & 78 deletions stream2/preprocessing/stream2_chromVar.out

This file was deleted.

3 changes: 2 additions & 1 deletion stream2/tools/_dimension_reduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ def dimension_reduction(
eigen_solver="auto",
**kwargs,
):
"""perform UMAP
"""perform dimension reduction
Parameters
----------
adata: AnnData
Expand Down

0 comments on commit b1cc64d

Please sign in to comment.