SingleCellExperiment 0.5.4__tar.gz → 0.5.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. {singlecellexperiment-0.5.4 → singlecellexperiment-0.5.6}/CHANGELOG.md +9 -1
  2. {singlecellexperiment-0.5.4 → singlecellexperiment-0.5.6}/PKG-INFO +1 -1
  3. {singlecellexperiment-0.5.4 → singlecellexperiment-0.5.6}/docs/changelog.md +9 -1
  4. {singlecellexperiment-0.5.4 → singlecellexperiment-0.5.6}/src/SingleCellExperiment.egg-info/PKG-INFO +1 -1
  5. {singlecellexperiment-0.5.4 → singlecellexperiment-0.5.6}/src/singlecellexperiment/SingleCellExperiment.py +97 -30
  6. {singlecellexperiment-0.5.4 → singlecellexperiment-0.5.6}/tests/test_sce.py +29 -0
  7. {singlecellexperiment-0.5.4 → singlecellexperiment-0.5.6}/.coveragerc +0 -0
  8. {singlecellexperiment-0.5.4 → singlecellexperiment-0.5.6}/.github/workflows/publish-pypi.yml +0 -0
  9. {singlecellexperiment-0.5.4 → singlecellexperiment-0.5.6}/.github/workflows/run-tests.yml +0 -0
  10. {singlecellexperiment-0.5.4 → singlecellexperiment-0.5.6}/.gitignore +0 -0
  11. {singlecellexperiment-0.5.4 → singlecellexperiment-0.5.6}/.pre-commit-config.yaml +0 -0
  12. {singlecellexperiment-0.5.4 → singlecellexperiment-0.5.6}/.readthedocs.yml +0 -0
  13. {singlecellexperiment-0.5.4 → singlecellexperiment-0.5.6}/AUTHORS.md +0 -0
  14. {singlecellexperiment-0.5.4 → singlecellexperiment-0.5.6}/CONTRIBUTING.md +0 -0
  15. {singlecellexperiment-0.5.4 → singlecellexperiment-0.5.6}/LICENSE.txt +0 -0
  16. {singlecellexperiment-0.5.4 → singlecellexperiment-0.5.6}/README.md +0 -0
  17. {singlecellexperiment-0.5.4 → singlecellexperiment-0.5.6}/docs/Makefile +0 -0
  18. {singlecellexperiment-0.5.4 → singlecellexperiment-0.5.6}/docs/_static/.gitignore +0 -0
  19. {singlecellexperiment-0.5.4 → singlecellexperiment-0.5.6}/docs/authors.md +0 -0
  20. {singlecellexperiment-0.5.4 → singlecellexperiment-0.5.6}/docs/conf.py +0 -0
  21. {singlecellexperiment-0.5.4 → singlecellexperiment-0.5.6}/docs/contributing.md +0 -0
  22. {singlecellexperiment-0.5.4 → singlecellexperiment-0.5.6}/docs/index.md +0 -0
  23. {singlecellexperiment-0.5.4 → singlecellexperiment-0.5.6}/docs/license.md +0 -0
  24. {singlecellexperiment-0.5.4 → singlecellexperiment-0.5.6}/docs/readme.md +0 -0
  25. {singlecellexperiment-0.5.4 → singlecellexperiment-0.5.6}/docs/requirements.txt +0 -0
  26. {singlecellexperiment-0.5.4 → singlecellexperiment-0.5.6}/docs/tutorial.md +0 -0
  27. {singlecellexperiment-0.5.4 → singlecellexperiment-0.5.6}/pyproject.toml +0 -0
  28. {singlecellexperiment-0.5.4 → singlecellexperiment-0.5.6}/setup.cfg +0 -0
  29. {singlecellexperiment-0.5.4 → singlecellexperiment-0.5.6}/setup.py +0 -0
  30. {singlecellexperiment-0.5.4 → singlecellexperiment-0.5.6}/src/SingleCellExperiment.egg-info/SOURCES.txt +0 -0
  31. {singlecellexperiment-0.5.4 → singlecellexperiment-0.5.6}/src/SingleCellExperiment.egg-info/dependency_links.txt +0 -0
  32. {singlecellexperiment-0.5.4 → singlecellexperiment-0.5.6}/src/SingleCellExperiment.egg-info/not-zip-safe +0 -0
  33. {singlecellexperiment-0.5.4 → singlecellexperiment-0.5.6}/src/SingleCellExperiment.egg-info/requires.txt +0 -0
  34. {singlecellexperiment-0.5.4 → singlecellexperiment-0.5.6}/src/SingleCellExperiment.egg-info/top_level.txt +0 -0
  35. {singlecellexperiment-0.5.4 → singlecellexperiment-0.5.6}/src/singlecellexperiment/__init__.py +0 -0
  36. {singlecellexperiment-0.5.4 → singlecellexperiment-0.5.6}/src/singlecellexperiment/_combineutils.py +0 -0
  37. {singlecellexperiment-0.5.4 → singlecellexperiment-0.5.6}/src/singlecellexperiment/_ioutils.py +0 -0
  38. {singlecellexperiment-0.5.4 → singlecellexperiment-0.5.6}/src/singlecellexperiment/io/__init__.py +0 -0
  39. {singlecellexperiment-0.5.4 → singlecellexperiment-0.5.6}/src/singlecellexperiment/io/h5ad.py +0 -0
  40. {singlecellexperiment-0.5.4 → singlecellexperiment-0.5.6}/src/singlecellexperiment/io/tenx.py +0 -0
  41. {singlecellexperiment-0.5.4 → singlecellexperiment-0.5.6}/tests/conftest.py +0 -0
  42. {singlecellexperiment-0.5.4 → singlecellexperiment-0.5.6}/tests/data/adata.h5ad +0 -0
  43. {singlecellexperiment-0.5.4 → singlecellexperiment-0.5.6}/tests/data/mocks.py +0 -0
  44. {singlecellexperiment-0.5.4 → singlecellexperiment-0.5.6}/tests/data/tenx.sub.h5 +0 -0
  45. {singlecellexperiment-0.5.4 → singlecellexperiment-0.5.6}/tests/test_sce_combine_cols.py +0 -0
  46. {singlecellexperiment-0.5.4 → singlecellexperiment-0.5.6}/tests/test_sce_combine_rows.py +0 -0
  47. {singlecellexperiment-0.5.4 → singlecellexperiment-0.5.6}/tests/test_sce_io.py +0 -0
  48. {singlecellexperiment-0.5.4 → singlecellexperiment-0.5.6}/tests/test_sce_methods.py +0 -0
  49. {singlecellexperiment-0.5.4 → singlecellexperiment-0.5.6}/tests/test_sce_slice.py +0 -0
  50. {singlecellexperiment-0.5.4 → singlecellexperiment-0.5.6}/tox.ini +0 -0
