Skip to content

Commit

Permalink
decode feature and barcode information from h5 as ascii (#14)
Browse files Browse the repository at this point in the history
in addition switch `__str__` with `__repr__`
  • Loading branch information
jkanche authored Sep 11, 2023
1 parent 43c5f9f commit e11aed7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions src/singlecellexperiment/SingleCellExperiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,15 +414,15 @@ def col_pairs(self, pairs: MutableMapping[str, MatrixTypesWithFrame]):
self._validate_pairs(pairs)
self._col_pairs = pairs

def __str__(self) -> str:
def __repr__(self) -> str:
pattern = (
f"Class SingleCellExperiment with {self.shape[0]} features and {self.shape[1]} cells \n"
f" main_experiment_name: {self.main_experiment_name if self.main_experiment_name is not None else None} \n"
f" assays: {list(self.assays.keys())} \n"
f" features: {self.row_data.columns if self.row_data is not None else None} \n"
f" cell annotations: {self.col_data.columns if self.col_data is not None else None} \n"
f" reduced dimensions: {self.reduced_dim_names if self.reduced_dims is not None else None} \n"
f" alternative experiments: {list(self.alternative_experiments.keys()) if self.alternative_experiments is not None else None}" # noqa: E501
f" row_data: {self.row_data.columns if self.row_data is not None else None} \n"
f" col_data: {self.col_data.columns if self.col_data is not None else None} \n"
f" reduced_dims: {self.reduced_dim_names if self.reduced_dims is not None else None} \n"
f" alternative_experiments: {list(self.alternative_experiments.keys()) if self.alternative_experiments is not None else None}" # noqa: E501
)
return pattern

Expand Down
4 changes: 2 additions & 2 deletions src/singlecellexperiment/io/tenx.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ def read_tenx_h5(path: str) -> SingleCellExperiment:
if "features" in groups:
features = pd.DataFrame()
for key, val in h5["matrix"]["features"].items():
features[key] = val[:]
features[key] = [x.decode("ascii") for x in val[:]]

barcodes = None
if "barcodes" in groups:
barcodes = pd.DataFrame()
barcodes["barcodes"] = h5["matrix"]["barcodes"][:]
barcodes["barcodes"] = [x.decode("ascii") for x in h5["matrix"]["barcodes"][:]]

return SingleCellExperiment(
assays={"counts": counts}, row_data=features, col_data=barcodes
Expand Down

0 comments on commit e11aed7

Please sign in to comment.