Skip to content

Commit

Permalink
use alt_read and alt_save functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jkanche committed May 20, 2024
1 parent 602e2e7 commit d457181
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
8 changes: 3 additions & 5 deletions src/dolomite_ranges/read_genomic_ranges.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
from genomicranges import GenomicRanges
from iranges import IRanges

from .read_sequence_information import read_sequence_information

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


Expand All @@ -34,7 +32,7 @@ def read_genomic_ranges(path: str, metadata: Optional[dict], **kwargs) -> Genomi
A :py:class:`~genomicranges.GenomicRanges.GenomicRanges` object.
"""
_seqinfo_path = os.path.join(path, "sequence_information")
seqinfo = read_sequence_information(path=_seqinfo_path, metadata=None)
seqinfo = dl.alt_read_object(path=_seqinfo_path, **kwargs)

with h5py.File(os.path.join(path, "ranges.h5"), "r") as handle:
ghandle = handle["genomic_ranges"]
Expand Down Expand Up @@ -64,12 +62,12 @@ def read_genomic_ranges(path: str, metadata: Optional[dict], **kwargs) -> Genomi

_range_annotation_path = os.path.join(path, "range_annotations")
if os.path.exists(_range_annotation_path):
_mcols = dl.read_object(_range_annotation_path)
_mcols = dl.alt_read_object(_range_annotation_path, **kwargs)
gr = gr.set_mcols(_mcols)

_meta_path = os.path.join(path, "other_annotations")
if os.path.exists(_meta_path):
_meta = dl.read_object(_meta_path)
_meta = dl.alt_read_object(_meta_path, **kwargs)
gr = gr.set_metadata(_meta.as_dict())

return gr
10 changes: 3 additions & 7 deletions src/dolomite_ranges/read_genomic_ranges_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
from dolomite_base.read_object import read_object_registry
from genomicranges import GenomicRangesList

from .read_genomic_ranges import read_genomic_ranges

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


Expand Down Expand Up @@ -48,9 +46,7 @@ def read_genomic_ranges_list(
ghandle["names"], expected_type=str, report_1darray=True
)

_all_granges = read_genomic_ranges(
path=os.path.join(path, "concatenated"), metadata=None
)
_all_granges = dl.alt_read_object(path=os.path.join(path, "concatenated"), **kwargs)

counter = 0
_split_granges = []
Expand All @@ -66,12 +62,12 @@ def read_genomic_ranges_list(

_elem_annotation_path = os.path.join(path, "element_annotations")
if os.path.exists(_elem_annotation_path):
_mcols = dl.read_object(_elem_annotation_path)
_mcols = dl.alt_read_object(_elem_annotation_path, **kwargs)
grl = grl.set_mcols(_mcols)

_meta_path = os.path.join(path, "other_annotations")
if os.path.exists(_meta_path):
_meta = dl.read_object(_meta_path)
_meta = dl.alt_read_object(_meta_path, **kwargs)
grl = grl.set_metadata(_meta.as_dict())

return grl
6 changes: 4 additions & 2 deletions src/dolomite_ranges/save_genomic_ranges.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,16 @@ def save_genomic_ranges(

_range_annotation = x.get_mcols()
if _range_annotation is not None and _range_annotation.shape[1] > 0:
dl.save_object(
dl.alt_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:
dl.save_object(_meta, path=os.path.join(path, "other_annotations"))
dl.alt_save_object(
_meta, path=os.path.join(path, "other_annotations"), **kwargs
)

return
8 changes: 5 additions & 3 deletions src/dolomite_ranges/save_genomic_ranges_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,20 @@ def save_genomic_ranges_list(
if isinstance(_all_ranges, list) and len(_all_ranges) > 1:
_all_ranges = combine_sequences(*x.get_ranges())

dl.save_object(_all_ranges, path=os.path.join(path, "concatenated"))
dl.alt_save_object(_all_ranges, path=os.path.join(path, "concatenated"), **kwargs)

_elem_annotation = x.get_mcols()
if _elem_annotation is not None and _elem_annotation.shape[1] > 0:
dl.save_object(
dl.alt_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:
dl.save_object(_meta, path=os.path.join(path, "other_annotations"))
dl.alt_save_object(
_meta, path=os.path.join(path, "other_annotations"), **kwargs
)

return

0 comments on commit d457181

Please sign in to comment.