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

Adding a custom value for missing annotation #116

Closed
edg1983 opened this issue Nov 28, 2019 · 9 comments
Closed

Adding a custom value for missing annotation #116

edg1983 opened this issue Nov 28, 2019 · 9 comments

Comments

@edg1983
Copy link

edg1983 commented Nov 28, 2019

Hi bred!

I have a suggestion for your already amazing vcfanno.

When annotating AF from an external file (gnomAD for example) it would be more convenient to have the annotation field set to zero for variants not found in gnomAD VCF.
In this way, one can simply filter for rare variant doing gnomAD_AF < 0.01 for example

In general, it would be great to have the possibility to specify in the toml configuration file how to annotate variants when they are not found in the annotation source, so one can decide to leave them un-annotated (as it is right now) or adding a value (like zero for AF annotation or some custom value for other kinds of annotations).

@wm75
Copy link

wm75 commented Nov 28, 2019

hmm, that reminds me of a question I always forget asking:
if I'm not mistaken, gnomAD has 0 values for AF already. What's the difference between an actual AF=0 and a variant without information. Are the zero ones rounded down from really small AFs or is it something else?

@brentp
Copy link
Owner

brentp commented Nov 28, 2019

Hi, I think you can do this with a [[postannotation]] that takes your annotated value and returns -1 if it's undefined and the value if it is defined.

@edg1983
Copy link
Author

edg1983 commented Nov 28, 2019

I will try with the post annotation as you suggested. Thanks!

@brentp
Copy link
Owner

brentp commented Dec 1, 2019

@wm75 so variants were discovered in the cohort, but then filtered/QC-ed somehow so they have an AF of 0. there is no rounding.

@wm75
Copy link

wm75 commented Dec 2, 2019

@brentp Thanks for the clarification!

@edg1983
Copy link
Author

edg1983 commented Apr 15, 2020

Hi brent,
I'm still trying to implement this correctly, but it seems I can not find the right recipe.
Can you give me an example of how to configure a lua script and post-annotation to fill in missing annotations with a custom value as you suggested before?

I'm performing annotation with some exome AF. When a variant in my VCF is not present in the cohort_exome.vcf I want to set -1 for exome_af. So I have configured annotations as follows

[[annotation]]
file="cohort_exome.vcf.gz"
fields=["AF","nhomalt"]
ops=["self","self"]
names=["exome_af","exome_nhomalts"]

[[postannotation]]
fields=["exome_af"]
op="lua:checkaf(exome_af)"
name="exome_af"
type="Float"

Then I've prepared a custom.lua file as follows

function checkaf(v)
  local output = v
  if (v == nil) then output = -1 end
  return output
end

However, vcfanno gives me warning that the exome_af field do not exist in INFO and the -1 value is not inserted.

@brentp brentp closed this as completed in 9f857a9 Apr 15, 2020
@brentp
Copy link
Owner

brentp commented Apr 15, 2020

well, that should have worked, but it didn't. I just pushed a fix for this and added something like your example as a test-case. thanks for the clear example.
here is a linux binary with the fix.
vcfanno_dev.gz

@edg1983
Copy link
Author

edg1983 commented Apr 16, 2020

Hi brent,

Thanks for the quick fix! It works perfectly now.
Just in case someone wants to replicate my approach, I've noticed that the previous version of my lua script replace missing values, but causes values already present to be outputted between square brackets like this

exome_af=[0.323]

So to obtain the desired result the lua script I've used is:

function checkaf(v)
  if (v == nil) then 
    output = -1
  else
    output = v[1]
  end  
  return output
end

@brentp
Copy link
Owner

brentp commented Apr 16, 2020

you can also use table.concat if you want to join the values into a string.

liserjrqlxue added a commit to liserjrqlxue/vcfanno that referenced this issue Sep 9, 2020
handle missing value in postannotation. closes brentp#116
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

No branches or pull requests

3 participants