Skip to content

Commit

Permalink
lazily load the low-hanging fruit
Browse files Browse the repository at this point in the history
  • Loading branch information
theAeon committed Jul 14, 2024
1 parent 79b04ac commit 0bb00aa
Show file tree
Hide file tree
Showing 30 changed files with 100 additions and 58 deletions.
17 changes: 15 additions & 2 deletions pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ dependencies = [
"setuptools>=68.0.0",
"dask>=2024.4.1",
"dask-expr>=1.1.0",
"lazy-loader>=0.4",
]
description = "The Python version of LIGER package."
keywords = [
Expand Down
5 changes: 3 additions & 2 deletions src/pyliger/_utilities.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import os

import h5sparse
import numpy as np
import lazy_loader as lazy
h5sparse = lazy.load("h5sparse", error_on_import=True)
np = lazy.load("numpy", error_on_import=True)
from anndata import AnnData


Expand Down
5 changes: 3 additions & 2 deletions src/pyliger/clustering/_leiden.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import leidenalg
import numpy as np
import lazy_loader as lazy
leidenalg = lazy.load("leidenalg", error_on_import=True)
np = lazy.load("numpy", error_on_import=True)

from pyliger.clustering._utilities import (
_assign_cluster,
Expand Down
5 changes: 3 additions & 2 deletions src/pyliger/clustering/_louvain.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import louvain
import numpy as np
import lazy_loader as lazy
louvain = lazy.load("louvain", error_on_import=True)
np = lazy.load("numpy", error_on_import=True)

from pyliger.clustering._utilities import (
_assign_cluster,
Expand Down
5 changes: 3 additions & 2 deletions src/pyliger/clustering/_utilities.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import igraph as ig
import numpy as np
import lazy_loader as lazy
ig = lazy.load("igraph", error_on_import=True)
np = lazy.load("numpy", error_on_import=True)
from annoy import AnnoyIndex
from numba import njit
from pynndescent import NNDescent
Expand Down
3 changes: 2 additions & 1 deletion src/pyliger/factorization/_iNMF_ANLS.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy as np
import lazy_loader as lazy
np = lazy.load("numpy", error_on_import=True)
from tqdm import tqdm

from pyliger.factorization._utilities import nnlsm_blockpivot
Expand Down
3 changes: 2 additions & 1 deletion src/pyliger/factorization/_iNMF_HALS.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import lazy_loader as lazy
import time

import numpy as np
np = lazy.load("numpy", error_on_import=True)

from pyliger.factorization._utilities import (
_init_H,
Expand Down
5 changes: 3 additions & 2 deletions src/pyliger/factorization/_online_iNMF.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import h5sparse
import numpy as np
import lazy_loader as lazy
h5sparse = np = lazy.load("h5sparse", error_on_import=True)
np = lazy.load("numpy", error_on_import=True)
from scipy.sparse import vstack
from tqdm import tqdm

Expand Down
3 changes: 2 additions & 1 deletion src/pyliger/factorization/_utilities.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy as np
import lazy_loader as lazy
np = lazy.load("numpy", error_on_import=True)
import numpy.linalg as nla
import scipy.linalg as sla
import scipy.sparse as sps
Expand Down
3 changes: 2 additions & 1 deletion src/pyliger/plotting/_dataset_cluster.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy as np
import lazy_loader as lazy
np = lazy.load("numpy", error_on_import=True)
from plotnine import (
aes,
geom_point,
Expand Down
5 changes: 3 additions & 2 deletions src/pyliger/plotting/_gene.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import lazy_loader as lazy
import warnings
from typing import Optional

import numpy as np
import pandas as pd
np = lazy.load("numpy", error_on_import=True)
pd = lazy.load("pandas", error_on_import=True)
from plotnine import (
aes,
element_blank,
Expand Down
7 changes: 4 additions & 3 deletions src/pyliger/plotting/_gene_loadings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import matplotlib as mpl
import numpy as np
import pandas as pd
import lazy_loader as lazy
mpl = lazy.load("matplotlib", error_on_import=True)
np = lazy.load("numpy", error_on_import=True)
pd = lazy.load("pandas", error_on_import=True)
from plotnine import (
aes,
annotate,
Expand Down
10 changes: 6 additions & 4 deletions src/pyliger/plotting/_go.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
from datetime import date
from math import log, log10

import matplotlib
import lazy_loader as lazy

matplotlib = lazy.load("matplotlib", error_on_import=True)
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import seaborn as sns
np = lazy.load("numpy", error_on_import=True)
pd = lazy.load("pandas", error_on_import=True)
sns = lazy.load("seaborn", error_on_import=True)
from adjustText import (
adjust_text,
) # # Python package which rearranges plot labels to ensure minimal overlap
Expand Down
3 changes: 2 additions & 1 deletion src/pyliger/plotting/_spatial.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import lazy_loader as lazy
import matplotlib.pyplot as plt
import pandas as pd
pd = lazy.load("pandas", error_on_import=True)
from plotnine import (
aes,
element_blank,
Expand Down
3 changes: 2 additions & 1 deletion src/pyliger/plotting/_utilities.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy as np
import lazy_loader as lazy
np = lazy.load("numpy", error_on_import=True)


def get_gene_values(
Expand Down
5 changes: 3 additions & 2 deletions src/pyliger/preprocessing/_cal_feature.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from collections import Counter
from pathlib import Path
import lazy_loader as lazy

import numpy as np
import pandas as pd
np = lazy.load("numpy", error_on_import=True)
pd = lazy.load("pandas", error_on_import=True)
from anndata import AnnData
from scipy.sparse import csr_matrix

Expand Down
5 changes: 3 additions & 2 deletions src/pyliger/preprocessing/_initialization.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from os import path
from typing import List, Optional

import h5sparse
import numpy as np
import lazy_loader as lazy
h5sparse = lazy.load("h5sparse", error_on_import=True)
np = lazy.load("numpy", error_on_import=True)
from scipy.sparse import csr_matrix

from pyliger._utilities import _h5_idx_generator, _create_h5_using_adata, _merge_sparse_data_all, _remove_missing_obs
Expand Down
5 changes: 3 additions & 2 deletions src/pyliger/preprocessing/_normalization.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from pathlib import Path
from typing import Optional

import h5sparse
import numpy as np
import lazy_loader as lazy
h5sparse = lazy.load("h5sparse", error_on_import=True)
np = lazy.load("numpy", error_on_import=True)
from sklearn.preprocessing import normalize as sp_normalize

from pyliger._utilities import _h5_idx_generator, _remove_missing_obs
Expand Down
5 changes: 3 additions & 2 deletions src/pyliger/preprocessing/_qc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import numpy as np
import pandas as pd
import lazy_loader as lazy
np = lazy.load("numpy", error_on_import=True)
pd = lazy.load("pandas", error_on_import=True)


def calculate_qc(liger_object):
Expand Down
5 changes: 3 additions & 2 deletions src/pyliger/preprocessing/_scale.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from typing import Optional

import h5sparse
import numpy as np
import lazy_loader as lazy
h5sparse = lazy.load("h5sparse", error_on_import=True)
np = lazy.load("numpy", error_on_import=True)
from scipy.sparse import csr_matrix
from sklearn.utils.sparsefuncs import inplace_column_scale

Expand Down
7 changes: 4 additions & 3 deletions src/pyliger/preprocessing/_select_genes.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import warnings

import h5sparse
import lazy_loader as lazy
h5sparse = lazy.load("h5sparse", error_on_import=True)
import matplotlib.pyplot as plt
import numexpr as ne
import numpy as np
ne = lazy.load("numexpr", error_on_import=True)
np = lazy.load("numpy", error_on_import=True)
from scipy.optimize import minimize
from scipy.stats import norm
from sklearn.utils.sparsefuncs import mean_variance_axis
Expand Down
5 changes: 3 additions & 2 deletions src/pyliger/pyliger.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import numpy as np
import pandas as pd
import lazy_loader as lazy
np = lazy.load("numpy", error_on_import=True)
pd = lazy.load("pandas", error_on_import=True)
from anndata import AnnData
from scipy.sparse import vstack

Expand Down
10 changes: 6 additions & 4 deletions src/pyliger/read_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import re
from pathlib import Path

import anndata
import h5py
import numpy as np
import pandas as pd
import lazy_loader as lazy

anndata = lazy.load("anndata", error_on_import=True)
h5py = lazy.load("h5py", error_on_import=True)
np = lazy.load("numpy", error_on_import=True)
pd = lazy.load("pandas", error_on_import=True)
import scipy.io
from anndata import AnnData
from matplotlib.image import imread
Expand Down
4 changes: 2 additions & 2 deletions src/pyliger/tools/_go.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pathlib import Path

import mygene
import lazy_loader as lazy
mygene = lazy.load("mygene", error_on_import=True)
from goatools.anno.genetogo_reader import Gene2GoReader
from goatools.base import download_go_basic_obo, download_ncbi_associations
from goatools.goea.go_enrichment_ns import GOEnrichmentStudyNS
Expand Down
5 changes: 3 additions & 2 deletions src/pyliger/tools/_marker.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import numpy as np
import pandas as pd
import lazy_loader as lazy
np = lazy.load("numpy", error_on_import=True)
pd = lazy.load("pandas", error_on_import=True)
from scipy.sparse import vstack
from sklearn.preprocessing import scale

Expand Down
3 changes: 2 additions & 1 deletion src/pyliger/tools/_metrics.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy as np
import lazy_loader as lazy
np = lazy.load("numpy", error_on_import=True)


def calc_dataset_specificity(liger_object, dataset1=None, dataset2=None, do_plot=True):
Expand Down
3 changes: 2 additions & 1 deletion src/pyliger/tools/_quantile_norm.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy as np
import lazy_loader as lazy
np = lazy.load("numpy", error_on_import=True)
from scipy import interpolate
from scipy.stats.mstats import mquantiles

Expand Down
7 changes: 4 additions & 3 deletions src/pyliger/tools/_umap.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import numpy as np
import pandas as pd
import umap
import lazy_loader as lazy
np = lazy.load("numpy", error_on_import=True)
pd = lazy.load("pandas", error_on_import=True)
umap = lazy.load("umap", error_on_import=True)
import umap.plot


Expand Down
6 changes: 3 additions & 3 deletions src/pyliger/tools/_wilcoxon.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from functools import reduce

import numpy as np
import pandas as pd
import lazy_loader as lazy
np = lazy.load("numpy", error_on_import=True)
pd = lazy.load("pandas", error_on_import=True)
import statsmodels.stats.multitest as smt
from scipy.sparse import vstack
from scipy.stats import distributions
Expand Down

0 comments on commit 0bb00aa

Please sign in to comment.