Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Oct 23, 2024
1 parent dfc8d65 commit 56fd31b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
1 change: 0 additions & 1 deletion src/rds2py/generics.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
"RangedSummarizedExperiment": "rds2py.parse_ranged_summarized_experiment",
# single-cell experiment
"SingleCellExperiment": "rds2py.parse_single_cell_experiment",

}


Expand Down
35 changes: 26 additions & 9 deletions src/rds2py/read_sce.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@


def parse_single_cell_experiment(robject: dict):
"""Parse an R object as
:py:class:`~singlecellexperiment.SingleCellExperiment.SingleCellExperiment`.
"""Parse an R object as :py:class:`~singlecellexperiment.SingleCellExperiment.SingleCellExperiment`.
Args:
robject:
Expand All @@ -24,33 +23,51 @@ def parse_single_cell_experiment(robject: dict):
_cls = get_class(robject)

if _cls not in ["SingleCellExperiment"]:
raise RuntimeError(f"`robject` does not contain a 'SingleCellExperiment' object, contains `{_cls}`.")
raise RuntimeError(
f"`robject` does not contain a 'SingleCellExperiment' object, contains `{_cls}`."
)

robject["class_name"] = "RangedSummarizedExperiment"
_rse = _dispatcher(robject)

# check red. dims, alternative expts
robj_reduced_dims = None
robj_altExps = None
col_attrs = _dispatcher(robject["attributes"]["int_colData"]["attributes"]["listData"]["attributes"]["names"])
col_attrs = _dispatcher(
robject["attributes"]["int_colData"]["attributes"]["listData"]["attributes"][
"names"
]
)

for idx in range(len(col_attrs)):
idx_col = col_attrs[idx]
idx_value = robject["attributes"]["int_colData"]["attributes"]["listData"]["data"][idx]
idx_value = robject["attributes"]["int_colData"]["attributes"]["listData"][
"data"
][idx]

if idx_col == "reducedDims" and idx_value["data"] is not None:
robj_reduced_dims = _dispatcher(robject["attributes"]["int_colData"]["attributes"]["listData"]["data"])
robj_reduced_dims = _dispatcher(
robject["attributes"]["int_colData"]["attributes"]["listData"]["data"]
)

if idx_col == "altExps":
alt_names = idx_value["attributes"]["listData"]["attributes"]["names"]["data"]
alt_names = idx_value["attributes"]["listData"]["attributes"]["names"][
"data"
]
robj_altExps = {}
for idx_alt_names in range(len(alt_names)):
altn = alt_names[idx_alt_names]

alt_key = list(idx_value["attributes"]["listData"]["data"][idx_alt_names]["attributes"].keys())[0]
alt_key = list(
idx_value["attributes"]["listData"]["data"][idx_alt_names][
"attributes"
].keys()
)[0]

robj_altExps[altn] = _dispatcher(
idx_value["attributes"]["listData"]["data"][idx_alt_names]["attributes"][alt_key]
idx_value["attributes"]["listData"]["data"][idx_alt_names][
"attributes"
][alt_key]
)