@@ -1,6 +1,14 @@
1
1
  # Changelog
2
2
 
3
- ## Version 0.5.1 - 0.5.3
3
+ ## Version 0.5.6
4
+
5
+ - Check if the column names of the alternative experiments match with the column names of the main experiment. This is the equivalent to the ``withDimnames`` parameter in the R implementation.
6
+ - On **getters** of alternative experiments, if `with_dim_names` is True, column names of the alternative experiment are **replaced** with the
7
+ column names of the main experiment.
8
+ - On **setters** of alternative experiments, if `with_dim_names` is True, column names of the alternative experiment are **checked** with the
9
+ column names of the main experiment and an Exception is raised if they do not match.
10
+
11
+ ## Version 0.5.1 - 0.5.5
4
12
 
5
13
  - Add wrapper class methods to combine experiments by rows or columns.
6
14
  - Expand function names for readability, still backwards compatible with the older function and method names.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: SingleCellExperiment
3
- Version: 0.5.4
3
+ Version: 0.5.6
4
4
  Summary: Container class for single-cell experiments
5
5
  Home-page: https://github.com/BiocPy/SingleCellExperiment
6
6
  Author: jkanche
@@ -1,6 +1,14 @@
1
1
  # Changelog
2
2
 
3
- ## Version 0.5.1 - 0.5.3
3
+ ## Version 0.5.6
4
+
5
+ - Check if the column names of the alternative experiments match with the column names of the main experiment. This is the equivalent to the ``withDimnames`` parameter in the R implementation.
6
+ - On **getters** of alternative experiments, if `with_dim_names` is True, column names of the alternative experiment are **replaced** with the
7
+ column names of the main experiment.
8
+ - On **setters** of alternative experiments, if `with_dim_names` is True, column names of the alternative experiment are **checked** with the
9
+ column names of the main experiment and an Exception is raised if they do not match.
10
+
11
+ ## Version 0.5.1 - 0.5.5
4
12
 
5
13
  - Add wrapper class methods to combine experiments by rows or columns.
6
14
  - Expand function names for readability, still backwards compatible with the older function and method names.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: SingleCellExperiment
