Skip to content
This repository has been archived by the owner on Jan 2, 2025. It is now read-only.

✨ Added view_tree for keys #317

Merged
merged 1 commit into from
Nov 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 23 additions & 40 deletions lnschema_core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,28 @@
TRANSFORM_TYPE_DEFAULT = TransformType.notebook if IPYTHON else TransformType.pipeline


class IsTree:
"""Base class providing view_tree function."""

@classmethod
def view_tree(
cls,
level: int = -1,
limit_to_directories: bool = False,
length_limit: int = 1000,
max_files_per_dir_per_type: int = 7,
) -> None:
"""View the tree structure of the keys.

Args:
level: ``int=-1`` Depth of the tree to be displayed. Default is -1 which means all levels.
limit_to_directories: ``bool=False`` If True, only directories will be displayed.
length_limit: ``int=1000`` Maximum number of nodes to be displayed.
max_files_per_dir_per_type: ``int=7`` Maximum number of files per directory per type.
"""
pass


class CanValidate:
"""Base class providing :class:`~lamindb.dev.Registry`-based validation."""

Expand Down Expand Up @@ -1291,7 +1313,7 @@ def members(self) -> "QuerySet":
pass


class File(Registry, Data):
class File(Registry, Data, IsTree):
"""Files: data batches.

Args:
Expand Down Expand Up @@ -1667,45 +1689,6 @@ def backed(self, is_run_input: Optional[bool] = None) -> Union["AnnDataAccessor"
"""
pass

@classmethod
def view_tree(
cls,
path: Optional[PathLike] = None,
*,
level: int = -1,
limit_to_directories: bool = False,
length_limit: int = 1000,
) -> None:
"""Print a visual tree structure of files & directories.

Examples:
>>> dir_path = ln.dev.datasets.generate_cell_ranger_files("sample_001", ln.settings.storage)
>>> dir_path.name
'sample_001'
>>> ln.File.view_tree(dir_path)
3 subdirectories, 15 files
sample_001
├── web_summary.html
├── metrics_summary.csv
├── molecule_info.h5
├── filtered_feature_bc_matrix
│ ├── features.tsv.gz
│ ├── barcodes.tsv.gz
│ └── matrix.mtx.gz
├── analysis
│ └── analysis.csv
├── raw_feature_bc_matrix
│ ├── features.tsv.gz
│ ├── barcodes.tsv.gz
│ └── matrix.mtx.gz
├── possorted_genome_bam.bam.bai
├── cloupe.cloupe
├── possorted_genome_bam.bam
├── filtered_feature_bc_matrix.h5
└── raw_feature_bc_matrix.h5
"""
pass

def load(self, is_run_input: Optional[bool] = None, stream: bool = False, **kwargs) -> DataLike:
"""Stage and load to memory.

Expand Down
Loading