Skip to content

Commit

Permalink
parse strands for granges
Browse files Browse the repository at this point in the history
  • Loading branch information
jkanche committed Jul 14, 2024
1 parent 6a2923a commit 5377d5f
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions src/rds2py/granges.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,33 +36,29 @@ def as_granges(robj):

_seqnames = _as_list(robj["attributes"]["seqnames"])

_strand_obj = robj["attributes"]["strand"]["attributes"]["values"]
_strands = _strand_obj["data"]
_strands = robj["attributes"]["strand"]
_fstrand = None
if "attributes" in _strands:
if "levels" in _strands["attributes"]:
_levels_data = _strands["attributes"]["levels"]["data"]
_strands = [_levels_data[x] for x in _strands]
_lengths = _strands["attributes"]["lengths"]["data"]
_factors = _strands["attributes"]["values"]["data"]
_levels = _strands["attributes"]["values"]["attributes"]["levels"]["data"]
_strds = [_levels[x - 1] for x in _factors]
_fstrand = []
for i, x in enumerate(_lengths):
_fstrand.extend([_strds[i]] * x)

_seqinfo_seqnames = robj["attributes"]["seqinfo"]["attributes"]["seqnames"]["data"]
_seqinfo_seqlengths = robj["attributes"]["seqinfo"]["attributes"]["seqlengths"][
"data"
]
_seqinfo_is_circular = robj["attributes"]["seqinfo"]["attributes"]["is_circular"][
"data"
]
_seqinfo_seqlengths = robj["attributes"]["seqinfo"]["attributes"]["seqlengths"]["data"]
_seqinfo_is_circular = robj["attributes"]["seqinfo"]["attributes"]["is_circular"]["data"]
_seqinfo_genome = robj["attributes"]["seqinfo"]["attributes"]["genome"]["data"]
_seqinfo = SeqInfo(
seqnames=_seqinfo_seqnames,
seqlengths=[None if x == -2147483648 else int(x) for x in _seqinfo_seqlengths],
is_circular=[
None if x == -2147483648 else bool(x) for x in _seqinfo_is_circular
],
is_circular=[None if x == -2147483648 else bool(x) for x in _seqinfo_is_circular],
genome=_seqinfo_genome,
)

_mcols = BiocFrame.from_pandas(
as_pandas_from_dframe(robj["attributes"]["elementMetadata"])
)
_mcols = BiocFrame.from_pandas(as_pandas_from_dframe(robj["attributes"]["elementMetadata"]))

_gr_names = None
if "NAMES" in robj["attributes"]:
Expand All @@ -71,6 +67,7 @@ def as_granges(robj):
return GenomicRanges(
seqnames=_seqnames,
ranges=_ranges,
strand=_fstrand,
names=_gr_names,
mcols=_mcols,
seqinfo=_seqinfo,
Expand Down

0 comments on commit 5377d5f

Please sign in to comment.