From 672a50361a680dc1db265ca7338a771aa210c738 Mon Sep 17 00:00:00 2001 From: huidongchen Date: Thu, 7 Sep 2023 16:26:44 -0400 Subject: [PATCH 1/5] add api file --- docs/source/API.rst | 76 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 75 insertions(+), 1 deletion(-) diff --git a/docs/source/API.rst b/docs/source/API.rst index cc8f1aa..bd9a1ea 100644 --- a/docs/source/API.rst +++ b/docs/source/API.rst @@ -1,2 +1,76 @@ +.. automodule:: stream2 + API -=== \ No newline at end of file +=== + +Import stream2 as:: + + import stream2 as st2 + +Configuration for SIMBA +~~~~~~~~~~~~~~~~~~~~~~~ +.. 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 `_ + +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 From 9174f674ace5c446d34057c10134a105ef19b62e Mon Sep 17 00:00:00 2001 From: huidongchen Date: Thu, 7 Sep 2023 16:49:25 -0400 Subject: [PATCH 2/5] minor tweaks --- docs/source/API.rst | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/docs/source/API.rst b/docs/source/API.rst index bd9a1ea..a989464 100644 --- a/docs/source/API.rst +++ b/docs/source/API.rst @@ -7,8 +7,8 @@ Import stream2 as:: import stream2 as st2 -Configuration for SIMBA -~~~~~~~~~~~~~~~~~~~~~~~ +Configuration for STREAM2 +~~~~~~~~~~~~~~~~~~~~~~~~~ .. autosummary:: :toctree: _autosummary @@ -18,7 +18,6 @@ Configuration for SIMBA Reading ~~~~~~~ - .. autosummary:: :toctree: _autosummary @@ -30,9 +29,9 @@ Reading See more at `anndata `_ + Preprocessing ~~~~~~~~~~~~~ - .. autosummary:: :toctree: _autosummary @@ -43,9 +42,9 @@ Preprocessing pp.pca pp.select_variable_genes + Tools ~~~~~ - .. autosummary:: :toctree: _autosummary @@ -63,7 +62,6 @@ Tools Plotting ~~~~~~~~ - .. autosummary:: :toctree: _autosummary @@ -73,4 +71,4 @@ Plotting pl.graph pl.dimension_reduction pl.stream_sc - pl.stream + pl.stream \ No newline at end of file From cd9517c7b0590f709fab5e084c0d26c3c0d427ac Mon Sep 17 00:00:00 2001 From: huidongchen Date: Fri, 8 Sep 2023 10:13:34 -0400 Subject: [PATCH 3/5] fix the issue 'pp tl pl' not detected on readthedocs --- stream2/__init__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/stream2/__init__.py b/stream2/__init__.py index eaee4fb..7e8659a 100644 --- a/stream2/__init__.py +++ b/stream2/__init__.py @@ -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']}) \ No newline at end of file From fb21213bbcdbd56bcb18f4086f538c65c78ac724 Mon Sep 17 00:00:00 2001 From: huidongchen Date: Fri, 8 Sep 2023 10:51:38 -0400 Subject: [PATCH 4/5] fix stying errors for readthedocs --- stream2/_settings.py | 6 +++++- stream2/plotting/_plot.py | 24 ++++++++++++------------ stream2/preprocessing/_general.py | 11 +++++++---- stream2/preprocessing/_pca.py | 1 + stream2/preprocessing/_qc.py | 6 ++++++ stream2/tools/_dimension_reduction.py | 3 ++- 6 files changed, 33 insertions(+), 18 deletions(-) diff --git a/stream2/_settings.py b/stream2/_settings.py index a34e15d..2714ac4 100644 --- a/stream2/_settings.py +++ b/stream2/_settings.py @@ -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 @@ -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( diff --git a/stream2/plotting/_plot.py b/stream2/plotting/_plot.py index d8a5bec..0ed6a96 100644 --- a/stream2/plotting/_plot.py +++ b/stream2/plotting/_plot.py @@ -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: @@ -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) @@ -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: @@ -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) @@ -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) @@ -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) @@ -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) @@ -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: @@ -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) @@ -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. @@ -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) diff --git a/stream2/preprocessing/_general.py b/stream2/preprocessing/_general.py index 5c92d13..5f1807f 100644 --- a/stream2/preprocessing/_general.py +++ b/stream2/preprocessing/_general.py @@ -7,6 +7,7 @@ def log_transform(adata): """Return the natural logarithm of one plus the input array, element-wise. + Parameters ---------- adata: AnnData @@ -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: diff --git a/stream2/preprocessing/_pca.py b/stream2/preprocessing/_pca.py index a08f3c0..25ef451 100644 --- a/stream2/preprocessing/_pca.py +++ b/stream2/preprocessing/_pca.py @@ -18,6 +18,7 @@ def pca( **kwargs, ): """perform Principal Component Analysis (PCA) + Parameters ---------- adata: AnnData diff --git a/stream2/preprocessing/_qc.py b/stream2/preprocessing/_qc.py index d90289a..8ecf5c3 100644 --- a/stream2/preprocessing/_qc.py +++ b/stream2/preprocessing/_qc.py @@ -179,6 +179,7 @@ def filter_samples( expr_cutoff=1, ): """Filter out samples based on different metrics. + Parameters ---------- adata: AnnData @@ -286,6 +287,7 @@ def filter_cells_rna( expr_cutoff=1, ): """Filter out cells for RNA-seq based on different metrics. + Parameters ---------- adata: AnnData @@ -394,6 +396,7 @@ def filter_cells_atac( expr_cutoff=1, ): """Filter out cells for ATAC-seq based on different metrics. + Parameters ---------- adata: AnnData @@ -502,6 +505,7 @@ def filter_genes( expr_cutoff=1, ): """Filter out features based on different metrics. + Parameters ---------- adata: AnnData @@ -616,6 +620,7 @@ def filter_peaks( expr_cutoff=1, ): """Filter out features based on different metrics. + Parameters ---------- adata: AnnData @@ -730,6 +735,7 @@ def filter_features( expr_cutoff=1, ): """Filter out features based on different metrics. + Parameters ---------- adata: AnnData diff --git a/stream2/tools/_dimension_reduction.py b/stream2/tools/_dimension_reduction.py index fc63c44..c355e0e 100644 --- a/stream2/tools/_dimension_reduction.py +++ b/stream2/tools/_dimension_reduction.py @@ -21,7 +21,8 @@ def dimension_reduction( eigen_solver="auto", **kwargs, ): - """perform UMAP + """perform dimension reduction + Parameters ---------- adata: AnnData From 6f7b01d369c9212b9a2f015945005a54653b70de Mon Sep 17 00:00:00 2001 From: huidongchen Date: Fri, 8 Sep 2023 10:52:28 -0400 Subject: [PATCH 5/5] del unnecessary file --- stream2/preprocessing/stream2_chromVar.out | 78 ---------------------- 1 file changed, 78 deletions(-) delete mode 100644 stream2/preprocessing/stream2_chromVar.out diff --git a/stream2/preprocessing/stream2_chromVar.out b/stream2/preprocessing/stream2_chromVar.out deleted file mode 100644 index 7e241c5..0000000 --- a/stream2/preprocessing/stream2_chromVar.out +++ /dev/null @@ -1,78 +0,0 @@ - -R version 4.1.3 (2022-03-10) -- "One Push-Up" -Copyright (C) 2022 The R Foundation for Statistical Computing -Platform: x86_64-conda-linux-gnu (64-bit) - -R is free software and comes with ABSOLUTELY NO WARRANTY. -You are welcome to redistribute it under certain conditions. -Type 'license()' or 'licence()' for distribution details. - -R is a collaborative project with many contributors. -Type 'contributors()' for more information and -'citation()' on how to cite R or R packages in publications. - -Type 'demo()' for some demos, 'help()' for on-line help, or -'help.start()' for an HTML browser interface to help. -Type 'q()' to quit R. - -> suppressMessages(library(chromVAR)) -> suppressMessages(library(Matrix)) -> suppressMessages(library(SummarizedExperiment)) -> suppressMessages(library(BiocParallel)) -> suppressMessages(library(data.table)) -> -> set.seed(2022) -> -> ### Get command line arguments -> args <- commandArgs(TRUE) -> print(args[[1]]) -[1] "input='.'" -> print(args[[2]]) -[1] "species='MusMusculus'" -> print(args[[3]]) -[1] "genome='mm10'" -> print(args[[4]]) -[1] "feature='motif'" -> print(args[[5]]) -[1] "n_jobs=4" -> -> if(length(args)<5){ -+ print("Not sufficient arguments supplied.") -+ }else{ -+ for(i in 1:length(args)){ -+ eval(parse(text=args[[i]])) -+ } -+ } -> -> print(paste0('input is ', input)) -[1] "input is ." -> print(paste0('species is ', species)) -[1] "species is MusMusculus" -> print(paste0('genome is ', genome)) -[1] "genome is mm10" -> print(paste0('feature is ', feature)) -[1] "feature is motif" -> print(paste0('n_jobs is ', n_jobs)) -[1] "n_jobs is 4" -> -> if(species=='HomoSapiens'){ -+ species = 'Homo sapiens' -+ }else if(species=='MusMusculus'){ -+ species = 'Mus musculus' -+ }else{ -+ print("Only 'HomoSapiens' and 'MusMusculus' are supported") -+ break -+ } -> -> print(paste0('Using',n_jobs,'cores...',sep = " ")) -[1] "Using4cores... " -> register(MulticoreParam(n_jobs)) -> -> ### Read in data files -> print(paste0('Read in regions: ', input, '/region_file.bed...')) -[1] "Read in regions: ./region_file.bed..." -> peaks <- makeGRangesFromDataFrame(data.frame(fread(paste0(input,'/region_file.bed'),col.names=c('seqnames','start','end')))) -Error in fread(paste0(input, "/region_file.bed"), col.names = c("seqnames", : - File './region_file.bed' does not exist or is non-readable. getwd()=='/mnt/c/Users/jobac/Desktop/all/git/STREAM2/stream2/preprocessing' -Calls: makeGRangesFromDataFrame -> data.frame -> fread -Execution halted