X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=vcf_rs_grep;h=4c89281f037abea871e4209f95f92c52a94bca0f;hb=56c8d8b286ae38e170ce915472f9aa86fabf9fee;hp=8021b036b41cc6e235a1b20852a3a9e32941e953;hpb=73807809b5938fd4961e5e14ab181829691c17b8;p=bin.git diff --git a/vcf_rs_grep b/vcf_rs_grep index 8021b03..4c89281 100755 --- a/vcf_rs_grep +++ b/vcf_rs_grep @@ -58,6 +58,7 @@ my %options = (debug => 0, ); GetOptions(\%options, + 'merge=s', 'debug|d+','help|h|?','man|m'); pod2usage() if $options{help}; @@ -103,6 +104,20 @@ while () { $rsids{$_} = 1; } +my %merge_rsids; +if (defined $options{merge}) { + my $merge = open_compressed_file($options{merge}) + or die "Unable to open file $options{merge}: $!"; + while (<$merge>) { + chomp; + my ($old,$new,undef) = split /\t/; + next unless exists $rsids{'rs'.$old}; + $merge_rsids{'rs'.$old} = 'rs'.$new; + $rsids{'rs'.$new} = 1; + } + close ($merge); +} + while (<$vcf>) { if (/^#/o) { print $_; @@ -111,7 +126,20 @@ while (<$vcf>) { $_ =~ /^\S+\s+\S+\s+(\S+)/o; next unless $1; next unless exists $rsids{$1} and $rsids{$1}; + $rsids{$1}++; print $_; } +my @unused_rsids; +for my $rsid (keys %rsids) { + if ($rsids{$rsid} == 1) { + push @unused_rsids,$rsid; + } +} +if (@unused_rsids) { + print STDERR "The following rsids were not found\n"; + print STDERR map {$_."\n"} @unused_rsids; +} + + __END__