[docs]defread_summarized_experiment(robject:dict,**kwargs)->SummarizedExperiment:"""Convert an R SummarizedExperiment to Python :py:class:`~summarizedexperiment.SummarizedExperiment.SummarizedExperiment`. Args: robject: Dictionary containing parsed SummarizedExperiment data. **kwargs: Additional arguments. Returns: A `SummarizedExperiment` from the R object. """_cls=get_class(robject)if_clsnotin["SummarizedExperiment"]:raiseRuntimeError(f"`robject` does not contain a 'SummarizedExperiment' object, contains `{_cls}`.")# parse assays namesrobj_asys={}assay_dims=Noneasy_names=list(_dispatcher(robject["attributes"]["assays"]["attributes"]["data"]["attributes"]["listData"]["attributes"]["names"],**kwargs,))foridx,asynameinenumerate(asy_names):idx_asy=robject["attributes"]["assays"]["attributes"]["data"]["attributes"]["listData"]["data"][idx]robj_asys[asyname]=_dispatcher(idx_asy,**kwargs)ifassay_dimsisNone:assay_dims=robj_asys[asyname].shape# parse coldatarobj_coldata=_sanitize_empty_frame(_dispatcher(robject["attributes"]["colData"],**kwargs),assay_dims[1])# parse rowdatarobj_rowdata=_sanitize_empty_frame(_dispatcher(robject["attributes"]["elementMetadata"],**kwargs),assay_dims[0])returnSummarizedExperiment(assays=_sanitize_assays(robj_asys),row_data=robj_rowdata,column_data=robj_coldata,)
[docs]defread_ranged_summarized_experiment(robject:dict,**kwargs)->RangedSummarizedExperiment:"""Convert an R RangedSummarizedExperiment to its Python equivalent. Args: robject: Dictionary containing parsed SummarizedExperiment data. **kwargs: Additional arguments. Returns: A Python RangedSummarizedExperiment object. """_cls=get_class(robject)if_clsnotin["RangedSummarizedExperiment"]:raiseRuntimeError(f"`robject` does not contain a 'RangedSummarizedExperiment' object, contains `{_cls}`.")robject["class_name"]="SummarizedExperiment"_se=_dispatcher(robject,**kwargs)# parse rowRangesrow_ranges_data=Noneif"rowRanges"inrobject["attributes"]:row_ranges_data=_dispatcher(robject["attributes"]["rowRanges"],**kwargs)returnRangedSummarizedExperiment(assays=_se.assays,row_data=_se.row_data,column_data=_se.column_data,row_ranges=row_ranges_data,)