# ignore colpairs for now, does anyone even use this ?
Expand Down
2 changes: 1 addition & 1 deletion test.json
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
{'type': 'S4', 'package_name': 'SummarizedExperiment', 'class_name': 'SummarizedExperiment', 'attributes': {'colData': {'type': 'S4', 'package_name': 'S4Vectors', 'class_name': 'DFrame', 'attributes': {'rownames': {'type': 'string', 'data': ['A', 'B', 'C', 'D', 'E', 'F'], 'class_name': 'string_vector'}, 'nrows': {'type': 'integer', 'data': array([6], dtype=int32), 'attributes': {}, 'class_name': 'integer_vector'}, 'listData': {'type': 'vector', 'data': [{'type': 'string', 'data': ['ChIP', 'Input', 'ChIP', 'Input', 'ChIP', 'Input'], 'class_name': 'string_vector'}], 'attributes': {'names': {'type': 'string', 'data': ['Treatment'], 'class_name': 'string_vector'}}, 'class_name': 'vector'}, 'elementType': {'type': 'string', 'data': ['ANY'], 'class_name': 'string_vector'}, 'elementMetadata': {'type': 'other', 'data': None, 'attributes': None, 'class_name': None}, 'metadata': {'type': 'vector', 'data': [], 'attributes': {}, 'class_name': 'vector'}}}, 'elementMetadata': {'type': 'S4', 'package_name': 'S4Vectors', 'class_name': 'DFrame', 'attributes': {'rownames': {'type': 'other', 'data': None, 'attributes': None, 'class_name': None}, 'nrows': {'type': 'integer', 'data': array([200], dtype=int32), 'attributes': {}, 'class_name': 'integer_vector'}, 'listData': {'type': 'vector', 'data': [{'type': 'string', 'data': ['chr1', 'chr1', 'chr1', 'chr1', 'chr1', 'chr1', 'chr1', 'chr1', 'chr1', 'chr1', 'chr1', 'chr1', 'chr1', 'chr1', 'chr1', 'chr1', 'chr1', 'chr1', 'chr1', 'chr1', 'chr1', 'chr1', 'chr1', 'chr1', 'chr1', 'chr1', 'chr1', 'chr1', 'chr1', 'chr1', 'chr1', 'chr1', 'chr1', 'chr1', 'chr1', 'chr1', 'chr1', 'chr1', 'chr1', 'chr1', 'chr1', 'chr1', 'chr1', 'chr1', 'chr1', 'chr1', 'chr1', 'chr1', 'chr1', 'chr1', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2', 'chr2'], 'class_name': 'string_vector'}], 'attributes': {'names': {'type': 'string', 'data': ['seqs'], 'class_name': 'string_vector'}}, 'class_name': 'vector'}, 'elementType': {'type': 'string', 'data': ['ANY'], 'class_name': 'string_vector'}, 'elementMetadata': {'type': 'other', 'data': None, 'attributes': None, 'class_name': None}, 'metadata': {'type': 'vector', 'data': [], 'attributes': {}, 'class_name': 'vector'}}}, 'assays': {'type': 'S4', 'package_name': 'SummarizedExperiment', 'class_name': 'SimpleAssays', 'attributes': {'data': {'type': 'S4', 'package_name': 'S4Vectors', 'class_name': 'SimpleList', 'attributes': {'listData': {'type': 'vector', 'data': [{'type': 'double', 'data': array([5984.7896784 , 4351.34643709, 2763.82637297, ..., 20.0651535 ,
2590.73635628, 4687.51702976]), 'attributes': {'dim': {'type': 'integer', 'data': array([200, 6], dtype=int32), 'attributes': {}, 'class_name': 'integer_vector'}}, 'class_name': 'double_vector'}], 'attributes': {'names': {'type': 'string', 'data': ['counts'], 'class_name': 'string_vector'}}, 'class_name': 'vector'}, 'elementType': {'type': 'string', 'data': ['ANY'], 'class_name': 'string_vector'}, 'elementMetadata': {'type': 'other', 'data': None, 'attributes': None, 'class_name': None}, 'metadata': {'type': 'vector', 'data': [], 'attributes': {}, 'class_name': 'vector'}}}}}, 'NAMES': {'type': 'other', 'data': None, 'attributes': None, 'class_name': None}, 'metadata': {'type': 'vector', 'data': [], 'attributes': {}, 'class_name': 'vector'}}}
2590.73635628, 4687.51702976]), 'attributes': {'dim': {'type': 'integer', 'data': array([200, 6], dtype=int32), 'attributes': {}, 'class_name': 'integer_vector'}}, 'class_name': 'double_vector'}], 'attributes': {'names': {'type': 'string', 'data': ['counts'], 'class_name': 'string_vector'}}, 'class_name': 'vector'}, 'elementType': {'type': 'string', 'data': ['ANY'], 'class_name': 'string_vector'}, 'elementMetadata': {'type': 'other', 'data': None, 'attributes': None, 'class_name': None}, 'metadata': {'type': 'vector', 'data': [], 'attributes': {}, 'class_name': 'vector'}}}}}, 'NAMES': {'type': 'other', 'data': None, 'attributes': None, 'class_name': None}, 'metadata': {'type': 'vector', 'data': [], 'attributes': {}, 'class_name': 'vector'}}}

0 comments on commit 56fd31b

Please sign in to comment.