Skip to content
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

Update uns to precomp stats to take a list as parameter #21

Open
wants to merge 4 commits into
base: rc/v1.4.0
Choose a base branch
from

Conversation

inkarkapen
Copy link
Collaborator

No description provided.

Copy link
Collaborator

@danielsf danielsf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of this looks good. I'm confused though: doesn't your use case also require an update to precomputed_stats_to_uns so that the cell_type_mapper code can save the precomputed stats file to the nested key structure in your scrattch .h5ad files?

Also: some unit tests in

tests/diff_exp/test_precompute.py

are now failing. There are calls to uns_to_precomputed_stats that need to be updated. The offending test is

test_serialization_of_actual_precomputed_stats

(sorry I forgot to call that out to you earlier). This is where the code actually tests that a precomputed stats file that is serialized to uns is unchanged from its source data. In addition to updated the function calls in this test, I think it would be a good idea to change the test logic itself so that it tries to save the precomputed_stats data to a nested key structure in uns, rather than the current flat key structure. This will involve the change to precomputed_stats_to_uns I implicitly requested above (unless you do not need precomputed_stats_to_uns changed....?)

tmp_dir=tmp_dir_fixture)
else:
a_data = anndata.read_h5ad(h5ad_path)
a_data.uns[uns_key] = {uns_key_nested: a_data.uns[uns_key]}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just being paranoid:

The way this code is constructed, the file at h5ad_path still has the expected data at [uns_key] which means that, even if uns_to_precomputed_stats were not modified, the test would still pass, I think.

Can you write a new anndata object at a different location that only has the expected data at your nested location. I am imagining something like this:

new_h5ad_path = mkstemp_clean(dir=tmp_dir_fixture, suffix='.h5ad')
src = anndata.read_h5ad(h5ad_path)
new_data = anndata.AnnData(
    obs=src.obs,
    var=src.var,
    X=src.X[()],
    uns = {uns_key_nested: {uns_key: {src.uns[uns_key]}}}
)
new_data.write_h5ad(new_h5ad_path)
h5ad_path = new_h5ad_path

@@ -555,7 +555,7 @@ def precomputed_stats_to_uns(

def uns_to_precomputed_stats(
h5ad_path,
uns_key,
uns_keys_list,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the docstring to reflect the new argument.

@@ -317,3 +319,24 @@ def aggregate_stats(
result[k] = result[k].astype(new_dtype)

return result


def _read_cluster_to_row(cluster_row_lookup):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a unit test for this function. I know it's trivial, I just want to make sure that this is actually solving the problem we want it to solve.

@danielsf
Copy link
Collaborator

danielsf commented Sep 5, 2024

@inkarkapen

Just pinging to ask you what you think the state of this PR is/should be. Is it no longer needed? Shall I just close without merging?

@danielsf danielsf changed the base branch from main to rc/v1.4.0 November 4, 2024 17:39
@danielsf
Copy link
Collaborator

danielsf commented Nov 4, 2024

I have redirected this PR to rc/v1.4.0. I've been adding a lot of features lately, both to support my own and others' use cases. rc/v1.4.0 will be the next tagged release of the code.

We can worry about rebasing the PR onto this branch once it is ready to merge.

@danielsf danielsf force-pushed the rc/v1.4.0 branch 3 times, most recently from e32d6d5 to 5ead218 Compare December 4, 2024 20:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants