Skip to content

Commit

Permalink
Fix ruff config
Browse files Browse the repository at this point in the history
Signed-off-by: zethson <[email protected]>
  • Loading branch information
Zethson committed Feb 6, 2024
1 parent a43baac commit 432988d
Show file tree
Hide file tree
Showing 14 changed files with 94 additions and 62 deletions.
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
author = "Lukas Heumos"
github_repo = "ehrapy"

version = "0.6.0"
release = "0.6.0"
version = "0.7.0"
release = "0.7.0"

extensions = [
"myst_parser",
Expand Down
2 changes: 1 addition & 1 deletion ehrapy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

__author__ = "Lukas Heumos"
__email__ = "[email protected]"
__version__ = "0.6.0"
__version__ = "0.7.0"

from ehrapy._settings import EhrapyConfig, ehrapy_settings

Expand Down
14 changes: 7 additions & 7 deletions ehrapy/anndata/anndata_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def move_to_obs(adata: AnnData, to_obs: list[str] | str, copy_obs: bool = False)
Examples:
>>> import ehrapy as ep
>>> adata = ep.dt.mimic_2(encoded=True)
>>> ep.ad.move_to_obs(adata, ['age'], copy_obs=False)
>>> ep.ad.move_to_obs(adata, ["age"], copy_obs=False)
"""
if isinstance(to_obs, str): # pragma: no cover
to_obs = [to_obs]
Expand Down Expand Up @@ -255,8 +255,8 @@ def delete_from_obs(adata: AnnData, to_delete: list[str]) -> AnnData:
Examples:
>>> import ehrapy as ep
>>> adata = ep.dt.mimic_2(encoded=True)
>>> ep.ad.move_to_obs(adata, ['age'], copy_obs=True)
>>> ep.ad.delete_from_obs(adata, ['age'])
>>> ep.ad.move_to_obs(adata, ["age"], copy_obs=True)
>>> ep.ad.delete_from_obs(adata, ["age"])
"""
if isinstance(to_delete, str): # pragma: no cover
to_delete = [to_delete]
Expand Down Expand Up @@ -287,8 +287,8 @@ def move_to_x(adata: AnnData, to_x: list[str] | str) -> AnnData:
Examples:
>>> import ehrapy as ep
>>> adata = ep.dt.mimic_2(encoded=True)
>>> ep.ad.move_to_obs(adata, ['age'], copy_obs=False)
>>> new_adata = ep.ad.move_to_x(adata, ['age'])
>>> ep.ad.move_to_obs(adata, ["age"], copy_obs=False)
>>> new_adata = ep.ad.move_to_x(adata, ["age"])
"""
if isinstance(to_x, str): # pragma: no cover
to_x = [to_x]
Expand Down Expand Up @@ -807,7 +807,7 @@ def get_obs_df( # pragma: no cover
Examples:
>>> import ehrapy as ep
>>> adata = ep.dt.mimic_2(encoded=True)
>>> ages = ep.ad.get_obs_df(adata, keys = ['age'])
>>> ages = ep.ad.get_obs_df(adata, keys=["age"])
"""
return obs_df(adata=adata, keys=keys, obsm_keys=obsm_keys, layer=layer, gene_symbols=features)

Expand All @@ -833,7 +833,7 @@ def get_var_df( # pragma: no cover
Examples:
>>> import ehrapy as ep
>>> adata = ep.dt.mimic_2(encoded=True)
>>> four_patients = ep.ad.get_var_df(adata, keys = ['0', '1', '2', '3'])
>>> four_patients = ep.ad.get_var_df(adata, keys=["0", "1", "2", "3"])
"""
return var_df(adata=adata, keys=keys, varm_keys=varm_keys, layer=layer)

Expand Down
4 changes: 2 additions & 2 deletions ehrapy/data/_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ def parkinsons(
Examples:
>>> import ehrapy as ep
>>> adata = ep.dt.parkinsons(columns_obs_only=['name'], encoded=True)
>>> adata = ep.dt.parkinsons(columns_obs_only=["name"], encoded=True)
"""
adata: AnnData = read_csv(
dataset_path=f"{ehrapy_settings.datasetdir}/parkinsons.csv",
Expand Down Expand Up @@ -582,7 +582,7 @@ def parkinson_dataset_with_replicated_acoustic_features(
Examples:
>>> import ehrapy as ep
>>> adata = ep.dt.parkinson_dataset_with_replicated_acoustic_features(columns_obs_only=['ID'], encoded=True)
>>> adata = ep.dt.parkinson_dataset_with_replicated_acoustic_features(columns_obs_only=["ID"], encoded=True)
"""
adata: AnnData = read_csv(
dataset_path=f"{ehrapy_settings.datasetdir}/parkinson_dataset_with_replicated_acoustic_features.csv",
Expand Down
5 changes: 4 additions & 1 deletion ehrapy/io/_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,10 @@ def read_fhir(
Be aware that most FHIR datasets have nested data that might need to be removed.
In such cases consider working with DataFrames.
>>> df = ep.io.read_fhir("/path/to/fhir/resources", return_df=True)
>>> df.drop(columns=[col for col in df.columns if any(isinstance(x, (list, dict)) for x in df[col].dropna())], inplace=True)
>>> df.drop(
... columns=[col for col in df.columns if any(isinstance(x, (list, dict)) for x in df[col].dropna())],
... inplace=True,
... )
>>> df.drop(columns=df.columns[df.isna().all()], inplace=True)
"""
_check_columns_only_params(columns_obs_only, columns_x_only)
Expand Down
8 changes: 4 additions & 4 deletions ehrapy/plot/_missingno_pl_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def missing_values_matrix(
Examples:
>>> import ehrapy as ep
>>> adata = ep.data.mimic_2(encoded=True)
>>> ep.pl.missing_values_matrix(adata, filter='bottom', max_cols=15, max_percentage=0.999)
>>> ep.pl.missing_values_matrix(adata, filter="bottom", max_cols=15, max_percentage=0.999)
Preview:
.. image:: /_static/docstring_previews/missingno_matrix.png
Expand Down Expand Up @@ -128,7 +128,7 @@ def missing_values_barplot(
Examples:
>>> import ehrapy as ep
>>> adata = ep.data.mimic_2(encoded=True)
>>> ep.pl.missing_values_barplot(adata, filter='bottom', max_cols=15, max_percentage=0.999)
>>> ep.pl.missing_values_barplot(adata, filter="bottom", max_cols=15, max_percentage=0.999)
Preview:
.. image:: /_static/docstring_previews/missingno_barplot.png
Expand Down Expand Up @@ -210,7 +210,7 @@ def missing_values_heatmap(
Examples:
>>> import ehrapy as ep
>>> adata = ep.data.mimic_2(encoded=True)
>>> ep.pl.missing_values_heatmap(adata, filter='bottom', max_cols=15, max_percentage=0.999)
>>> ep.pl.missing_values_heatmap(adata, filter="bottom", max_cols=15, max_percentage=0.999)
Preview:
.. image:: /_static/docstring_previews/missingno_heatmap.png
Expand Down Expand Up @@ -288,7 +288,7 @@ def missing_values_dendrogram(
Example:
>>> import ehrapy as ep
>>> adata = ep.data.mimic_2(encoded=True)
>>> ep.pl.missing_values_dendrogram(adata, filter='bottom', max_cols=15, max_percentage=0.999)
>>> ep.pl.missing_values_dendrogram(adata, filter="bottom", max_cols=15, max_percentage=0.999)
Preview:
.. image:: /_static/docstring_previews/missingno_dendrogram.png
Expand Down
24 changes: 14 additions & 10 deletions ehrapy/plot/_scanpy_pl_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1076,7 +1076,7 @@ def pca_loadings(
>>> ep.pp.log_norm(adata, offset=1)
>>> ep.pp.neighbors(adata)
>>> ep.pp.pca(adata)
>>> ep.pl.pca_loadings(adata, components='1,2,3')
>>> ep.pl.pca_loadings(adata, components="1,2,3")
Preview:
.. image:: /_static/docstring_previews/pca_loadings.png
Expand Down Expand Up @@ -1143,7 +1143,7 @@ def pca_overview(adata: AnnData, **params): # pragma: no cover
>>> ep.pp.log_norm(adata, offset=1)
>>> ep.pp.neighbors(adata)
>>> ep.pp.pca(adata)
>>> ep.pl.pca_overview(adata, components='1,2,3', color="service_unit")
>>> ep.pl.pca_overview(adata, components="1,2,3", color="service_unit")
Preview:
.. image:: /_static/docstring_previews/pca_overview_1.png
Expand Down Expand Up @@ -1185,7 +1185,9 @@ def tsne(adata, **kwargs) -> Axes | list[Axes] | None: # pragma: no cover
.. image:: /_static/docstring_previews/tsne_1.png
>>> ep.pl.tsne(adata, color=["day_icu_intime", "service_unit"], wspace=0.5, title=["Day of ICU admission", "Service unit"])
>>> ep.pl.tsne(
... adata, color=["day_icu_intime", "service_unit"], wspace=0.5, title=["Day of ICU admission", "Service unit"]
... )
.. image:: /_static/docstring_previews/tsne_2.png
Expand Down Expand Up @@ -1228,7 +1230,9 @@ def umap(adata: AnnData, **kwargs) -> Axes | list[Axes] | None: # pragma: no co
.. image:: /_static/docstring_previews/umap_1.png
>>> ep.pl.umap(adata, color=["day_icu_intime", "service_unit"], wspace=0.5, title=["Day of ICU admission", "Service unit"])
>>> ep.pl.umap(
... adata, color=["day_icu_intime", "service_unit"], wspace=0.5, title=["Day of ICU admission", "Service unit"]
... )
.. image:: /_static/docstring_previews/umap_2.png
Expand Down Expand Up @@ -1265,7 +1269,7 @@ def diffmap(adata, **kwargs) -> Axes | list[Axes] | None: # pragma: no cover
>>> ep.pp.log_norm(adata, offset=1)
>>> ep.pp.neighbors(adata)
>>> ep.tl.diffmap(adata)
>>> ep.pl.diffmap(adata, color='day_icu_intime')
>>> ep.pl.diffmap(adata, color="day_icu_intime")
Preview:
.. image:: /_static/docstring_previews/diffmap.png
Expand Down Expand Up @@ -1402,7 +1406,7 @@ def embedding(
>>> ep.pp.log_norm(adata, offset=1)
>>> ep.pp.neighbors(adata)
>>> ep.tl.umap(adata)
>>> ep.pl.embedding(adata, 'X_umap', color='icu_exp_flg')
>>> ep.pl.embedding(adata, "X_umap", color="icu_exp_flg")
Preview:
.. image:: /_static/docstring_previews/embedding.png
Expand Down Expand Up @@ -1580,10 +1584,10 @@ def dpt_groups_pseudotime(
>>> adata = ep.dt.mimic_2(encoded=True)
>>> ep.pp.knn_impute(adata)
>>> ep.pp.log_norm(adata, offset=1)
>>> ep.pp.neighbors(adata, method='gauss')
>>> ep.pp.neighbors(adata, method="gauss")
>>> ep.tl.leiden(adata, resolution=0.5, key_added="leiden_0_5")
>>> ep.tl.diffmap(adata, n_comps=10)
>>> adata.uns['iroot'] = np.flatnonzero(adata.obs['leiden_0_5'] == '0')[0]
>>> adata.uns["iroot"] = np.flatnonzero(adata.obs["leiden_0_5"] == "0")[0]
>>> ep.tl.dpt(adata, n_branchings=3)
>>> ep.pl.dpt_groups_pseudotime(adata)
Expand Down Expand Up @@ -1615,10 +1619,10 @@ def dpt_timeseries(
>>> adata = ep.dt.mimic_2(encoded=True)
>>> ep.pp.knn_impute(adata)
>>> ep.pp.log_norm(adata, offset=1)
>>> ep.pp.neighbors(adata, method='gauss')
>>> ep.pp.neighbors(adata, method="gauss")
>>> ep.tl.leiden(adata, resolution=0.5, key_added="leiden_0_5")
>>> ep.tl.diffmap(adata, n_comps=10)
>>> adata.uns['iroot'] = np.flatnonzero(adata.obs['leiden_0_5'] == '0')[0]
>>> adata.uns["iroot"] = np.flatnonzero(adata.obs["leiden_0_5"] == "0")[0]
>>> ep.tl.dpt(adata, n_branchings=3)
>>> ep.pl.dpt_timeseries(adata)
Expand Down
40 changes: 26 additions & 14 deletions ehrapy/plot/_survival_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,18 @@ def ols(
Examples:
>>> import ehrapy as ep
>>> adata = ep.dt.mimic_2(encoded=False)
>>> co2_lm_result = ep.tl.ols(adata, var_names=['pco2_first', 'tco2_first'], formula='tco2_first ~ pco2_first', missing="drop").fit()
>>> ep.pl.ols(adata, x='pco2_first', y='tco2_first', ols_results=[co2_lm_result], ols_color=['red'], xlabel="PCO2", ylabel="TCO2")
>>> co2_lm_result = ep.tl.ols(
... adata, var_names=["pco2_first", "tco2_first"], formula="tco2_first ~ pco2_first", missing="drop"
... ).fit()
>>> ep.pl.ols(
... adata,
... x="pco2_first",
... y="tco2_first",
... ols_results=[co2_lm_result],
... ols_color=["red"],
... xlabel="PCO2",
... ylabel="TCO2",
... )
.. image:: /_static/docstring_previews/ols_plot_1.png
Expand Down Expand Up @@ -175,21 +185,23 @@ def kmf(
# While in KaplanMeierFitter, `event_observed` is True if the the death was observed, False if the event was lost (right-censored).
# So we need to flip `censor_fl` when pass `censor_fl` to KaplanMeierFitter
>>> adata[:, ['censor_flg']].X = np.where(adata[:, ['censor_flg']].X == 0, 1, 0)
>>> kmf = ep.tl.kmf(adata[:, ['mort_day_censored']].X, adata[:, ['censor_flg']].X)
>>> ep.pl.kmf([kmf], color=['r'], xlim=[0, 700], ylim=[0, 1], xlabel="Days", ylabel="Proportion Survived", show=True)
>>> adata[:, ["censor_flg"]].X = np.where(adata[:, ["censor_flg"]].X == 0, 1, 0)
>>> kmf = ep.tl.kmf(adata[:, ["mort_day_censored"]].X, adata[:, ["censor_flg"]].X)
>>> ep.pl.kmf(
... [kmf], color=["r"], xlim=[0, 700], ylim=[0, 1], xlabel="Days", ylabel="Proportion Survived", show=True
... )
.. image:: /_static/docstring_previews/kmf_plot_1.png
>>> T = adata[:, ['mort_day_censored']].X
>>> E = adata[:, ['censor_flg']].X
>>> groups = adata[:, ['service_unit']].X
>>> ix1 = (groups == 'FICU')
>>> ix2 = (groups == 'MICU')
>>> ix3 = (groups == 'SICU')
>>> kmf_1 = ep.tl.kmf(T[ix1], E[ix1], label='FICU')
>>> kmf_2 = ep.tl.kmf(T[ix2], E[ix2], label='MICU')
>>> kmf_3 = ep.tl.kmf(T[ix3], E[ix3], label='SICU')
>>> T = adata[:, ["mort_day_censored"]].X
>>> E = adata[:, ["censor_flg"]].X
>>> groups = adata[:, ["service_unit"]].X
>>> ix1 = groups == "FICU"
>>> ix2 = groups == "MICU"
>>> ix3 = groups == "SICU"
>>> kmf_1 = ep.tl.kmf(T[ix1], E[ix1], label="FICU")
>>> kmf_2 = ep.tl.kmf(T[ix2], E[ix2], label="MICU")
>>> kmf_3 = ep.tl.kmf(T[ix3], E[ix3], label="SICU")
>>> ep.pl.kmf([kmf_1, kmf_2, kmf_3], ci_show=[False,False,False], color=['k','r', 'g'],
>>> xlim=[0, 750], ylim=[0, 1], xlabel="Days", ylabel="Proportion Survived")
Expand Down
2 changes: 1 addition & 1 deletion ehrapy/preprocessing/_encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def encode(
Examples:
>>> import ehrapy as ep
>>> adata = ep.dt.mimic_2()
>>> adata_encoded = ep.pp.encode(adata, autodetect=True, encodings='one_hot_encoding')
>>> adata_encoded = ep.pp.encode(adata, autodetect=True, encodings="one_hot_encoding")
>>> # Example using custom encodings per columns:
>>> import ehrapy as ep
Expand Down
4 changes: 2 additions & 2 deletions ehrapy/preprocessing/_outliers.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def winsorize(
Examples:
>>> import ehrapy as ep
>>> adata = ep.dt.mimic_2(encoded=True)
>>> ep.pp.winsorize(adata, ['bmi'])
>>> ep.pp.winsorize(adata, ["bmi"])
"""
_validate_outlier_input(adata, obs_cols, vars)

Expand Down Expand Up @@ -88,7 +88,7 @@ def clip_quantile(
Examples:
>>> import ehrapy as ep
>>> adata = ep.dt.mimic_2(encoded=True)
>>> ep.pp.clip_quantile(adata, ['bmi'])
>>> ep.pp.clip_quantile(adata, ["bmi"])
"""
obs_cols, vars = _validate_outlier_input(adata, obs_cols, vars) # type: ignore

Expand Down
20 changes: 10 additions & 10 deletions ehrapy/tools/_sa.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ def ols(
Examples:
>>> import ehrapy as ep
>>> adata = ep.dt.mimic_2(encoded=False)
>>> formula = 'tco2_first ~ pco2_first'
>>> var_names = ['tco2_first', 'pco2_first']
>>> ols = ep.tl.ols(adata, var_names, formula, missing = 'drop')
>>> formula = "tco2_first ~ pco2_first"
>>> var_names = ["tco2_first", "pco2_first"]
>>> ols = ep.tl.ols(adata, var_names, formula, missing="drop")
"""
if isinstance(var_names, list):
data = pd.DataFrame(adata[:, var_names].X, columns=var_names).astype(float)
Expand Down Expand Up @@ -85,10 +85,10 @@ def glm(
Examples:
>>> import ehrapy as ep
>>> adata = ep.dt.mimic_2(encoded=False)
>>> formula = 'day_28_flg ~ age'
>>> var_names = ['day_28_flg', 'age']
>>> family = 'Binomial'
>>> glm = ep.tl.glm(adata, var_names, formula, family, missing = 'drop', ascontinus = ['age'])
>>> formula = "day_28_flg ~ age"
>>> var_names = ["day_28_flg", "age"]
>>> family = "Binomial"
>>> glm = ep.tl.glm(adata, var_names, formula, family, missing="drop", ascontinus=["age"])
"""
family_dict = {
"Gaussian": sm.families.Gaussian(),
Expand Down Expand Up @@ -149,8 +149,8 @@ def kmf(
>>> import ehrapy as ep
>>> adata = ep.dt.mimic_2(encoded=False)
>>> # Flip 'censor_fl' because 0 = death and 1 = censored
>>> adata[:, ['censor_flg']].X = np.where(adata[:, ['censor_flg']].X == 0, 1, 0)
>>> kmf = ep.tl.kmf(adata[:, ['mort_day_censored']].X, adata[:, ['censor_flg']].X)
>>> adata[:, ["censor_flg"]].X = np.where(adata[:, ["censor_flg"]].X == 0, 1, 0)
>>> kmf = ep.tl.kmf(adata[:, ["mort_day_censored"]].X, adata[:, ["censor_flg"]].X)
"""
kmf = KaplanMeierFitter()
if censoring == "None" or "right":
Expand Down Expand Up @@ -288,7 +288,7 @@ def cox_ph(adata: AnnData, duration_col: str, event_col: str, entry_col: str = N
>>> import ehrapy as ep
>>> adata = ep.dt.mimic_2(encoded=False)
>>> # Flip 'censor_fl' because 0 = death and 1 = censored
>>> adata[:, ['censor_flg']].X = np.where(adata[:, ['censor_flg']].X == 0, 1, 0)
>>> adata[:, ["censor_flg"]].X = np.where(adata[:, ["censor_flg"]].X == 0, 1, 0)
>>> cph = ep.tl.cox_ph(adata, "mort_day_censored", "censor_flg")
"""
df = anndata_to_df(adata)
Expand Down
6 changes: 3 additions & 3 deletions ehrapy/tools/_scanpy_tl_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,8 @@ def embedding_density(
>>> import ehrapy as ep
>>> adata = ep.data.mimic_2(encoded=True)
>>> ep.tl.umap(adata)
>>> ep.tl.embedding_density(adata, basis='umap', groupby='phase')
>>> ep.pl.embedding_density(adata, basis='umap', key='umap_density_phase', group='G1')
>>> ep.tl.embedding_density(adata, basis="umap", groupby="phase")
>>> ep.pl.embedding_density(adata, basis="umap", key="umap_density_phase", group="G1")
"""
sc.tl.embedding_density(adata=adata, basis=basis, groupby=groupby, key_added=key_added, components=components)

Expand Down Expand Up @@ -477,7 +477,7 @@ def dendrogram(
Examples:
>>> import ehrapy as ep
>>> adata = ep.data.mimic_2(encoded=True)
>>> ep.tl.dendrogram(adata, groupby='service_unit')
>>> ep.tl.dendrogram(adata, groupby="service_unit")
>>> ep.pl.dendrogram(adata)
"""
return sc.tl.dendrogram(
Expand Down
11 changes: 9 additions & 2 deletions ehrapy/tools/feature_ranking/_rank_features_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,14 +389,21 @@ def rank_features_groups(
>>> adata = ep.dt.mimic_2(encoded=False)
>>> # want to move some metadata to the obs field
>>> ep.anndata.move_to_obs(adata, to_obs=["service_unit", "service_num", "age", "mort_day_censored"])
>>> ep.tl.rank_features_groups(adata, "service_unit", field_to_rank="obs", columns_to_rank={"obs_names": ["age", "mort_day_censored"]})
>>> ep.tl.rank_features_groups(
... adata, "service_unit", field_to_rank="obs", columns_to_rank={"obs_names": ["age", "mort_day_censored"]}
... )
>>> ep.pl.rank_features_groups(adata)
>>> import ehrapy as ep
>>> adata = ep.dt.mimic_2(encoded=False)
>>> # want to move some metadata to the obs field
>>> ep.anndata.move_to_obs(adata, to_obs=["service_unit", "service_num", "age", "mort_day_censored"])
>>> ep.tl.rank_features_groups(adata, "service_unit", field_to_rank="layer_and_obs", columns_to_rank={"var_names": ['copd_flg', 'renal_flg'], "obs_names": ["age", "mort_day_censored"]})
>>> ep.tl.rank_features_groups(
... adata,
... "service_unit",
... field_to_rank="layer_and_obs",
... columns_to_rank={"var_names": ["copd_flg", "renal_flg"], "obs_names": ["age", "mort_day_censored"]},
... )
>>> ep.pl.rank_features_groups(adata)
"""
Expand Down
Loading

0 comments on commit 432988d

Please sign in to comment.