From 269d44829205f2d75de5f9cf43226e2c6361c551 Mon Sep 17 00:00:00 2001 From: sichao Date: Mon, 28 Aug 2023 16:58:29 -0400 Subject: [PATCH 01/13] reformat pp external --- dynamo/preprocessing/external/__init__.py | 2 +- dynamo/preprocessing/external/integration.py | 4 +++- dynamo/preprocessing/external/pearson_residual_recipe.py | 2 +- dynamo/preprocessing/external/sctransform.py | 1 + 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/dynamo/preprocessing/external/__init__.py b/dynamo/preprocessing/external/__init__.py index d6551b301..bb73ed945 100644 --- a/dynamo/preprocessing/external/__init__.py +++ b/dynamo/preprocessing/external/__init__.py @@ -11,4 +11,4 @@ "select_genes_by_pearson_residuals", "harmony_debatch", "integrate", -] \ No newline at end of file +] diff --git a/dynamo/preprocessing/external/integration.py b/dynamo/preprocessing/external/integration.py index b7529b38a..e2b4da139 100644 --- a/dynamo/preprocessing/external/integration.py +++ b/dynamo/preprocessing/external/integration.py @@ -7,6 +7,7 @@ # Convert sparse matrix to dense matrix. to_dense_matrix = lambda X: np.array(X.todense()) if isspmatrix(X) else np.asarray(X) + def integrate( adatas: List[AnnData], batch_key: str = "slices", @@ -78,6 +79,7 @@ def integrate( return integrated_adata + def harmony_debatch( adata: AnnData, key: str, @@ -125,4 +127,4 @@ def harmony_debatch( adata.obsm[adjusted_basis] = adjusted_matrix - return adata if copy else None \ No newline at end of file + return adata if copy else None diff --git a/dynamo/preprocessing/external/pearson_residual_recipe.py b/dynamo/preprocessing/external/pearson_residual_recipe.py index 8ae353054..bc711fa51 100644 --- a/dynamo/preprocessing/external/pearson_residual_recipe.py +++ b/dynamo/preprocessing/external/pearson_residual_recipe.py @@ -28,6 +28,7 @@ main_logger = LoggerManager.main_logger + # TODO: Use compute_pearson_residuals function to calculate residuals def _highly_variable_pearson_residuals( adata: AnnData, @@ -108,7 +109,6 @@ def _highly_variable_pearson_residuals( # Get pearson residuals for each batch separately residual_gene_vars_by_batch = [] for batch in np.unique(batch_info): - adata_subset = adata[batch_info == batch] # Filter out zero genes diff --git a/dynamo/preprocessing/external/sctransform.py b/dynamo/preprocessing/external/sctransform.py index b54c90dfd..3bbc12fae 100644 --- a/dynamo/preprocessing/external/sctransform.py +++ b/dynamo/preprocessing/external/sctransform.py @@ -218,6 +218,7 @@ def sctransform_core( """ import multiprocessing import sys + try: from KDEpy import FFTKDE except ImportError: From f9411810570e9976c4ce3195b3a3aa839fa72b91 Mon Sep 17 00:00:00 2001 From: sichao Date: Mon, 28 Aug 2023 17:00:48 -0400 Subject: [PATCH 02/13] reformat Preprocessor --- dynamo/preprocessing/Preprocessor.py | 1 - 1 file changed, 1 deletion(-) diff --git a/dynamo/preprocessing/Preprocessor.py b/dynamo/preprocessing/Preprocessor.py index d060ee3f6..666c94730 100644 --- a/dynamo/preprocessing/Preprocessor.py +++ b/dynamo/preprocessing/Preprocessor.py @@ -247,7 +247,6 @@ def standardize_adata(self, adata: AnnData, tkey: str, experiment_type: str) -> main_debug("applying convert_gene_name function...") self.convert_gene_name(adata) - self.basic_stats(adata) self.add_experiment_info(adata, tkey, experiment_type) main_info_insert_adata("tkey=%s" % tkey, "uns['pp']", indent_level=2) From fa6b7746e4f16b0766e7edd7f98f2f894f8e428c Mon Sep 17 00:00:00 2001 From: sichao Date: Mon, 28 Aug 2023 17:02:27 -0400 Subject: [PATCH 03/13] reformat gene_selection --- dynamo/preprocessing/gene_selection.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/dynamo/preprocessing/gene_selection.py b/dynamo/preprocessing/gene_selection.py index 6314a5efe..58a621a4e 100644 --- a/dynamo/preprocessing/gene_selection.py +++ b/dynamo/preprocessing/gene_selection.py @@ -247,7 +247,11 @@ def calc_dispersion_by_svr( adata_ori.uns[key] = {"mean": mean, "cv": cv, "svr_gamma": svr_gamma} prefix = "" if layer == "X" else layer + "_" - (adata.var[prefix + "log_m"], adata.var[prefix + "log_cv"], adata.var[prefix + "score"],) = ( + ( + adata.var[prefix + "log_m"], + adata.var[prefix + "log_cv"], + adata.var[prefix + "score"], + ) = ( np.nan, np.nan, -np.inf, From 10b4c0adaa4ae9079cbdaab5b210cebbba6496e6 Mon Sep 17 00:00:00 2001 From: sichao Date: Mon, 28 Aug 2023 17:03:31 -0400 Subject: [PATCH 04/13] reformat pp deprecated --- dynamo/preprocessing/deprecated.py | 1 + 1 file changed, 1 insertion(+) diff --git a/dynamo/preprocessing/deprecated.py b/dynamo/preprocessing/deprecated.py index 16488ee3c..b0b9fecb6 100644 --- a/dynamo/preprocessing/deprecated.py +++ b/dynamo/preprocessing/deprecated.py @@ -72,6 +72,7 @@ def wrapper(*args, **kwargs): # from __future__ import division, print_function + # https://stats.stackexchange.com/questions/356053/the-identity-link-function-does-not-respect-the-domain-of-the-gamma- # family def _weight_matrix_legacy(fitted_model: sm.Poisson) -> np.ndarray: From b85c14e3622275e49effb5b3bfa3860ae72dca0d Mon Sep 17 00:00:00 2001 From: sichao Date: Tue, 29 Aug 2023 10:43:52 -0400 Subject: [PATCH 05/13] reformat external --- dynamo/external/hodge.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/dynamo/external/hodge.py b/dynamo/external/hodge.py index 5e8928833..472a15f3f 100644 --- a/dynamo/external/hodge.py +++ b/dynamo/external/hodge.py @@ -232,7 +232,11 @@ def func(x): W.dot(ddhodge_div), W.dot(potential_), ) - (adata.obs[prefix + "ddhodge_sampled"], adata.obs[prefix + "ddhodge_div"], adata.obs[prefix + "potential"],) = ( + ( + adata.obs[prefix + "ddhodge_sampled"], + adata.obs[prefix + "ddhodge_div"], + adata.obs[prefix + "potential"], + ) = ( False, 0, 0, From 3147d0232751e3f2bd13af96412c283ef670476b Mon Sep 17 00:00:00 2001 From: sichao Date: Tue, 29 Aug 2023 10:46:04 -0400 Subject: [PATCH 06/13] reformat simulation --- dynamo/simulation/ODE.py | 2 +- dynamo/simulation/simulate_anndata.py | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/dynamo/simulation/ODE.py b/dynamo/simulation/ODE.py index 281e7fc57..c1599c674 100755 --- a/dynamo/simulation/ODE.py +++ b/dynamo/simulation/ODE.py @@ -105,7 +105,7 @@ def toggle( return res -def Ying_model(x: np.ndarray, t: Optional[float]=None): +def Ying_model(x: np.ndarray, t: Optional[float] = None): """network used in the potential landscape paper from Ying, et. al: https://www.nature.com/articles/s41598-017-15889-2. This is also the mixture of Gaussian model. diff --git a/dynamo/simulation/simulate_anndata.py b/dynamo/simulation/simulate_anndata.py index 02c4472a1..aade2bdc4 100644 --- a/dynamo/simulation/simulate_anndata.py +++ b/dynamo/simulation/simulate_anndata.py @@ -82,7 +82,6 @@ def __init__( required_param_names: List = [], velocity_func: Optional[Callable] = None, ) -> None: - # initialization of variables self.reactions = reactions self.C0s = np.atleast_2d(C0s) @@ -193,7 +192,6 @@ def simulate(self, t_span, n_cells=None, **simulator_kwargs): def generate_anndata(self, remove_empty_cells: bool = False): if self.T is not None and self.C is not None: - obs = pd.DataFrame( { "cell_name": np.arange(self.get_n_cells()), @@ -391,7 +389,6 @@ def __init__( simulator: CellularModelSimulator, syn_rxn_tag: str = "synthesis", ) -> None: - self.n_cells = simulator.C.shape[0] self.splicing = simulator.splicing From 87fe93b646eddecfc17b8e682c34fc4410dce68d Mon Sep 17 00:00:00 2001 From: sichao Date: Tue, 29 Aug 2023 10:47:50 -0400 Subject: [PATCH 07/13] reformat prediction --- dynamo/prediction/fate.py | 1 - dynamo/prediction/least_action_path.py | 2 +- dynamo/prediction/tscRNA_seq.py | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/dynamo/prediction/fate.py b/dynamo/prediction/fate.py index acb5e7eda..786ba29c7 100755 --- a/dynamo/prediction/fate.py +++ b/dynamo/prediction/fate.py @@ -462,7 +462,6 @@ def fate_bias( while True: is_dist_larger_than_threshold = distances.flatten() < dist_threshold * median_dist if any(is_dist_larger_than_threshold): - # let us diffuse one step further to identify cells from terminal cell types in case # cells with indices are all close to some random progenitor cells. if hasattr(nbrs, "query"): diff --git a/dynamo/prediction/least_action_path.py b/dynamo/prediction/least_action_path.py index 5852d35a2..9336f0763 100644 --- a/dynamo/prediction/least_action_path.py +++ b/dynamo/prediction/least_action_path.py @@ -534,7 +534,7 @@ def least_action( A = [] path_ind = 0 - for (init_state, target_state) in LoggerManager.progress_logger( + for init_state, target_state in LoggerManager.progress_logger( pairs, progress_name=f"iterating through {len(pairs)} pairs" ): logger.info( diff --git a/dynamo/prediction/tscRNA_seq.py b/dynamo/prediction/tscRNA_seq.py index fb5797792..89eafd860 100644 --- a/dynamo/prediction/tscRNA_seq.py +++ b/dynamo/prediction/tscRNA_seq.py @@ -17,7 +17,6 @@ def get_pulse_r0( add_init_r0_key: str = "init_r0_pulse", copy: bool = False, ) -> Union[anndata.AnnData, None]: - """Get the total RNA at the initial time point for a kinetic experiment with the formula: :math:`r_0 = \frac{(r - l)}{(1 - k)}`, where :math: `k = 1 - e^{- \gamma t} From 2857cb885c8fcd4b1d590e5f494dfdf21e0a4af2 Mon Sep 17 00:00:00 2001 From: sichao Date: Thu, 31 Aug 2023 17:02:53 -0400 Subject: [PATCH 08/13] isort pp external --- dynamo/preprocessing/external/__init__.py | 6 ++---- .../preprocessing/external/pearson_residual_recipe.py | 11 ++++------- dynamo/preprocessing/external/sctransform.py | 3 ++- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/dynamo/preprocessing/external/__init__.py b/dynamo/preprocessing/external/__init__.py index bb73ed945..0d21bd4aa 100644 --- a/dynamo/preprocessing/external/__init__.py +++ b/dynamo/preprocessing/external/__init__.py @@ -1,8 +1,6 @@ from .integration import harmony_debatch, integrate -from .pearson_residual_recipe import ( - normalize_layers_pearson_residuals, - select_genes_by_pearson_residuals, -) +from .pearson_residual_recipe import (normalize_layers_pearson_residuals, + select_genes_by_pearson_residuals) from .sctransform import sctransform __all__ = [ diff --git a/dynamo/preprocessing/external/pearson_residual_recipe.py b/dynamo/preprocessing/external/pearson_residual_recipe.py index bc711fa51..8dac00483 100644 --- a/dynamo/preprocessing/external/pearson_residual_recipe.py +++ b/dynamo/preprocessing/external/pearson_residual_recipe.py @@ -17,13 +17,10 @@ from scipy.sparse import issparse from ...configuration import DKM -from ...dynamo_logger import ( - LoggerManager, - main_info, - main_info_insert_adata_layer, - main_warning, -) -from ...preprocessing.utils import is_nonnegative_integer_arr, seurat_get_mean_var +from ...dynamo_logger import (LoggerManager, main_info, + main_info_insert_adata_layer, main_warning) +from ...preprocessing.utils import (is_nonnegative_integer_arr, + seurat_get_mean_var) from ..QC import filter_genes_by_outliers main_logger = LoggerManager.main_logger diff --git a/dynamo/preprocessing/external/sctransform.py b/dynamo/preprocessing/external/sctransform.py index 3bbc12fae..b43cc1e70 100644 --- a/dynamo/preprocessing/external/sctransform.py +++ b/dynamo/preprocessing/external/sctransform.py @@ -20,7 +20,8 @@ from scipy import stats from ...configuration import DKM -from ...dynamo_logger import main_info, main_info_insert_adata_layer, main_warning +from ...dynamo_logger import (main_info, main_info_insert_adata_layer, + main_warning) from ..utils import get_gene_selection_filter _EPS = np.finfo(float).eps From a06dd952f1dc2d0eade427657ec2ee44a109fffb Mon Sep 17 00:00:00 2001 From: sichao Date: Thu, 31 Aug 2023 17:11:12 -0400 Subject: [PATCH 09/13] isort preprocessor --- dynamo/preprocessing/Preprocessor.py | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/dynamo/preprocessing/Preprocessor.py b/dynamo/preprocessing/Preprocessor.py index 666c94730..e275e6249 100644 --- a/dynamo/preprocessing/Preprocessor.py +++ b/dynamo/preprocessing/Preprocessor.py @@ -9,21 +9,13 @@ from anndata import AnnData from ..configuration import DKM -from ..dynamo_logger import ( - LoggerManager, - main_debug, - main_info, - main_info_insert_adata, - main_warning, -) +from ..dynamo_logger import (LoggerManager, main_debug, main_info, + main_info_insert_adata, main_warning) from ..tools.connectivity import neighbors as default_neighbors from ..tools.utils import update_dict from .cell_cycle import cell_cycle_scores -from .external import ( - normalize_layers_pearson_residuals, - sctransform, - select_genes_by_pearson_residuals, -) +from .external import (normalize_layers_pearson_residuals, sctransform, + select_genes_by_pearson_residuals) from .gene_selection import select_genes_by_seurat_recipe, select_genes_monocle from .normalization import calc_sz_factor, normalize from .pca import pca @@ -32,15 +24,9 @@ from .QC import filter_genes_by_outliers as monocle_filter_genes_by_outliers from .QC import regress_out_parallel from .transform import Freeman_Tukey, log, log1p, log2 -from .utils import ( - _infer_labeling_experiment_type, - calc_new_to_total_ratio, - collapse_species_adata, - convert2symbol, - convert_layers2csr, - detect_experiment_datatype, - unique_var_obs_adata, -) +from .utils import (_infer_labeling_experiment_type, calc_new_to_total_ratio, + collapse_species_adata, convert2symbol, convert_layers2csr, + detect_experiment_datatype, unique_var_obs_adata) class Preprocessor: From 11a6b9672095a7db091cf2915e6db0943c559286 Mon Sep 17 00:00:00 2001 From: sichao Date: Thu, 31 Aug 2023 17:11:56 -0400 Subject: [PATCH 10/13] isort pp steps --- dynamo/preprocessing/QC.py | 14 +++----- dynamo/preprocessing/__init__.py | 44 ++++++++------------------ dynamo/preprocessing/deprecated.py | 34 +++++++------------- dynamo/preprocessing/gene_selection.py | 23 ++++---------- dynamo/preprocessing/normalization.py | 12 ++----- dynamo/preprocessing/pca.py | 3 +- 6 files changed, 39 insertions(+), 91 deletions(-) diff --git a/dynamo/preprocessing/QC.py b/dynamo/preprocessing/QC.py index f972de43e..7102b6963 100644 --- a/dynamo/preprocessing/QC.py +++ b/dynamo/preprocessing/QC.py @@ -13,16 +13,10 @@ from scipy.sparse import issparse, spmatrix from ..configuration import DKM -from ..dynamo_logger import ( - LoggerManager, - main_debug, - main_exception, - main_finish_progress, - main_info, - main_info_insert_adata_obs, - main_log_time, - main_warning, -) +from ..dynamo_logger import (LoggerManager, main_debug, main_exception, + main_finish_progress, main_info, + main_info_insert_adata_obs, main_log_time, + main_warning) from .utils import get_inrange_shared_counts_mask diff --git a/dynamo/preprocessing/__init__.py b/dynamo/preprocessing/__init__.py index 22d95a23e..dc94fc821 100755 --- a/dynamo/preprocessing/__init__.py +++ b/dynamo/preprocessing/__init__.py @@ -2,40 +2,21 @@ """ from .cell_cycle import cell_cycle_scores +from .deprecated import (calc_sz_factor_legacy, cook_dist, filter_cells_legacy, + normalize_cell_expr_by_size_factors, recipe_monocle, + recipe_velocyto) from .dynast import lambda_correction -from .external import ( - harmony_debatch, - integrate, - normalize_layers_pearson_residuals, - sctransform, - select_genes_by_pearson_residuals, -) +from .external import (harmony_debatch, integrate, + normalize_layers_pearson_residuals, sctransform, + select_genes_by_pearson_residuals) from .normalization import calc_sz_factor, normalize -from .QC import ( - basic_stats, - filter_genes_by_clusters, - filter_cells_by_outliers, - filter_genes_by_outliers, - filter_genes_by_pattern, -) from .pca import pca, top_pca_genes +from .QC import (basic_stats, filter_cells_by_outliers, + filter_genes_by_clusters, filter_genes_by_outliers, + filter_genes_by_pattern) from .transform import log1p, log1p_adata_layer -from .utils import ( - compute_gene_exp_fraction, - convert2symbol, - decode, - get_svr_filter, - relative2abs, - scale, -) -from .deprecated import ( - cook_dist, - calc_sz_factor_legacy, - normalize_cell_expr_by_size_factors, - filter_cells_legacy, - recipe_monocle, - recipe_velocyto, -) +from .utils import (compute_gene_exp_fraction, convert2symbol, decode, + get_svr_filter, relative2abs, scale) filter_cells = filter_cells_by_outliers filter_genes = filter_genes_by_outliers @@ -43,7 +24,8 @@ normalize_cells = normalize from .CnmfPreprocessor import CnmfPreprocessor -from .gene_selection import calc_Gini, calc_dispersion_by_svr, highest_frac_genes, select_genes_monocle +from .gene_selection import (calc_dispersion_by_svr, calc_Gini, + highest_frac_genes, select_genes_monocle) from .Preprocessor import Preprocessor __all__ = [ diff --git a/dynamo/preprocessing/deprecated.py b/dynamo/preprocessing/deprecated.py index b0b9fecb6..6f4da4a21 100644 --- a/dynamo/preprocessing/deprecated.py +++ b/dynamo/preprocessing/deprecated.py @@ -19,36 +19,24 @@ from sklearn.decomposition import FastICA from ..configuration import DKM, DynamoAdataConfig, DynamoAdataKeyManager -from ..dynamo_logger import ( - LoggerManager, - main_debug, - main_info, - main_info_insert_adata_obsm, - main_warning, -) +from ..dynamo_logger import (LoggerManager, main_debug, main_info, + main_info_insert_adata_obsm, main_warning) from ..tools.utils import update_dict from ..utils import copy_adata from .cell_cycle import cell_cycle_scores from .gene_selection import calc_dispersion_by_svr -from .normalization import calc_sz_factor, get_sz_exprs, normalize_mat_monocle, sz_util +from .normalization import (calc_sz_factor, get_sz_exprs, + normalize_mat_monocle, sz_util) from .pca import pca from .QC import basic_stats, filter_genes_by_clusters, filter_genes_by_outliers from .transform import _Freeman_Tukey -from .utils import ( - _infer_labeling_experiment_type, - add_noise_to_duplicates, - calc_new_to_total_ratio, - collapse_species_adata, - compute_gene_exp_fraction, - convert2symbol, - convert_layers2csr, - detect_experiment_datatype, - get_inrange_shared_counts_mask, - get_nan_or_inf_data_bool_mask, - get_svr_filter, - merge_adata_attrs, - unique_var_obs_adata, -) +from .utils import (_infer_labeling_experiment_type, add_noise_to_duplicates, + calc_new_to_total_ratio, collapse_species_adata, + compute_gene_exp_fraction, convert2symbol, + convert_layers2csr, detect_experiment_datatype, + get_inrange_shared_counts_mask, + get_nan_or_inf_data_bool_mask, get_svr_filter, + merge_adata_attrs, unique_var_obs_adata) def deprecated(func): diff --git a/dynamo/preprocessing/gene_selection.py b/dynamo/preprocessing/gene_selection.py index 58a621a4e..b1771a1c7 100644 --- a/dynamo/preprocessing/gene_selection.py +++ b/dynamo/preprocessing/gene_selection.py @@ -16,24 +16,13 @@ from scipy.sparse import csr_matrix, issparse from ..configuration import DKM -from ..dynamo_logger import ( - LoggerManager, - main_critical, - main_debug, - main_info, - main_info_insert_adata_uns, - main_info_insert_adata_var, - main_warning, -) +from ..dynamo_logger import (LoggerManager, main_critical, main_debug, + main_info, main_info_insert_adata_uns, + main_info_insert_adata_var, main_warning) from .pca import pca -from .utils import ( - compute_gene_exp_fraction, - get_gene_selection_filter, - get_nan_or_inf_data_bool_mask, - get_svr_filter, - merge_adata_attrs, - seurat_get_mean_var, -) +from .utils import (compute_gene_exp_fraction, get_gene_selection_filter, + get_nan_or_inf_data_bool_mask, get_svr_filter, + merge_adata_attrs, seurat_get_mean_var) def calc_Gini(adata: AnnData, layers: Union[Literal["all"], List[str]] = "all") -> AnnData: diff --git a/dynamo/preprocessing/normalization.py b/dynamo/preprocessing/normalization.py index 991f599cf..003d28608 100644 --- a/dynamo/preprocessing/normalization.py +++ b/dynamo/preprocessing/normalization.py @@ -14,15 +14,9 @@ from scipy.sparse.base import issparse from ..configuration import DKM -from ..dynamo_logger import ( - main_debug, - main_info_insert_adata_layer, - main_info_insert_adata_obsm, - main_warning, -) -from .utils import ( - merge_adata_attrs, -) +from ..dynamo_logger import (main_debug, main_info_insert_adata_layer, + main_info_insert_adata_obsm, main_warning) +from .utils import merge_adata_attrs def calc_sz_factor( diff --git a/dynamo/preprocessing/pca.py b/dynamo/preprocessing/pca.py index c3437d784..245b46240 100644 --- a/dynamo/preprocessing/pca.py +++ b/dynamo/preprocessing/pca.py @@ -16,7 +16,8 @@ from sklearn.utils.sparsefuncs import mean_variance_axis from ..configuration import DKM -from ..dynamo_logger import main_info_insert_adata_obsm, main_info_insert_adata_var +from ..dynamo_logger import (main_info_insert_adata_obsm, + main_info_insert_adata_var) def _truncatedSVD_with_center( From 112ab9698a265707d4d9d16b55cd532b08b8f490 Mon Sep 17 00:00:00 2001 From: sichao Date: Fri, 1 Sep 2023 11:47:20 -0400 Subject: [PATCH 11/13] isort external --- dynamo/external/hodge.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dynamo/external/hodge.py b/dynamo/external/hodge.py index 472a15f3f..d2d31e49e 100644 --- a/dynamo/external/hodge.py +++ b/dynamo/external/hodge.py @@ -10,7 +10,6 @@ from scipy.sparse import csr_matrix, issparse from ..dynamo_logger import main_finish_progress, main_info, main_log_time - # from ..vectorfield.scVectorField import graphize_vecfld from ..tools.graph_calculus import divergence, graphize_velocity, potential from ..tools.sampling import sample_by_velocity, trn @@ -21,7 +20,8 @@ div, potential, )""" -from ..tools.connectivity import _gen_neighbor_keys, check_and_recompute_neighbors +from ..tools.connectivity import (_gen_neighbor_keys, + check_and_recompute_neighbors) def ddhodge( From 4499ae9d33c13068630987d51f4406df6c8b7222 Mon Sep 17 00:00:00 2001 From: sichao Date: Fri, 1 Sep 2023 11:48:49 -0400 Subject: [PATCH 12/13] isort simulation --- dynamo/simulation/__init__.py | 30 +++++++-------------------- dynamo/simulation/simulate_anndata.py | 20 ++++-------------- dynamo/simulation/utils.py | 10 ++------- 3 files changed, 14 insertions(+), 46 deletions(-) diff --git a/dynamo/simulation/__init__.py b/dynamo/simulation/__init__.py index 23e1f1ff2..2175d2f10 100755 --- a/dynamo/simulation/__init__.py +++ b/dynamo/simulation/__init__.py @@ -1,25 +1,11 @@ from .evaluation import evaluate from .Gillespie import Gillespie -from .ODE import ( - Simulator, - Ying_model, - jacobian_bifur2genes, - neurongenesis, - ode_bifur2genes, - state_space_sampler, - toggle, -) -from .simulate_anndata import ( - AnnDataSimulator, - BifurcationTwoGenes, - CellularModelSimulator, - KinLabelingSimulator, - Neurongenesis, - OscillationTwoGenes, - bifur2genes_params, - bifur2genes_splicing_params, - neurongenesis_params, - osc2genes_params, - osc2genes_splicing_params, -) +from .ODE import (Simulator, Ying_model, jacobian_bifur2genes, neurongenesis, + ode_bifur2genes, state_space_sampler, toggle) +from .simulate_anndata import (AnnDataSimulator, BifurcationTwoGenes, + CellularModelSimulator, KinLabelingSimulator, + Neurongenesis, OscillationTwoGenes, + bifur2genes_params, bifur2genes_splicing_params, + neurongenesis_params, osc2genes_params, + osc2genes_splicing_params) from .utils import CellularSpecies, directMethod diff --git a/dynamo/simulation/simulate_anndata.py b/dynamo/simulation/simulate_anndata.py index aade2bdc4..5d2493a56 100644 --- a/dynamo/simulation/simulate_anndata.py +++ b/dynamo/simulation/simulate_anndata.py @@ -5,24 +5,12 @@ import pandas as pd # dynamo logger related -from ..dynamo_logger import ( - LoggerManager, - main_critical, - main_exception, - main_info, - main_tqdm, - main_warning, -) +from ..dynamo_logger import (LoggerManager, main_critical, main_exception, + main_info, main_tqdm, main_warning) from ..tools.sampling import sample from ..tools.utils import flatten, isarray -from .ODE import ( - hill_act_func, - hill_inh_func, - neurongenesis, - ode_bifur2genes, - ode_neurongenesis, - ode_osc2genes, -) +from .ODE import (hill_act_func, hill_inh_func, neurongenesis, ode_bifur2genes, + ode_neurongenesis, ode_osc2genes) from .utils import CellularSpecies, GillespieReactions, Reaction bifur2genes_params = { diff --git a/dynamo/simulation/utils.py b/dynamo/simulation/utils.py index d5e7e9653..9c71e3502 100644 --- a/dynamo/simulation/utils.py +++ b/dynamo/simulation/utils.py @@ -3,14 +3,8 @@ import numpy as np # dynamo logger related -from ..dynamo_logger import ( - LoggerManager, - main_critical, - main_exception, - main_info, - main_tqdm, - main_warning, -) +from ..dynamo_logger import (LoggerManager, main_critical, main_exception, + main_info, main_tqdm, main_warning) def directMethod( From 6126b634cc9517d0ae1fadbc36b9827ff4144e5b Mon Sep 17 00:00:00 2001 From: sichao Date: Fri, 3 Nov 2023 15:53:11 -0400 Subject: [PATCH 13/13] update code quality check in workflow --- .github/workflows/python-plain-run-test.yml | 26 +++++++++++++-------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/.github/workflows/python-plain-run-test.yml b/.github/workflows/python-plain-run-test.yml index 0fe8e62ab..e92eeedea 100644 --- a/.github/workflows/python-plain-run-test.yml +++ b/.github/workflows/python-plain-run-test.yml @@ -9,6 +9,21 @@ on: branches: [ master ] jobs: + check-code: + name: Check code quality + runs-on: ubuntu-latest + steps: + - name: Checkout branch + uses: actions/checkout@v2 + - name: Setup python + uses: actions/setup-python@v2 + with: + python-version: '3.9' + architecture: x64 + - name: Install dependencies + run: pip install isort black + - name: Check code quality + run: isort --profile black --check dynamo tests && black --check dynamo tests && echo OK build: runs-on: ubuntu-latest strategy: @@ -25,20 +40,11 @@ jobs: run: | python -m pip install --upgrade pip pip install git+https://github.com/pypa/pip.git@611e9253ff74ca5b8ce438c2423373ab0d44c961 - pip install flake8 pytest + pip install pytest if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - name: Install package run: | pip install -e .[test] - - name: Lint with flake8 - run: | - # stop the build if there are Python syntax errors or undefined names - flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics - # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics -# - name: Test with pytest -# run: | -# pytest - name: Run tests and collect coverage run: | pip install pytest-cov