VCF header line counting
2
1
Entering edit mode
9.8 years ago
basalganglia ▴ 40

Hello happy bioinformaticians :)

It can be a very simple question but I want to ask that how can I count line (row) of header of VCF ?

I can be done manually but I want to get accurate result.

Thanks,
BG

vcf header • 7.9k views
ADD COMMENT
10
Entering edit mode
9.8 years ago
Coryza ▴ 430

Simply count the number of rows starting with a #:

grep -c '^#' <vcf>

If you want to count the number of sequence headers:

grep -c '##contig' <vcf>

And even more.. if you want to count the number of non-headers:

grep -c '^[^#]' <vcf>

On the command line of course ;)

ADD COMMENT
5
Entering edit mode

The grep command will read the entire file, so if your VCF file is very large, something like this will run faster:

sed -n '/^[^#]/q;p' <vcf> | wc -l
ADD REPLY
0
Entering edit mode

Thanks it was so helpful !!!

ADD REPLY
0
Entering edit mode

Thanks !! :)

ADD REPLY
0
Entering edit mode

Please accept Coryza's answer if it was helpful, otherwise give them feedback on why it did not address your problem.

ADD REPLY
2
Entering edit mode
18 months ago
beausoleilmo ▴ 600

I think this would be the fastest

bcftools view --header-only <vcf> | wc -l
ADD COMMENT

Login before adding your answer.

Traffic: 2381 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6