Skip to content

Commit

Permalink
formatting and import optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
parashardhapola committed Aug 1, 2024
1 parent 84e8c63 commit dff149d
Show file tree
Hide file tree
Showing 31 changed files with 110 additions and 70 deletions.
1 change: 1 addition & 0 deletions scarf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"""

import warnings

from dask.array import PerformanceWarning
from importlib_metadata import version

Expand Down
8 changes: 4 additions & 4 deletions scarf/ann.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from typing import Optional

import dask.array as da
import numpy as np
import pandas as pd
import dask.array as da

from threadpoolctl import threadpool_limits
from .utils import controlled_compute, logger, tqdmbar
from .harmony import run_harmony

from .harmony import run_harmony
from .utils import controlled_compute, logger, tqdmbar

__all__ = ["AnnStream", "instantiate_knn_index", "fix_knn_query"]

Expand Down
7 changes: 4 additions & 3 deletions scarf/assay.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
method for feature selection.
"""


from typing import Tuple, List, Generator, Optional, Union

import numpy as np
import pandas as pd
from dask.array.core import Array as daskArrayType
from dask.array.core import from_zarr
from zarr import hierarchy as z_hierarchy
from scipy.sparse import csr_matrix, vstack
import pandas as pd
from zarr import hierarchy as z_hierarchy

from .metadata import MetaData
from .utils import show_dask_progress, controlled_compute, logger

Expand Down
1 change: 1 addition & 0 deletions scarf/bio_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
g. cell cycle genes).
"""

from typing import List

__all__ = ["s_phase_genes", "g2m_phase_genes"]
Expand Down
4 changes: 3 additions & 1 deletion scarf/datastore/base_datastore.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from typing import List, Union, Optional

import numpy as np
import zarr
from loguru import logger
from ..utils import show_dask_progress, controlled_compute, load_zarr, ZARRLOC

from ..assay import RNAassay, ATACassay, ADTassay, Assay
from ..metadata import MetaData
from ..utils import show_dask_progress, controlled_compute, load_zarr, ZARRLOC


def sanitize_hierarchy(
Expand Down
6 changes: 4 additions & 2 deletions scarf/datastore/datastore.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
from typing import Iterable, Optional, Union, List, Literal, Tuple

import numpy as np
import pandas as pd
from dask import array as daskarr
from loguru import logger

from .mapping_datastore import MappingDatastore
from ..writers import create_zarr_obj_array, create_zarr_dataset
from ..utils import tqdmbar, controlled_compute, ZARRLOC
from ..assay import RNAassay, ATACassay
from ..feat_utils import hto_demux
from ..utils import tqdmbar, controlled_compute, ZARRLOC
from ..writers import create_zarr_obj_array, create_zarr_dataset

__all__ = ["DataStore"]

Expand Down
8 changes: 5 additions & 3 deletions scarf/datastore/graph_datastore.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
from typing import Tuple, Optional, Union, List, Callable
import os
from typing import Tuple, Optional, Union, List, Callable

import numpy as np
import pandas as pd
from dask.array import from_zarr # type: ignore
from loguru import logger
from scipy.sparse import csr_matrix, coo_matrix
from dask.array import from_zarr # type: ignore

from .base_datastore import BaseDataStore
from ..utils import clean_array, show_dask_progress, system_call, tqdmbar
from ..assay import Assay
from ..utils import clean_array, show_dask_progress, system_call, tqdmbar
from ..writers import create_zarr_dataset


Expand Down
6 changes: 4 additions & 2 deletions scarf/datastore/mapping_datastore.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
from typing import Generator, Tuple, List, Dict, Union, Callable, Optional
import os
from typing import Generator, Tuple, List, Dict, Union, Callable, Optional

import numpy as np
import pandas as pd
from dask import array as daskarr
from loguru import logger
from scipy.sparse import csr_matrix

from .graph_datastore import GraphDataStore
from ..assay import Assay, RNAassay
from ..writers import create_zarr_dataset
from ..utils import (
show_dask_progress,
clean_array,
tqdmbar,
controlled_compute,
system_call,
)
from ..writers import create_zarr_dataset


class MappingDatastore(GraphDataStore):
Expand Down
4 changes: 3 additions & 1 deletion scarf/dendrogram.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import numpy as np
from typing import List, Dict

import networkx as nx
import numpy as np

from .utils import logger, tqdmbar

__all__ = ["BalancedCut", "CoalesceTree", "make_digraph"]
Expand Down
6 changes: 4 additions & 2 deletions scarf/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
- fetch_dataset: Downloads datasets from online repositories and saves them in as-is format
"""

import io
import os
import tarfile
import pandas as pd
import io
import time
from json import JSONDecodeError

import pandas as pd

from .utils import logger, tqdmbar

__all__ = ["show_available_datasets", "fetch_dataset"]
Expand Down
6 changes: 4 additions & 2 deletions scarf/feat_utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
"""Utility functions for features."""
import pandas as pd
import numpy as np

from typing import List, Tuple

import numpy as np
import pandas as pd

__all__ = ["fit_lowess", "binned_sampling", "hto_demux"]


Expand Down
4 changes: 3 additions & 1 deletion scarf/harmony.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from functools import partial
import pandas as pd

import numpy as np
import pandas as pd
from sklearn.cluster import KMeans

from .utils import tqdmbar, logger


Expand Down
8 changes: 5 additions & 3 deletions scarf/knn_utils.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
"""Utility functions for running the KNN algorithm."""

from typing import List, Tuple

