Skip to content

Commit

Permalink
merged to the lastest code
Browse files Browse the repository at this point in the history
  • Loading branch information
Ukyeon committed May 19, 2023
2 parents d7b5616 + a9b3958 commit 364e4e6
Show file tree
Hide file tree
Showing 60 changed files with 3,826 additions and 3,035 deletions.
6 changes: 4 additions & 2 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ version: 2
formats: []

build:
image: latest
os: ubuntu-22.04
tools:
python: "3.7"
# image: latest

# Build documentation in the docs/ directory with Sphinx
sphinx:
Expand All @@ -14,7 +17,6 @@ sphinx:
# - requirements: docs/requirements.txt

python:
version: 3.7
install:
- method: pip
path: .
Expand Down
1 change: 0 additions & 1 deletion build.sh

This file was deleted.

2 changes: 0 additions & 2 deletions conda_recipe/bld.bat

This file was deleted.

1 change: 0 additions & 1 deletion conda_recipe/build.sh

This file was deleted.

57 changes: 0 additions & 57 deletions conda_recipe/meta.yaml

This file was deleted.

34 changes: 25 additions & 9 deletions dynamo/dynamo_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,19 +152,35 @@ def error(self, message, indent_level=1, *args, **kwargs):
message = format_logging_message(message, logging.ERROR, indent_level=indent_level)
return self.logger.error(message, *args, **kwargs)

def info_insert_adata(self, key, adata_attr="obsm", indent_level=1, *args, **kwargs):
def info_insert_adata(self, key, adata_attr="obsm", log_level=logging.NOTSET, indent_level=1, *args, **kwargs):
message = "<insert> %s to %s in AnnData Object." % (key, adata_attr)
message = format_logging_message(message, logging.DEBUG, indent_level=indent_level)
return self.logger.debug(message, *args, **kwargs)
if log_level == logging.NOTSET or log_level == logging.DEBUG:
self.debug(message, indent_level=indent_level, *args, **kwargs)
elif log_level == logging.INFO:
self.info(message, indent_level=indent_level, *args, **kwargs)
elif log_level == logging.WARN:
self.warning(message, indent_level=indent_level, *args, **kwargs)
elif log_level == logging.ERROR:
self.error(message, indent_level=indent_level, *args, **kwargs)
elif log_level == logging.CRITICAL:
self.critical(message, indent_level=indent_level, *args, **kwargs)
else:
raise NotImplementedError

def info_insert_adata_var(self, key, indent_level=1, *args, **kwargs):
return self.info_insert_adata(self, key, adata_attr="var", indent_level=1, *args, **kwargs)
def info_insert_adata_var(self, key, log_level, indent_level, *args, **kwargs):
return self.info_insert_adata(
self, key, adata_attr="var", log_level=log_level, indent_level=indent_level, *args, **kwargs
)

def info_insert_adata_obsm(self, key, indent_level=1, *args, **kwargs):
return self.info_insert_adata(self, key, adata_attr="obsm", indent_level=1, *args, **kwargs)
def info_insert_adata_obsm(self, key, log_level, indent_level, *args, **kwargs):
return self.info_insert_adata(
self, key, adata_attr="obsm", log_level=log_level, indent_level=indent_level, *args, **kwargs
)

def info_insert_adata_uns(self, key, indent_level=1, *args, **kwargs):
return self.info_insert_adata(self, key, adata_attr="uns", indent_level=1, *args, **kwargs)
def info_insert_adata_uns(self, key, log_level, indent_level, *args, **kwargs):
return self.info_insert_adata(
self, key, adata_attr="uns", log_level=log_level, indent_level=indent_level, *args, **kwargs
)

def log_time(self):
now = time.time()
Expand Down
8 changes: 0 additions & 8 deletions dynamo/external/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,14 @@

from .gseapy import enrichr
from .hodge import ddhodge
from .pearson_residual_recipe import (
normalize_layers_pearson_residuals,
select_genes_by_pearson_residuals,
)
from .scifate import scifate_glmnet
from .scribe import coexp_measure, coexp_measure_mat, scribe
from .sctransform import sctransform