3
- Version: 0.5.4
3
+ Version: 0.5.6
4
4
  Summary: Container class for single-cell experiments
5
5
  Home-page: https://github.com/BiocPy/SingleCellExperiment
6
6
  Author: jkanche
@@ -45,7 +45,7 @@ def _validate_reduced_dims(reduced_dims, shape):
45
45
  raise ValueError(f"Reduced dimension: '{rdname}' does not contain embeddings for all cells.")
46
46
 
47
47
 
48
- def _validate_alternative_experiments(alternative_experiments, shape):
48
+ def _validate_alternative_experiments(alternative_experiments, shape, column_names, with_dim_names=True):
49
49
  if alternative_experiments is None:
50
50
  raise ValueError("'alternative_experiments' cannot be `None`, must be assigned to an empty dictionary.")
51
51
 
@@ -62,6 +62,15 @@ def _validate_alternative_experiments(alternative_experiments, shape):
62
62
  if shape[1] != alternative_experiment.shape[1]:
63
63
  raise ValueError(f"Alternative experiment: '{alt_name}' does not contain same number of" " cells.")
64
64
 
65
+ _alt_cnames = alternative_experiment.get_column_names()
66
+ _alt_cnames = None if _alt_cnames is None else list(_alt_cnames)
67
+ if _alt_cnames is not None:
68
+ if list(column_names) != _alt_cnames:
69
+ if with_dim_names:
70
+ raise Exception(f"Column names do not match for alternative_experiment: {alt_name}")
71
+ else:
72
+ warn(f"Column names do not match for alternative_experiment: {alt_name}", UserWarning)
73
+
65
74
 
66
75
  def _validate_pairs(pairs):
67
76
  if pairs is not None:
@@ -102,6 +111,7 @@ class SingleCellExperiment(RangedSummarizedExperiment):
102
111
  alternative_experiments: Optional[Dict[str, Any]] = None,
103
112
  row_pairs: Optional[Any] = None,
104
113
  column_pairs: Optional[Any] = None,
114
+ alternative_experiment_check_dim_names: bool = True,
105
115
  validate: bool = True,
106
116
  ) -> None:
107
117
  """Initialize a single-cell experiment.
@@ -166,6 +176,13 @@ class SingleCellExperiment(RangedSummarizedExperiment):
166
176
  (e.g., sc-atac, crispr) and values as subclasses of
167
177
  :py:class:`~summarizedexperiment.SummarizedExperiment.SummarizedExperiment`.
168
178
 
179
+ alternative_experiment_check_dim_names:
180
+ Whether to check if the column names of the alternative experiment match the column names
181
+ of the main experiment. This is the equivalent to the ``withDimnames``
182
+ parameter in the R implementation.
183
+
184
+ Defaults to True.
185
+
169
186
  row_pairs:
170
187
  Row pairings/relationships between features.
171
188
 
@@ -201,7 +218,12 @@ class SingleCellExperiment(RangedSummarizedExperiment):
201
218
 
202
219
  if validate:
203
220
  _validate_reduced_dims(self._reduced_dims, self._shape)
204
- _validate_alternative_experiments(self._alternative_experiments, self._shape)
221
+ _validate_alternative_experiments(
222
+ self._alternative_experiments,
223
+ self._shape,
224
+ self.get_column_names(),
225
+ with_dim_names=alternative_experiment_check_dim_names,
226
+ )
205
227
  _validate_pairs(self._row_pairs)
206
228
  _validate_pairs(self._column_pairs)
207
229
 
@@ -605,17 +627,28 @@ class SingleCellExperiment(RangedSummarizedExperiment):
605
627
  ######>> alternative_experiments <<######
606
628
  #########################################
607
629
 
608
- def get_alternative_experiments(self) -> Dict[str, Any]:
630
+ def get_alternative_experiments(self, with_dim_names: bool = True) -> Dict[str, Any]:
609
631
  """Access alternative experiments.
610
632
 
633
+ Args:
634
+ with_dim_names:
635
+ Whether to replace the column names of the alternative experiment with the column names
636
+ of the main experiment. This is the equivalent to the ``withDimnames``
637
+ parameter in the R implementation.
638
+
639
+ Defaults to True.
640
+
611
641
  Returns:
