From 1cbbd2c5a1cdeca0a185e5133f7b81f294334af3 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 25 Oct 2024 19:23:25 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- setup.py | 5 +---- src/rds2py/PyRdsReader.py | 16 +++------------- src/rds2py/rdsutils.py | 4 +--- src/rds2py/read_dict.py | 4 +--- src/rds2py/read_factor.py | 4 +--- src/rds2py/read_granges.py | 20 +++++--------------- src/rds2py/read_mae.py | 4 +--- src/rds2py/read_matrix.py | 5 +---- src/rds2py/read_rle.py | 4 +--- src/rds2py/read_sce.py | 28 ++++++---------------------- src/rds2py/read_se.py | 24 ++++++------------------ 11 files changed, 27 insertions(+), 91 deletions(-) diff --git a/setup.py b/setup.py index 8649f6a..f495462 100644 --- a/setup.py +++ b/setup.py @@ -38,10 +38,7 @@ def build_cmake(self, ext): "lib", "-B", build_temp, - "-Dpybind11_DIR=" - + os.path.join( - os.path.dirname(pybind11.__file__), "share", "cmake", "pybind11" - ), + "-Dpybind11_DIR=" + os.path.join(os.path.dirname(pybind11.__file__), "share", "cmake", "pybind11"), "-DPYTHON_EXECUTABLE=" + sys.executable, ] if os.name != "nt": diff --git a/src/rds2py/PyRdsReader.py b/src/rds2py/PyRdsReader.py index fabdcfc..23592ad 100644 --- a/src/rds2py/PyRdsReader.py +++ b/src/rds2py/PyRdsReader.py @@ -71,9 +71,7 @@ def _process_object(self, obj: RdsReader) -> Dict[str, Any]: except Exception as e: raise PyRdsParserError(f"Error processing object: {str(e)}") - def _handle_r_special_cases( - self, data: np.ndarray, rtype: str, size: int - ) -> Union[np.ndarray, range]: + def _handle_r_special_cases(self, data: np.ndarray, rtype: str, size: int) -> Union[np.ndarray, range]: """Handle special R data representations.""" try: # Special handling for R integer containing NA @@ -82,12 +80,7 @@ def _handle_r_special_cases( return np.array([np.nan if x == self.R_MIN else x for x in data]) # Special handling for R integer sequences - if ( - rtype == "integer" - and size == 2 - and data[0] == self.R_MIN - and data[1] < 0 - ): + if rtype == "integer" and size == 2 and data[0] == self.R_MIN and data[1] < 0: if data[1] == self.R_MIN: return [None, None] return range(data[1] * -1) @@ -106,10 +99,7 @@ def _get_numeric_data(self, obj: RdsReader, rtype: str) -> np.ndarray: raise PyRdsParserError(f"Error getting numeric data: {str(e)}") def _process_vector(self, obj: RdsReader) -> List[Dict[str, Any]]: - return [ - self._process_object(obj.load_vec_element(i)) - for i in range(obj.get_rsize()) - ] + return [self._process_object(obj.load_vec_element(i)) for i in range(obj.get_rsize())] def _process_attributes(self, obj: RdsReader) -> Dict[str, Dict[str, Any]]: try: diff --git a/src/rds2py/rdsutils.py b/src/rds2py/rdsutils.py index e73942c..ea1f6f5 100644 --- a/src/rds2py/rdsutils.py +++ b/src/rds2py/rdsutils.py @@ -37,9 +37,7 @@ def get_class(robj: dict) -> str: if "class_name" in robj: _inferred_cls_name = robj["class_name"] if _inferred_cls_name is not None and ( - "integer" in _inferred_cls_name - or "double" in _inferred_cls_name - or _inferred_cls_name == "vector" + "integer" in _inferred_cls_name or "double" in _inferred_cls_name or _inferred_cls_name == "vector" ): if "attributes" in robj: obj_attr = robj["attributes"] diff --git a/src/rds2py/read_dict.py b/src/rds2py/read_dict.py index f63831b..0b583fb 100644 --- a/src/rds2py/read_dict.py +++ b/src/rds2py/read_dict.py @@ -10,9 +10,7 @@ def parse_vector(robject: dict): _cls = get_class(robject) if _cls not in ["vector"]: - raise RuntimeError( - f"`robject` does not contain not a vector/dictionary object, contains `{_cls}`." - ) + raise RuntimeError(f"`robject` does not contain not a vector/dictionary object, contains `{_cls}`.") if "names" not in robject["attributes"]: return [_dispatcher(x) for x in robject["data"]] diff --git a/src/rds2py/read_factor.py b/src/rds2py/read_factor.py index f2d732c..39426c9 100644 --- a/src/rds2py/read_factor.py +++ b/src/rds2py/read_factor.py @@ -10,9 +10,7 @@ def parse_factor(robject: dict): _cls = get_class(robject) if _cls not in ["factor"]: - raise RuntimeError( - f"`robject` does not contain not a factor object, contains `{_cls}`." - ) + raise RuntimeError(f"`robject` does not contain not a factor object, contains `{_cls}`.") data = robject["data"] diff --git a/src/rds2py/read_granges.py b/src/rds2py/read_granges.py index 7e60c54..fb20ef5 100644 --- a/src/rds2py/read_granges.py +++ b/src/rds2py/read_granges.py @@ -39,18 +39,10 @@ def parse_genomic_ranges(robject): _strands = _dispatcher(robject["attributes"]["strand"]) _seqnames = _dispatcher(robject["attributes"]["seqnames"]) - _seqinfo_seqnames = _dispatcher( - robject["attributes"]["seqinfo"]["attributes"]["seqnames"] - ) - _seqinfo_seqlengths = _dispatcher( - robject["attributes"]["seqinfo"]["attributes"]["seqlengths"] - ) - _seqinfo_is_circular = _dispatcher( - robject["attributes"]["seqinfo"]["attributes"]["is_circular"] - ) - _seqinfo_genome = _dispatcher( - robject["attributes"]["seqinfo"]["attributes"]["genome"] - ) + _seqinfo_seqnames = _dispatcher(robject["attributes"]["seqinfo"]["attributes"]["seqnames"]) + _seqinfo_seqlengths = _dispatcher(robject["attributes"]["seqinfo"]["attributes"]["seqlengths"]) + _seqinfo_is_circular = _dispatcher(robject["attributes"]["seqinfo"]["attributes"]["is_circular"]) + _seqinfo_genome = _dispatcher(robject["attributes"]["seqinfo"]["attributes"]["genome"]) _seqinfo = SeqInfo( seqnames=_seqinfo_seqnames, seqlengths=_seqinfo_seqlengths, @@ -99,9 +91,7 @@ def parse_granges_list(robject): _tmp_names = robject["attributes"]["partitioning"]["attributes"]["NAMES"] _groups = None if _tmp_names is None else _dispatcher(_tmp_names) - _partitionends = _dispatcher( - robject["attributes"]["partitioning"]["attributes"]["end"] - ) + _partitionends = _dispatcher(robject["attributes"]["partitioning"]["attributes"]["end"]) _grelist = [] diff --git a/src/rds2py/read_mae.py b/src/rds2py/read_mae.py index 510ac16..f555621 100644 --- a/src/rds2py/read_mae.py +++ b/src/rds2py/read_mae.py @@ -44,9 +44,7 @@ def parse_multi_assay_experiment(robject: dict): _cls = get_class(robject) if _cls not in ["MultiAssayExperiment"]: - raise RuntimeError( - f"`robject` does not contain a 'MultiAssayExperiment' object, contains `{_cls}`." - ) + raise RuntimeError(f"`robject` does not contain a 'MultiAssayExperiment' object, contains `{_cls}`.") # parse experiment names _expt_obj = robject["attributes"]["ExperimentList"]["attributes"]["listData"] diff --git a/src/rds2py/read_matrix.py b/src/rds2py/read_matrix.py index ca4a81a..c08d222 100644 --- a/src/rds2py/read_matrix.py +++ b/src/rds2py/read_matrix.py @@ -35,9 +35,7 @@ def _as_sparse_matrix(robject: dict): _cls = get_class(robject) if _cls not in ["dgCMatrix", "dgRMatrix", "dgTMatrix"]: - raise RuntimeError( - f"`robject` does not contain not a supported sparse matrix format, contains `{_cls}`." - ) + raise RuntimeError(f"`robject` does not contain not a supported sparse matrix format, contains `{_cls}`.") if _cls == "dgCMatrix": mat = csc_matrix( @@ -98,7 +96,6 @@ def _as_dense_matrix(robject, order: Literal["C", "F"] = "F"): """ _cls = get_class(robject) - if order not in ["C", "F"]: raise ValueError("order must be either 'C' or 'F'.") diff --git a/src/rds2py/read_rle.py b/src/rds2py/read_rle.py index a6bafc7..32f1fbd 100644 --- a/src/rds2py/read_rle.py +++ b/src/rds2py/read_rle.py @@ -20,9 +20,7 @@ def parse_rle(robject: dict): _cls = get_class(robject) if _cls != "Rle": - raise RuntimeError( - f"`robject` does not contain a 'Rle' object, contains `{_cls}`." - ) + raise RuntimeError(f"`robject` does not contain a 'Rle' object, contains `{_cls}`.") data = list(_dispatcher(robject["attributes"]["values"])) diff --git a/src/rds2py/read_sce.py b/src/rds2py/read_sce.py index 8a3ce02..e0692bb 100644 --- a/src/rds2py/read_sce.py +++ b/src/rds2py/read_sce.py @@ -10,9 +10,7 @@ def parse_alts_summarized_experiment_by_column(robject: dict): _cls = get_class(robject) if _cls not in ["SummarizedExperimentByColumn"]: - raise RuntimeError( - f"`robject` does not contain a 'SummarizedExperimentByColumn' object, contains `{_cls}`." - ) + raise RuntimeError(f"`robject` does not contain a 'SummarizedExperimentByColumn' object, contains `{_cls}`.") objs = {} @@ -39,9 +37,7 @@ 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) @@ -49,32 +45,20 @@ def parse_single_cell_experiment(robject: dict): # check red. dims, alternative expts robj_reduced_dims = None robj_alt_exps = None - col_attrs = list( - _dispatcher( - robject["attributes"]["int_colData"]["attributes"]["listData"][ - "attributes" - ]["names"] - ) - ) + col_attrs = list(_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.get("data", None) is not None: robj_reduced_dims = _dispatcher(idx_value) if idx_col == "altExps": - alt_names = list( - _dispatcher(idx_value["attributes"]["listData"]["attributes"]["names"]) - ) + alt_names = list(_dispatcher(idx_value["attributes"]["listData"]["attributes"]["names"])) robj_alt_exps = {} for idx, altn in enumerate(alt_names): - robj_alt_exps[altn] = _dispatcher( - idx_value["attributes"]["listData"]["data"][idx] - )["se"] + robj_alt_exps[altn] = _dispatcher(idx_value["attributes"]["listData"]["data"][idx])["se"] # ignore colpairs for now, does anyone even use this ? # if col == "colPairs": diff --git a/src/rds2py/read_se.py b/src/rds2py/read_se.py index 08b58cd..96d4050 100644 --- a/src/rds2py/read_se.py +++ b/src/rds2py/read_se.py @@ -43,37 +43,27 @@ def parse_summarized_experiment(robject: dict): _cls = get_class(robject) if _cls not in ["SummarizedExperiment"]: - raise RuntimeError( - f"`robject` does not contain a 'SummarizedExperiment' object, contains `{_cls}`." - ) + raise RuntimeError(f"`robject` does not contain a 'SummarizedExperiment' object, contains `{_cls}`.") # parse assays names robj_asys = {} assay_dims = None asy_names = list( _dispatcher( - robject["attributes"]["assays"]["attributes"]["data"]["attributes"][ - "listData" - ]["attributes"]["names"] + robject["attributes"]["assays"]["attributes"]["data"]["attributes"]["listData"]["attributes"]["names"] ) ) for idx, asyname in enumerate(asy_names): - idx_asy = robject["attributes"]["assays"]["attributes"]["data"]["attributes"][ - "listData" - ]["data"][idx] + idx_asy = robject["attributes"]["assays"]["attributes"]["data"]["attributes"]["listData"]["data"][idx] robj_asys[asyname] = _dispatcher(idx_asy) if assay_dims is None: assay_dims = robj_asys[asyname].shape # parse coldata - robj_coldata = _sanitize_empty_frame( - _dispatcher(robject["attributes"]["colData"]), assay_dims[1] - ) + robj_coldata = _sanitize_empty_frame(_dispatcher(robject["attributes"]["colData"]), assay_dims[1]) # parse rowdata - robj_rowdata = _sanitize_empty_frame( - _dispatcher(robject["attributes"]["elementMetadata"]), assay_dims[0] - ) + robj_rowdata = _sanitize_empty_frame(_dispatcher(robject["attributes"]["elementMetadata"]), assay_dims[0]) return SummarizedExperiment( assays=_sanitize_assays(robj_asys), @@ -99,9 +89,7 @@ def parse_ranged_summarized_experiment(robject: dict): _cls = get_class(robject) if _cls not in ["RangedSummarizedExperiment"]: - raise RuntimeError( - f"`robject` does not contain a 'RangedSummarizedExperiment' object, contains `{_cls}`." - ) + raise RuntimeError(f"`robject` does not contain a 'RangedSummarizedExperiment' object, contains `{_cls}`.") robject["class_name"] = "SummarizedExperiment" _se = _dispatcher(robject)