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 25, 2024
1 parent cb4fd8c commit 1cbbd2c
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 91 deletions.
5 changes: 1 addition & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
16 changes: 3 additions & 13 deletions src/rds2py/PyRdsReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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:
Expand Down
4 changes: 1 addition & 3 deletions src/rds2py/rdsutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
4 changes: 1 addition & 3 deletions src/rds2py/read_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]]
Expand Down
4 changes: 1 addition & 3 deletions src/rds2py/read_factor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
20 changes: 5 additions & 15 deletions src/rds2py/read_granges.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 = []

Expand Down
4 changes: 1 addition & 3 deletions src/rds2py/read_mae.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
5 changes: 1 addition & 4 deletions src/rds2py/read_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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'.")

Expand Down
4 changes: 1 addition & 3 deletions src/rds2py/read_rle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]))

Expand Down
28 changes: 6 additions & 22 deletions src/rds2py/read_sce.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}

Expand All @@ -39,42 +37,28 @@ 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_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":
Expand Down
24 changes: 6 additions & 18 deletions src/rds2py/read_se.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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)
Expand Down

0 comments on commit 1cbbd2c

Please sign in to comment.