-
Notifications
You must be signed in to change notification settings - Fork 1
add sample_key kwarg, changed sample_key and batch_key logic #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -934,6 +934,7 @@ def __init__( | |
| batch_size: int | None = None, | ||
| gene_likelihood: str | None = None, | ||
| check_val_every_n_epoch: int | None = None, | ||
| sample_key: str | None = None, | ||
| **kwargs, | ||
| ): | ||
| """ | ||
|
|
@@ -979,6 +980,8 @@ def __init__( | |
| Likelihood, nb, zinb or poisson, see scvi docs. | ||
| check_val_every_n_epoch | ||
| Check validation loss every n epochs. | ||
| sample_key | ||
| Key in adata.obs indicating different slices/sections. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Docstring should also state what |
||
| """ | ||
| super().__init__( | ||
| adata, | ||
|
|
@@ -998,6 +1001,7 @@ def __init__( | |
| batch_size=batch_size, | ||
| gene_likelihood=gene_likelihood, | ||
| check_val_every_n_epoch=check_val_every_n_epoch, | ||
| sample_key=sample_key, | ||
| **kwargs, | ||
| ) | ||
|
|
||
|
|
@@ -1018,6 +1022,7 @@ def __init__( | |
| self.batch_size = batch_size | ||
| self.gene_likelihood = gene_likelihood | ||
| self.check_val_every_n_epoch = check_val_every_n_epoch | ||
| self.sample_key = sample_key | ||
|
|
||
| # Initialize models | ||
| self.embedding_model = None | ||
|
|
@@ -1035,9 +1040,11 @@ def setup(self, expression_embedding_key: str, force_recompute: bool = False) -> | |
| adata_prepared = self._prepare_hvg() | ||
|
|
||
| # Prepare preprocessing parameters, filtering out None values for k_nn only | ||
| # preprocessing_params are passed to preprocessing_anndata and setup_anndata | ||
| # as described in the tutorial | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Per Once the default behavior is settled, please add a |
||
| preprocessing_params = { | ||
| "adata": adata_prepared, | ||
| "sample_key": self.batch_key, | ||
| "sample_key": self.sample_key, | ||
| "labels_key": self.cell_type_key, | ||
| "cell_coordinates_key": self.spatial_key, | ||
| "expression_embedding_key": expression_embedding_key, | ||
|
|
@@ -1125,7 +1132,7 @@ def fit(self): | |
| adata_hvg, | ||
| layer=self.counts_layer, | ||
| batch_key=self.batch_key, | ||
| sample_key=self.batch_key, | ||
| sample_key=self.sample_key, # like slice_key in ResolVI | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Two small things on this line:
|
||
| labels_key=self.cell_type_key, | ||
| cell_coordinates_key=self.spatial_key, | ||
| expression_embedding_key=expression_embedding_key, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Behavior break vs. main. Previously
sample_keywas implicitlyself.batch_key; now it defaults toNone, which propagates through toscvi.external.SCVIVA.setup_anndata(sample_key=None)and raisesKeyError: None(this is what's failing in CI for all threetest_scviva_methodparametrizations andtest_embedding_retrieval[method_config4]).Two reasonable options:
Preserve old default — keep the kwarg, but fall back to
batch_keywhenNone:This way existing users keep working; new users can override.
Make
sample_keyrequired-ish — keepNonedefault but raise a clear error infit()/setup()if it's stillNoneat use time, and update the existingtest_scviva_methodto passsample_key="batch"explicitly. Document the change as breaking in the PR body / CHANGELOG.Either is fine, but the current state silently breaks every existing caller.