import numpy as np
import pandas as pd
from scipy.sparse import csr_matrix, coo_matrix
from numba import jit
from .writers import create_zarr_dataset
from scipy.sparse import csr_matrix, coo_matrix

from .ann import AnnStream
from .utils import tqdmbar, controlled_compute

from .writers import create_zarr_dataset

__all__ = [
"self_query_knn",
Expand Down
7 changes: 5 additions & 2 deletions scarf/mapping_utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
"""Utility functions for the mapping."""

from typing import Tuple

import dask.array as daskarr
import numpy as np
from typing import Tuple
import pandas as pd

from .assay import Assay
from .utils import controlled_compute, show_dask_progress, logger, tqdmbar
import pandas as pd

__all__ = ["align_features", "coral"]

Expand Down
11 changes: 7 additions & 4 deletions scarf/markers.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
"""Module to find biomarkers."""
from scarf.assay import Assay
from scarf.utils import logger, tqdmbar
from numba import jit

from typing import Optional

import numpy as np
import pandas as pd
from numba import jit
from scipy.stats import linregress
from typing import Optional
from scipy.stats import rankdata

from scarf.assay import Assay
from scarf.utils import logger, tqdmbar


def read_prenormed_batches(store, cell_idx: np.ndarray, batch_size: int, desc: str):
batch = {}
Expand Down
11 changes: 6 additions & 5 deletions scarf/meld_assay.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@
- coordinate_melding:
"""

import gzip
import logging
from typing import Tuple, List, Union
import pandas as pd

import numpy as np
import gzip
import pandas as pd
from numba import jit
from zarr import hierarchy
from scipy.sparse import coo_matrix
from .writers import create_zarr_count_assay
from .utils import controlled_compute, logger, tqdmbar
from zarr import hierarchy

from .utils import controlled_compute, logger, tqdmbar
from .writers import create_zarr_count_assay

__all__ = ["GffReader", "coordinate_melding"]

Expand Down
6 changes: 4 additions & 2 deletions scarf/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@

import re
from typing import List, Iterable, Any, Dict, Tuple, Optional, Union

import numpy as np
from zarr import hierarchy as z_hierarchy
import pandas as pd
from zarr import hierarchy as z_hierarchy

from .feat_utils import fit_lowess
from .writers import create_zarr_obj_array
from .utils import logger
from .writers import create_zarr_obj_array

zarrGroup = z_hierarchy.Group

Expand Down
10 changes: 6 additions & 4 deletions scarf/plots.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
"""Contains the code for plotting in Scarf."""
import matplotlib.pyplot as plt

from typing import Tuple, Optional, Union, List

import matplotlib as mpl
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from typing import Tuple, Optional, Union, List
import seaborn as sns
from cmocean import cm

from .utils import logger

plt.rcParams["svg.fonttype"] = "none"
Expand Down Expand Up @@ -1258,7 +1261,6 @@ def plot_annotated_heatmap(
save_dpi: int = 300,
show_fig: bool = True,
):
import matplotlib.gridspec as gridspec
import matplotlib.ticker as mticker

if display_row_labels is None:
Expand Down
8 changes: 5 additions & 3 deletions scarf/readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@
- LoomReader: A class to read in data in the form of a Loom file.
"""

import os
from abc import ABC, abstractmethod
from typing import Generator, Dict, List, Optional, Tuple
from typing import IO

import h5py
import numpy as np
import pandas as pd
import os
from scipy.sparse import coo_matrix
from typing import IO
import h5py

from .utils import logger, tqdmbar

__all__ = [
Expand Down
1 change: 1 addition & 0 deletions scarf/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import shutil
import sys

from ..utils import logger

logger.remove()
Expand Down
4 changes: 1 addition & 3 deletions scarf/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
from .fixtures_downloader import *
from .fixtures_readers import *
from .fixtures_datastore import *

5 changes: 3 additions & 2 deletions scarf/tests/fixtures_datastore.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import pytest
from . import full_path, remove
import numpy as np
import pandas as pd
import pytest

from . import full_path, remove


@pytest.fixture(scope="session")
Expand Down
1 change: 1 addition & 0 deletions scarf/tests/fixtures_downloader.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest

from . import full_path, remove


Expand Down
1 change: 1 addition & 0 deletions scarf/tests/fixtures_readers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest

from . import full_path, remove


Expand Down
7 changes: 3 additions & 4 deletions scarf/tests/test_datastore.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pandas as pd
import numpy as np
import pandas as pd

from . import full_path, remove


Expand Down Expand Up @@ -174,9 +175,7 @@ def test_run_pseudotime_marker_search(self, pseudotime_markers):
full_path("pseudotime_markers_r_values.csv"), index_col=0
)
assert np.all(precalc_markers.index == pseudotime_markers.index)
assert np.all(
precalc_markers.names.values == pseudotime_markers.names.values
)
assert np.all(precalc_markers.names.values == pseudotime_markers.names.values)
assert np.allclose(
precalc_markers.I__RNA_pseudotime__r.values,
pseudotime_markers.I__RNA_pseudotime__r.values,
Expand Down
3 changes: 2 additions & 1 deletion scarf/tests/test_metadata.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest
import numpy as np
import pytest

from . import full_path, remove


Expand Down
3 changes: 2 additions & 1 deletion scarf/tests/test_writers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from . import full_path, remove
import numpy as np

from . import full_path, remove


def test_crtozarr(crh5_reader):
from ..writers import CrToZarr
Expand Down
Loading

0 comments on commit dff149d

Please sign in to comment.