<?xml version='1.0'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:atom="http://www.w3.org/2005/Atom" >
<channel>
	<title><![CDATA[BOL: Perl script to parse VCF file !]]></title>
	<link>https://bioinformaticsonline.com/snippets/view/44457/perl-script-to-parse-vcf-file?</link>
	<atom:link href="https://bioinformaticsonline.com/snippets/view/44457/perl-script-to-parse-vcf-file?" rel="self" type="application/rss+xml" />
	<description><![CDATA[]]></description>
	
	<item>
	<guid isPermaLink="true">https://bioinformaticsonline.com/snippets/view/44457/perl-script-to-parse-vcf-file</guid>
	<pubDate>Thu, 01 Feb 2024 02:08:11 -0600</pubDate>
	<link>https://bioinformaticsonline.com/snippets/view/44457/perl-script-to-parse-vcf-file</link>
	<title><![CDATA[Perl script to parse VCF file !]]></title>
	<description><![CDATA[<code>#!/usr/bin/perl

use strict;
use warnings;

# Usage: ./parse_vcf.pl input.vcf

die &quot;Usage: ./parse_vcf.pl input.vcf\n&quot; unless @ARGV;

my $vcf_file = shift @ARGV;
my @vcf_entries = parse_vcf($vcf_file);

print &quot;Total entries: &quot;, scalar(@vcf_entries), &quot;\n&quot;;
print &quot;---------------------------\n&quot;;

my %chromosome_counts;
for my $entry (@vcf_entries) {
    $chromosome_counts{$entry-&gt;{CHROM}}++;
}

print &quot;Chromosome counts:\n&quot;;
for my $chromosome (sort keys %chromosome_counts) {
    print &quot;  $chromosome: $chromosome_counts{$chromosome}\n&quot;;
}

sub parse_vcf {
    my ($file) = @_;

    open my $fh, &#039;&lt;&#039;, $file or die &quot;Cannot open file $file: $!\n&quot;;

    my @entries;

    while (my $line = &lt;$fh&gt;) {
        next if $line =~ /^\s*$/;  # skip empty lines
        next if $line =~ /^\s*#/; # skip comments

        chomp $line;
        my @fields = split /\t/, $line;

        my %entry;
        @entry{qw/CHROM POS ID REF ALT QUAL FILTER INFO FORMAT SAMPLES/} = @fields;

        push @entries, \%entry;
    }

    close $fh;

    return @entries;
}</code>]]></description>
	<dc:creator>LEGE</dc:creator>
</item>

</channel>
</rss>