brentp / vcfanno

annotate a VCF with other VCFs/BEDs/tabixed files
https://genomebiology.biomedcentral.com/articles/10.1186/s13059-016-0973-5
MIT License
357 stars 55 forks source link

Errors with postannotate #122

Closed huangk3 closed 4 years ago

huangk3 commented 4 years ago

Hi @brentp

I tried to add a tag through checking if a field contains a substring but got the following error:

api.go:691: ERROR: in lua postannotation at 21:27543049 for in_omim.
<string>:56: bad argument #1 to find (string expected, got nil)
stack traceback:
        [G]: in function 'find'
        <string>:56: in function 'contains'
        <string>:128: in main chunk
        (tailcall): ?
        [G]: ?
empty values were: []
values were: [MedGen:CN043596]
code is: check_in_omim(clinvar_disease_databas...

The lua looks like:

function check_in_omim(clinvar_disease_database)
    if contains(clinvar_disease_database, "OMIM") then
        return true
    end
    return false
end

the conf looks like:

[[postannotation]]
fields=["clinvar_disease_database"]
op="lua:check_in_omim(clinvar_disease_database[1])"
name="in_omim"
type="Flag"

The vcf looks like:

21      27543049        rs459543        C       G       4385.7  PASS    AC=6;AF=0.019;AN=264;BaseQRankSum=0.037;ClippingRankSum=0.161;DB;DP=5036;ExcessHet=3.4144;FS=14.045;InbreedingCoeff=-0.0341;MLEAC=6;MLEAF=0.023;MQ=60;MQRankSum=0.415;POSITIVE_TRAIN_SITE;QD=14.38;ReadPosRankSum=0.521;SOR=0.787;VQSLOD=16.88;culprit=FS;hetAltAB=0.5049;gerp_element_pval=0;clinvar_pathogenic=Likely_benign;clinvar_disease_name=Early-Onset_Familial_Alzheimer_Disease;clinvar_disease_database=MedGen:CN043596  GT:AD:DP:GQ:PL  0/0:52,0:52:99:0,114,1710

I want to add "in_omim=1" if the 'clinvar_disease_database' contains 'OMIM' or "in_omim=0" otherwise. Take the variant above as an example, 'in_omim=0' should be added but I got the error as mentioned in the beginning. Thanks!

brentp commented 4 years ago

are you source a lua file that has the definition for contains? This works for me:

function contains(str, tok)
    return string.find(str, tok) ~= nil
end

function check_in_omim(arg)
    return arg ~= nil and contains(arg, "OMIM")
end

--print(check_in_omim())
--print(check_in_omim("XXXOMIM"))
huangk3 commented 4 years ago

Yeah, it works. Thanks @brentp