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

Count the number of alleles at each site #3580

Open
iris-garden opened this issue May 6, 2024 · 0 comments
Open

Count the number of alleles at each site #3580

iris-garden opened this issue May 6, 2024 · 0 comments
Labels
discourse migrated from discuss.hail.is

Comments

@iris-garden
Copy link
Owner

Note

The following post was exported from discuss.hail.is, a forum for asking questions about Hail which has since been deprecated.

(Jan 03, 2024 at 20:51) alee9 said:

Hi All,

I would like to add a row-wise annotation (info field) to my matrix table called ‘NAL’ that contains the number of alleles at a site (the length of the alleles array).

I have attempted to achieve this using the command
mt = mt.annotate_rows(info=mt.info.annotate(NAL=mt.alleles.aggregate(hl.agg.count())))

However, this results in the following error

Traceback (most recent call last):
  File "/home/alee9/.local/lib/python3.10/site-packages/hail/typecheck/check.py", line 594, in arg_check
    return checker.check(arg, function_name, arg_name)
  File "/home/alee9/.local/lib/python3.10/site-packages/hail/typecheck/check.py", line 359, in check
    raise TypecheckFailure
hail.typecheck.check.TypecheckFailure

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<decorator-gen-572>", line 2, in aggregate
  File "/home/alee9/.local/lib/python3.10/site-packages/hail/typecheck/check.py", line 586, in wrapper
    args_, kwargs_ = check_all(__original_func, args, kwargs, checkers, is_method=is_method)
  File "/home/alee9/.local/lib/python3.10/site-packages/hail/typecheck/check.py", line 551, in check_all
    args_.append(arg_check(args[i], name, arg_name, checker))
  File "/home/alee9/.local/lib/python3.10/site-packages/hail/typecheck/check.py", line 596, in arg_check
    raise TypeError("{fname}: parameter '{argname}': "
TypeError: aggregate: parameter 'f': expected 1-argument function, found hail.expr.expressions.typed_expressions.Int64Expression: <Int64Expression of type int64>

I suspect that the command that I am using is not correct and would be grateful for any help in constructing the correct command.

Thanks in advance

(Jan 04, 2024 at 06:35) Benjamin_Blankenmeis said:

I’d maybe try something like:

mt = mt.annotate_rows(info=mt.info.annotate(NAL=hl.len(mt.alleles)))

mt.alleles is usually a row field, so you actually don’t need to perform an aggregation over the samples/columns.

(Jan 04, 2024 at 08:54) alee9 said:

Hi Benjamin, thanks for your swift reply. It works perfectly, and gives exactly what I wanted.

@iris-garden iris-garden added the discourse migrated from discuss.hail.is label May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discourse migrated from discuss.hail.is
Projects
None yet
Development

No branches or pull requests

1 participant