Skip to content

[query] Refactor vds.sample_qc to use independent aggregators - #14297

Merged
danking merged 5 commits into
hail-is:mainfrom
chrisvittal:query/vds/sample-qc-refactor
Feb 27, 2024
Merged

danking merged 5 commits into
hail-is:mainfrom
chrisvittal:query/vds/sample-qc-refactor

Conversation

@chrisvittal

@chrisvittal chrisvittal commented Feb 15, 2024 •

Copy link
Copy Markdown
Collaborator

This will allow expert users to import these functions directly and use them in, for example, grouped aggregators.

from hail.vds.sample_qc import vmt_sample_qc, vmt_sample_qc_variant_annotations

vmt = vds.variant_data
vmt = vmt.annotate_entries(GT=hl.vds.lgt_to_gt(vmt.LGT, vmt.LA))
ac, atype = vmt_sample_qc_variant_annotations(global_gt=vmt.GT, alleles=vmt.alleles)
vmt = vmt.annotate_rows(group=compute_variant_group(vmt), ac=ac, atype=atype)
vmt = vmt.annotate_cols(
    qc=hl.agg.group_by(
        vmt.group,
        vmt_sample_qc(
            global_gt=vmt.GT,
            gq=vmt.GQ,
            ac=vmt.ac,
            atype=vmt.atype,
            dp=vmt.DP
        )
    )
)

@chrisvittal
chrisvittal force-pushed the query/vds/sample-qc-refactor branch from b79cd49 to da77a47 Compare February 15, 2024 07:19
@chrisvittal
chrisvittal marked this pull request as ready for review February 15, 2024 16:24
@chrisvittal
chrisvittal force-pushed the query/vds/sample-qc-refactor branch from 3b1982a to 9ca0dfb Compare February 15, 2024 16:26

@patrick-schultz patrick-schultz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Very straightforward. A few comments, but otherwise looks good.

Comment thread hail/python/hail/vds/sample_qc.py Resolved
Comment thread hail/python/hail/vds/sample_qc.py Resolved


@typecheck(global_gt=Expression, alleles=ArrayExpression)
def vmt_sample_qc_variant_annotations(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For both expert users and ourselves, can you add some minimal documentation for these auxiliary methods? I don't know if they should be linked in the docs or not, but they should at least have docstrings.

Comment thread hail/python/hail/vds/sample_qc.py Resolved
Dan King and others added 3 commits February 21, 2024 10:57
This will allow expert users to import these functions directly and use
them in, for example, grouped aggregators.

```python3
from hail.vds.sample_qc import vmt_sample_qc, vmt_sample_qc_variant_annotations

vmt = vds.variant_data
vmt = vmt.annotate_entries(GT=hl.vds.lgt_to_gt(vmt.LGT, vmt.LA))
ac_and_atype = _vmt_sample_qc_variant_annotations(global_gt=vmt.GT, alleles=vmt.alleles)
vmt = vmt.annotate_rows(group=compute_variant_group(vmt), **ac_and_atype)
vmt = vmt.annotate_cols(
    qc=hl.agg.group_by(
        vmt.group,
        vmt_sample_qc(
            global_gt=vmt.GT,
            gq=vmt.GQ,
            ac=vmt.ac,
            atype=vmt.atype,
            dp=vmt.DP
        )
    )
)
```
@chrisvittal
chrisvittal force-pushed the query/vds/sample-qc-refactor branch from 9ca0dfb to 28070c4 Compare February 21, 2024 15:57

@danking danking left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you expose allele_ints to users in some way? See the use-case here: https://hail.zulipchat.com/#narrow/stream/379853-Hail.2FVariants/topic/Echo.20VDS/near/423120704

@chrisvittal
chrisvittal dismissed danking’s stale review February 26, 2024 20:47

Out of scope, not this PR. Will do it though.

@patrick-schultz patrick-schultz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@danking
danking merged commit 4e4b3d7 into hail-is:main Feb 27, 2024
@chrisvittal chrisvittal linked an issue Feb 27, 2024 that may be closed by this pull request
@matren395

Copy link
Copy Markdown

Remarkable, thank you! Is this exposed in the most recent version of Hail , 0.2.128 ?

@patrick-schultz

Copy link
Copy Markdown
Member

No, but it will be included in the next release, which should be in the next week or two.

@matren395

Copy link
Copy Markdown

Hmmmm we were looking to merge a PR featuring this code a bit before then. We've been working from a copy of this function I had just Copy-Pasted out into some internal temp file called something like 'tmp_hail_methods' up until now, but I wouldn't want that temp file there when I merge.

if it's not unreasonable would it be possible to get this in some 0.2.128.1 wheel ?

@chrisvittal

Copy link
Copy Markdown
Collaborator Author

No, it will be in 0.2.129 release date currently unknown, but we think it will be early March.

@matren395

Copy link
Copy Markdown

Hi!!!

  • I was just delivered a wheel of Hail 0.2.128 loaded with this method from Chris, available at: gs://hail-30-day/hailctl/dataproc/cvittal-dev/0.2.128-2863e0eb192c/hail-0.2.128-py3-none-any.whl . Very helpful for removing those temp methods in the PR!

  • it looks like the code will have a home inside of something that looks like the following:

    qc = hl.struct(
        **{
            ann: hl.agg.filter(
                expr,
                vmt_sample_qc(
                    global_gt=vmt.GT,
                    gq=vmt.GQ,
                    variant_ac=vmt.variant_ac,
                    variant_atypes=vmt.variant_atypes,
                    dp=vmt.DP,
                ),
            )
            for ann, expr in argument_dictionary.items()
        }
    )

inside of a hl.agg.filter call, and where argument_dictionary looks like {'vep_name':ht.vep.field , "pass_all_vqc": hl.len(vmt.filters) == 0} and so on. Just to give an idea what the usage is going to be.

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.

[query] Feature Request: hl.vds.sample_qc_agg

4 participants