612
- A dictionary with names of
613
- the experiments as keys and value the experiment.
642
+ A dictionary with experiment names as keys and value the alternative experiment.
614
643
  """
615
- return self._alternative_experiments
644
+ _out = OrderedDict()
645
+ for name in self.get_alternative_experiment_names():
646
+ _out[name] = self.get_alternative_experiment(name, with_dim_names=with_dim_names)
647
+
648
+ return _out
616
649
 
617
650
  def set_alternative_experiments(
618
- self, alternative_experiments: Dict[str, Any], in_place: bool = False
651
+ self, alternative_experiments: Dict[str, Any], with_dim_names: bool = True, in_place: bool = False
619
652
  ) -> "SingleCellExperiment":
620
653
  """Set new alternative experiments.
621
654
 
@@ -623,6 +656,13 @@ class SingleCellExperiment(RangedSummarizedExperiment):
623
656
  alternative_experiments:
624
657
  New alternative experiments.
625
658
 
659
+ with_dim_names:
660
+ Whether to check if the column names of the alternative experiment match the column names
661
+ of the main experiment. This is the equivalent to the ``withDimnames``
662
+ parameter in the R implementation.
663
+
664
+ Defaults to True.
665
+
626
666
  in_place:
627
667
  Whether to modify the ``SingleCellExperiment`` in place.
628
668
 
@@ -630,7 +670,9 @@ class SingleCellExperiment(RangedSummarizedExperiment):
630
670
  A modified ``SingleCellExperiment`` object, either as a copy of the original
631
671
  or as a reference to the (in-place-modified) original.
632
672
  """
633
- _validate_alternative_experiments(alternative_experiments, self.shape)
673
+ _validate_alternative_experiments(
674
+ alternative_experiments, self.shape, self.get_column_names(), with_dim_names=with_dim_names
675
+ )
634
676
  output = self._define_output(in_place)
635
677
  output._alternative_experiments = alternative_experiments
636
678
  return output
@@ -705,13 +747,20 @@ class SingleCellExperiment(RangedSummarizedExperiment):
705
747
  ######>> alternative_experiment getter <<######
706
748
  ###############################################
707
749
 
708
- def get_alternative_experiment(self, name: Union[str, int]) -> Any:
750
+ def get_alternative_experiment(self, name: Union[str, int], with_dim_names: bool = True) -> Any:
709
751
  """Access alternative experiment by name.
710
752
 
711
753
  Args:
712
754
  name:
713
755
  Name or index position of the alternative experiment.
714
756
 
757
+ with_dim_names:
758
+ Whether to replace the column names of the alternative experiment with the column names
759
+ of the main experiment. This is the equivalent to the ``withDimnames``
760
+ parameter in the R implementation.
761
+
762
+ Defaults to True.
763
+
715
764
  Raises:
716
765
  AttributeError:
717
766
  If the dimension name does not exist.
@@ -721,6 +770,8 @@ class SingleCellExperiment(RangedSummarizedExperiment):
721
770
  Returns:
722
771
  The alternative experiment.
723
772
  """
773
+ _out = None
774
+
724
775
  if isinstance(name, int):
725
776
  if name < 0:
726
777
  raise IndexError("Index cannot be negative.")
@@ -728,21 +779,26 @@ class SingleCellExperiment(RangedSummarizedExperiment):
728
779
  if name > len(self.alternative_experiment_names):
729
780
  raise IndexError("Index greater than the number of alternative experiments.")
730
781
 
731
- return self._alternative_experiments[self.alternative_experiment_names[name]]
782
+ _out = self._alternative_experiments[self.alternative_experiment_names[name]]
732
783
  elif isinstance(name, str):
733
784
  if name not in self._alternative_experiments:
734
785
  raise AttributeError(f"Alternative experiment: {name} does not exist.")
735
786
 
736
- return self._alternative_experiments[name]
787
+ _out = self._alternative_experiments[name]
788
+ else:
789
+ raise TypeError(f"'name' must be a string or integer, provided '{type(name)}'.")
737
790
 
738
- raise TypeError(f"'name' must be a string or integer, provided '{type(name)}'.")
791
+ if with_dim_names:
792
+ _out = _out.set_column_names(self.get_column_names())
793
+
794
+ return _out
739
795
 
740
796
  def alternative_experiment(self, name: Union[str, int]) -> Any:
741
797
  """Alias for :py:meth:`~get_alternative_experiment`, for back-compatibility."""
742
798
  return self.get_alternative_experiment(name=name)
743
799
 
744
800
  def set_alternative_experiment(
745
- self, name: str, alternative_experiment: Any, in_place: bool = False
801
+ self, name: str, alternative_experiment: Any, with_dim_names: bool = True, in_place: bool = False
746
802
  ) -> "SingleCellExperiment":
747
803
  """Add or replace :py:attr:`~singlecellexperiment.SingleCellExperiment.alternative_experiment`'s.