__all__ = [
"enrichr",
"ddhodge",
"normalize_layers_pearson_residuals",
"select_genes_by_pearson_residuals",
"scifate_glmnet",
"coexp_measure",
"coexp_measure_mat",
"scribe",
"sctransform",
]
1 change: 0 additions & 1 deletion dynamo/external/gseapy.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ def enrichr(
gene_sets=gene_sets, # GO_Biological_Process_2018
organism=organism, # don't forget to set organism to the one you desired! e.g. Yeast
background=background,
description=description,
outdir=outdir,
no_plot=no_plot,
cutoff=cutoff, # test dataset, use lower value from range(0,1)
Expand Down
2 changes: 1 addition & 1 deletion dynamo/external/scifate.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def adata_processing_TF_link(
total = adata.layers[nt_layers[1]]

# recalculate size factor
from ..preprocessing import calc_sz_factor_legacy
from ..preprocessing.deprecated import calc_sz_factor_legacy

adata = calc_sz_factor_legacy(
adata,
Expand Down
2 changes: 1 addition & 1 deletion dynamo/external/scribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def scribe(

if normalize:
# recalculate size factor
from ..preprocessing import calc_sz_factor_legacy
from ..preprocessing.deprecated import calc_sz_factor_legacy

adata = calc_sz_factor_legacy(
adata,
Expand Down
3 changes: 3 additions & 0 deletions dynamo/plot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
)
from .scatters import scatters
from .scPotential import show_landscape
from .sctransform import sctransform_plot_fit, plot_residual_var
from .scVectorField import ( # , plot_LIC_gray
cell_wise_vectors,
cell_wise_vectors_3d,
Expand Down Expand Up @@ -150,4 +151,6 @@
"causality",
"comb_logic",
"hessian",
"sctransform_plot_fit",
"plot_residual_var",
]
10 changes: 7 additions & 3 deletions dynamo/plot/cell_cycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def cell_cycle_scores(
# Heatmap returns an axes obj but you need to get a mappable obj (get_children)
colorbar(ax.get_children()[0], cax=cax, ticks=[-0.9, 0, 0.9])

if save_show_or_return == "save":
if save_show_or_return in ["save", "both", "all"]:
s_kwargs = {
"path": None,
"prefix": "plot_direct_graph",
Expand All @@ -82,13 +82,17 @@ def cell_cycle_scores(
"close": True,
"verbose": True,
}

if save_show_or_return in ["both", "all"]:
s_kwargs["close"] = False

s_kwargs = update_dict(s_kwargs, save_kwargs)

save_fig(**s_kwargs)
elif save_show_or_return == "show":
if save_show_or_return in ["show", "both", "all"]:
plt.tight_layout()
plt.show()
elif save_show_or_return == "return":
if save_show_or_return in ["return", "all"]:
return ax
else:
raise NotImplementedError("Unavailable save_show_or_return flag: %s" % save_show_or_return)
21 changes: 13 additions & 8 deletions dynamo/plot/connectivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ def connectivity_base(

ax.set(xticks=[], yticks=[])

if save_show_or_return == "save":
if save_show_or_return in ["save", "both", "all"]:
s_kwargs = {
"path": None,
"prefix": "connectivity_base",
Expand All @@ -321,14 +321,16 @@ def connectivity_base(
}
s_kwargs = update_dict(s_kwargs, save_kwargs)

if save_show_or_return in ["both", "all"]:
s_kwargs["close"] = False

save_fig(**s_kwargs)
elif save_show_or_return == "show":

if save_show_or_return in ["show", "both", "all"]:
plt.tight_layout()
plt.show()
elif save_show_or_return == "return":
if save_show_or_return in ["return", "all"]:
return ax
else:
raise NotImplementedError("Unsupported save_show_or_return")


docstrings.delete_params("con_base.parameters", "edge_df", "save_show_or_return", "save_kwargs")
Expand Down Expand Up @@ -578,7 +580,7 @@ def nneighbors(
ax.set_ylabel(cur_b + "_2")
ax.set_title(cur_c)

if save_show_or_return == "save":
if save_show_or_return in ["save", "both", "all"]:
s_kwargs = {
"path": None,
"prefix": "nneighbors",
Expand All @@ -590,11 +592,14 @@ def nneighbors(
}
s_kwargs = update_dict(s_kwargs, save_kwargs)

if save_show_or_return in ["both", "all"]:
s_kwargs["close"] = False

save_fig(**s_kwargs)
elif save_show_or_return == "show":
if save_show_or_return in ["show", "both", "all"]:
plt.tight_layout()
plt.show()
elif save_show_or_return == "return":
if save_show_or_return in ["return", "all"]:
return g
else:
raise NotImplementedError('Invalid "save_show_or_return".')
Expand Down
2 changes: 1 addition & 1 deletion dynamo/plot/dimension_reduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def pca(adata: AnnData, *args, **kwargs) -> Optional[Axes]:
`save_show_or_return='return'` as a kwarg, the axes of the plot would be returned.
"""

scatters(adata, "pca", *args, **kwargs)
return scatters(adata, "pca", *args, **kwargs)


def umap(adata: AnnData, *args, **kwargs) -> Optional[Axes]:
Expand Down
21 changes: 13 additions & 8 deletions dynamo/plot/dynamics.py
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,7 @@ def phase_portraits(
despline_all(ax6)
deaxis_all(ax6)

if save_show_or_return == "save":
if save_show_or_return in ["save", "both", "all"]:
s_kwargs = {
"path": None,
"prefix": "phase_portraits",
Expand All @@ -1076,18 +1076,19 @@ def phase_portraits(
}
s_kwargs = update_dict(s_kwargs, save_kwargs)

if save_show_or_return in ["both", "all"]:
s_kwargs["close"] = False

save_fig(**s_kwargs)
elif save_show_or_return == "show":
if save_show_or_return in ["show", "both", "all"]:

with warnings.catch_warnings():
warnings.simplefilter("ignore")
plt.tight_layout()

plt.show()
elif save_show_or_return == "return":
if save_show_or_return in ["return", "all"]:
return g
else:
raise NotImplementedError("Unsupported save_show_or_return")


def dynamics(
Expand Down Expand Up @@ -2727,7 +2728,7 @@ def dynamics(
elif experiment_type == "coassay":
pass # show protein velocity (steady state and the Gamma distribution model)
# g.autofmt_xdate(rotation=-30, ha='right')
if save_show_or_return == "save":
if save_show_or_return in ["save", "both", "all"]:
s_kwargs = {
"path": None,
"prefix": "dynamics",
Expand All @@ -2738,11 +2739,15 @@ def dynamics(
"verbose": True,
}
s_kwargs = update_dict(s_kwargs, save_kwargs)

if save_show_or_return in ["both", "all"]:
s_kwargs["close"] = False

save_fig(**s_kwargs)
elif save_show_or_return == "show":
if save_show_or_return in ["show", "both", "all"]:
plt.tight_layout()
plt.show()
elif save_show_or_return == "return":
if save_show_or_return in ["return", "all"]:
return g


Expand Down
18 changes: 13 additions & 5 deletions dynamo/plot/fate.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def fate_bias(
fate_bias, col_cluster=True, row_cluster=True, figsize=figsize, yticklabels=False, **cluster_maps_kwargs
)

if save_show_or_return == "save":
if save_show_or_return in ["save", "both", "all"]:
s_kwargs = {
"path": None,
"prefix": "fate_bias",
Expand All @@ -86,11 +86,14 @@ def fate_bias(
}
s_kwargs = update_dict(s_kwargs, save_kwargs)

if save_show_or_return in ["both", "all"]:
s_kwargs["close"] = False

save_fig(**s_kwargs)
elif save_show_or_return == "show":
if save_show_or_return in ["show", "both", "all"]:
plt.tight_layout()
plt.show()
elif save_show_or_return == "return":
if save_show_or_return in ["return", "all"]:
return ax


Expand Down Expand Up @@ -154,11 +157,16 @@ def fate(
"close": True,
"verbose": True,
}

# prevent the plot from being closed if the plot need to be shown or returned.
if save_show_or_return in ["both", "all"]:
s_kwargs["close"] = False

s_kwargs = update_dict(s_kwargs, save_kwargs)

save_fig(**s_kwargs)
elif save_show_or_return in ["show", "both", "all"]:
if save_show_or_return in ["show", "both", "all"]:
plt.tight_layout()
plt.show()
elif save_show_or_return in ["return", "all"]:
if save_show_or_return in ["return", "all"]:
return ax
Loading

0 comments on commit 364e4e6

Please sign in to comment.