This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Remove Single Info Field From Vcf

What's the quickest way to remove a single INFO field from a VCF file? Don't care what framework - vcftools, pyvcf, whatever. Just want a one liner to do this.

In this case, I just want to remove the ensembl CSQ field so I can annotate again

vcf

3 answers

The below python function takes a vcf line (non-header) and will return a line without CSQ field. Good luck~

def removeCSQ(line):
        values = line.split()
        INFO = values[7]
        NEWINFO = []
        for info in INFO.split(";"):
                if not "CSQ=" in info:
                        NEWINFO.append(info)
        values[7] = ";".join(NEWINFO)
        return "\t".join(values)

Using RTG Tools:

rtg vcfsubset -i in.vcf -o out.vcf --remove-info CSQ

Use vt package

vt rminfo in.vcf -t CSQ -o out.vcf

Log in to answer this question.