Skip to content

Commit

Permalink
adapt to alpha 6 of dolomite-base
Browse files Browse the repository at this point in the history
  • Loading branch information
jkanche committed Jan 25, 2024
1 parent 3ad6eaa commit 79b32a0
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 15 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ python_requires = >=3.8
# For more information, check out https://semver.org/.
install_requires =
importlib-metadata; python_version<"3.8"
dolomite-base==0.2.0-alpha5
dolomite-base==0.2.0-alpha6
genomicranges>=0.4.10,<0.5.0
biocframe>=0.5.8,<0.6.0
h5py
Expand Down
7 changes: 4 additions & 3 deletions src/dolomite_ranges/read_genomic_ranges.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import os
from typing import Optional

import dolomite_base as dl
import h5py
from dolomite_base.read_object import registry
from dolomite_base.read_object import read_object_registry
from genomicranges import GenomicRanges
from iranges import IRanges

from .read_sequence_information import read_sequence_information

registry["genomic_ranges"] = "dolomite_ranges.read_genomic_ranges"
read_object_registry["genomic_ranges"] = "dolomite_ranges.read_genomic_ranges"


def read_genomic_ranges(path: str, metadata: dict, **kwargs) -> GenomicRanges:
def read_genomic_ranges(path: str, metadata: Optional[dict], **kwargs) -> GenomicRanges:
"""Load genomic ranges into a
:py:class:`~genomicranges.GenomicRanges.GenomicRanges` object.
Expand Down
9 changes: 6 additions & 3 deletions src/dolomite_ranges/read_genomic_ranges_list.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import os
from typing import Optional

import dolomite_base as dl
import h5py
from dolomite_base.read_object import registry
from dolomite_base.read_object import read_object_registry
from genomicranges import GenomicRangesList

from .read_genomic_ranges import read_genomic_ranges

registry["genomic_ranges_list"] = "dolomite_ranges.read_genomic_ranges_list"
read_object_registry["genomic_ranges_list"] = "dolomite_ranges.read_genomic_ranges_list"


def read_genomic_ranges_list(path: str, metadata: dict, **kwargs) -> GenomicRangesList:
def read_genomic_ranges_list(
path: str, metadata: Optional[dict], **kwargs
) -> GenomicRangesList:
"""Load genomic ranges into a
:py:class:`~genomicranges.GenomicRanges.GenomicRangesList` object.
Expand Down
9 changes: 6 additions & 3 deletions src/dolomite_ranges/read_sequence_information.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import os
from typing import Optional

import dolomite_base as dl
import h5py
from dolomite_base.read_object import registry
from dolomite_base.read_object import read_object_registry
from genomicranges import SeqInfo

registry["sequence_information"] = "dolomite_ranges.read_sequence_information"
read_object_registry[
"sequence_information"
] = "dolomite_ranges.read_sequence_information"


def read_sequence_information(path: str, metadata: dict, **kwargs) -> SeqInfo:
def read_sequence_information(path: str, metadata: Optional[dict], **kwargs) -> SeqInfo:
"""Load sequence information into a
:py:class:`~genomicranges.SeqInfo.SeqInfo` object.
Expand Down
18 changes: 16 additions & 2 deletions src/dolomite_ranges/save_genomic_ranges.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from typing import Optional

import dolomite_base as dl
import h5py
Expand All @@ -7,7 +8,9 @@

@dl.save_object.register
@dl.validate_saves
def save_genomic_ranges(x: GenomicRanges, path: str, **kwargs):
def save_genomic_ranges(
x: GenomicRanges, path: str, data_frame_args: Optional[dict] = None, **kwargs
):
"""Method for saving :py:class:`~genomicranges.GenomicRanges.GenomicRanges`
objects to their corresponding file representations, see
:py:meth:`~dolomite_base.save_object.save_object` for details.
Expand All @@ -19,6 +22,10 @@ def save_genomic_ranges(x: GenomicRanges, path: str, **kwargs):
path:
Path to a directory in which to save ``x``.
data_frame_args:
Further arguments to pass to the ``save_object`` method for
``mcols``.
kwargs:
Further arguments to be passed to individual methods.
Expand All @@ -27,6 +34,9 @@ def save_genomic_ranges(x: GenomicRanges, path: str, **kwargs):
"""
os.mkdir(path)

if data_frame_args is None:
data_frame_args = {}

with open(os.path.join(path, "OBJECT"), "w", encoding="utf-8") as handle:
handle.write(
'{ "type": "genomic_ranges", "genomic_ranges": { "version": "1.0" } }'
Expand Down Expand Up @@ -61,7 +71,11 @@ def save_genomic_ranges(x: GenomicRanges, path: str, **kwargs):

_range_annotation = x.get_mcols()
if _range_annotation is not None and _range_annotation.shape[1] > 0:
dl.save_object(_range_annotation, path=os.path.join(path, "range_annotations"))
dl.save_object(
_range_annotation,
path=os.path.join(path, "range_annotations"),
**data_frame_args
)

_meta = x.get_metadata()
if _meta is not None and len(_meta) > 0:
Expand Down
18 changes: 16 additions & 2 deletions src/dolomite_ranges/save_genomic_ranges_list.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from typing import Optional

import dolomite_base as dl
import h5py
Expand All @@ -8,7 +9,9 @@

@dl.save_object.register
@dl.validate_saves
def save_genomic_ranges_list(x: GenomicRangesList, path: str, **kwargs):
def save_genomic_ranges_list(
x: GenomicRangesList, path: str, data_frame_args: Optional[dict] = None, **kwargs
):
"""Method for saving :py:class:`~genomicranges.GenomicRanges.GenomicRangesList`
objects to their corresponding file representations, see
:py:meth:`~dolomite_base.save_object.save_object` for details.
Expand All @@ -20,6 +23,10 @@ def save_genomic_ranges_list(x: GenomicRangesList, path: str, **kwargs):
path:
Path to a directory in which to save ``x``.
data_frame_args:
Further arguments to pass to the ``save_object`` method for
``mcols``.
kwargs:
Further arguments to be passed to individual methods.
Expand All @@ -28,6 +35,9 @@ def save_genomic_ranges_list(x: GenomicRangesList, path: str, **kwargs):
"""
os.mkdir(path)

if data_frame_args is None:
data_frame_args = {}

with open(os.path.join(path, "OBJECT"), "w", encoding="utf-8") as handle:
handle.write(
'{ "type": "genomic_ranges_list", "genomic_ranges_list": { "version": "1.0" } }'
Expand All @@ -51,7 +61,11 @@ def save_genomic_ranges_list(x: GenomicRangesList, path: str, **kwargs):

_elem_annotation = x.get_mcols()
if _elem_annotation is not None and _elem_annotation.shape[1] > 0:
dl.save_object(_elem_annotation, path=os.path.join(path, "element_annotations"))
dl.save_object(
_elem_annotation,
path=os.path.join(path, "element_annotations"),
**data_frame_args
)

_meta = x.get_metadata()
if _meta is not None and len(_meta) > 0:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_granges_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_genomic_ranges_list():
assert len(roundtrip.get_ranges()) == len(grl.get_ranges())
assert (roundtrip["a"].get_start() == grl["a"].get_start()).all()
assert (roundtrip["a"].get_strand() == grl["a"].get_strand()).all()
assert (roundtrip.get_range_lengths() == grl.get_range_lengths()).all()


def test_genomic_ranges_list_empty():
grl = GenomicRangesList.empty(n=100)
Expand Down

0 comments on commit 79b32a0

Please sign in to comment.