Skip to content

Commit

Permalink
Merge branch 'rewrite' of https://github.com/BiocPy/rds2py into rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
jkanche committed Oct 24, 2024
2 parents 6ab9a69 + 56fd31b commit b0aeada
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 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
25 changes: 18 additions & 7 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,7 +23,9 @@ 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)
Expand All @@ -36,21 +37,31 @@ def parse_single_cell_experiment(robject: dict):

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(idx_value)

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 b0aeada

Please sign in to comment.