748
804
 
@@ -755,6 +811,13 @@ class SingleCellExperiment(RangedSummarizedExperiment):
755
811
  Is a subclasses of
756
812
  :py:class:`~summarizedexperiment.SummarizedExperiment.SummarizedExperiment`.
757
813
 
814
+ with_dim_names:
815
+ Whether to check if the column names of the alternative experiment match the column names
816
+ of the main experiment. This is the equivalent to the ``withDimnames``
817
+ parameter in the R implementation.
818
+
819
+ Defaults to True.
820
+
758
821
  in_place:
759
822
  Whether to modify the ``SingleCellExperiment`` in place.
760
823
 
@@ -769,7 +832,9 @@ class SingleCellExperiment(RangedSummarizedExperiment):
769
832
  _tmp_alt_expt = _tmp_alt_expt.copy()
770
833
  _tmp_alt_expt[name] = alternative_experiment
771
834
 
772
- _validate_alternative_experiments(_tmp_alt_expt, self._shape)
835
+ _validate_alternative_experiments(
836
+ _tmp_alt_expt, self._shape, self.get_column_names(), with_dim_names=with_dim_names
837
+ )
773
838
  output._alternative_experiments = _tmp_alt_expt
774
839
  return output
775
840
 
@@ -1058,22 +1123,24 @@ class SingleCellExperiment(RangedSummarizedExperiment):
1058
1123
  )
1059
1124
 
1060
1125
  if self.reduced_dims is not None:
1061
- mat = self._reduced_dims
1062
- if isinstance(mat, DelayedArray) or issubclass(type(mat), DelayedArray):
1063
- if is_sparse(mat):
1064
- warn(
1065
- "Converting delayedarray into sparse, may require more memory",
1066
- RuntimeWarning,
1067
- )
1068
-
1069
- mat = to_scipy_sparse_matrix(mat)
1070
- else:
1071
- warn(
1072
- "Converting delayedarray into dense, may require more memory",
1073
- RuntimeWarning,
1074
- )
1075
- mat = to_dense_array(mat)
1076
- obj.obsm = mat
1126
+ nrdims_ = OrderedDict()
1127
+ for dim, mat in self._reduced_dims.items():
1128
+ if isinstance(mat, DelayedArray) or issubclass(type(mat), DelayedArray):
1129
+ if is_sparse(mat):
1130
+ warn(
1131
+ "Converting delayedarray into sparse, may require more memory",
1132
+ RuntimeWarning,
1133
+ )
1134
+
1135
+ mat = to_scipy_sparse_matrix(mat)
1136
+ else:
1137
+ warn(
1138
+ "Converting delayedarray into dense, may require more memory",
1139
+ RuntimeWarning,
1140
+ )
1141
+ mat = to_dense_array(mat)
1142
+ nrdims_[dim] = mat
1143
+ obj.obsm = nrdims_
1077
1144
 
1078
1145
  if self.row_pairs is not None:
1079
1146
  obj.varp = self.row_pairs
@@ -143,3 +143,32 @@ def test_SCE_creation_modifications():
143
143
 
144
144
  tse.set_reduced_dimension("something", np.random.rand(tse.shape[1], 4), in_place=True)
145
145
  assert nassay_tse.get_reduced_dimension_names() == tse.get_reduced_dimension_names()
146
+
147
+ def test_SCE_different_alt_names():
148
+ rse = SummarizedExperiment(
149
+ assays={"counts": counts}, row_data=row_data, column_data=pd.DataFrame(index = ["ChIP"] * 6 )
150
+ )
151
+
152
+ with pytest.raises(Exception):
153
+ tse = SingleCellExperiment(
154
+ assays={"counts": counts},
155
+ row_data=row_data,
156
+ column_data=col_data,
157
+ alternative_experiments={"alt": rse},
158
+ )
159
+
160
+ with pytest.raises(Exception):
161
+ tse = SingleCellExperiment(
162
+ assays={"counts": counts},
163
+ row_data=row_data,
164
+ column_data=pd.DataFrame(index = ["ChIP", "Input"] * 3),
165
+ alternative_experiments={"alt": rse},
166
+ )
167
+
168
+ with pytest.raises(Exception):
169
+ tse = SingleCellExperiment(
170
+ assays={"counts": counts},
171
+ row_data=row_data,
172
+ column_data=pd.DataFrame(index = ["ChIP", "Input", "Input"] * 2),
173
+ alternative_experiments={"alt": rse},
174
+ )