2 # vcf_rs_grep greps RS from a VCF file
3 # and is released under the terms of the GNU GPL version 3, or any
4 # later version, at your option. See the file README and COPYING for
6 # Copyright 2017 by Don Armstrong <don@donarmstrong.com>.
17 vcf_rs_grep - greps RS from a VCF file
21 vcf_rs_grep [options] vcf_file.gz < rs_list |gzip -c > vcf_greped.gz
24 --debug, -d debugging level (Default 0)
25 --help, -h display this help
26 --man, -m display manual
34 Debug verbosity. (Default 0)
38 Display brief usage information.
48 vcf_rs_grep vcf_file.gz < rs_list |gzip -c > vcf_greped.gz
55 my %options = (debug => 0,
61 'debug|d+','help|h|?','man|m');
63 pod2usage() if $options{help};
64 pod2usage({verbose=>2}) if $options{man};
66 $DEBUG = $options{debug};
70 push @USAGE_ERRORS,"You must provide exactly one VCF file to read";
73 pod2usage(join("\n",@USAGE_ERRORS)) if @USAGE_ERRORS;
76 sub open_compressed_file {
79 my $mode = '<:encoding(UTF-8)';
81 if ($file =~ /\.gz$/) {
82 $mode = '-|:encoding(UTF-8)';
83 push @opts,'gzip','-dc';
85 if ($file =~ /\.xz$/) {
86 $mode = '-|:encoding(UTF-8)';
87 push @opts,'xz','-dc';
89 if ($file =~ /\.bz2$/) {
90 $mode = '-|:encoding(UTF-8)';
91 push @opts,'bzip2','-dc';
93 open($fh,$mode,@opts,$file);
97 my $vcf = open_compressed_file($ARGV[0]) or
98 die "Unable to open file $ARGV[0]";
111 $_ =~ /^\S+\s+\S+\s+(\S+)/o;
113 next unless exists $rsids{$1} and $rsids{$1};