]> git.donarmstrong.com Git - bin.git/blobdiff - vcf_rs_grep
add reset usb bus command
[bin.git] / vcf_rs_grep
index 8021b036b41cc6e235a1b20852a3a9e32941e953..4c89281f037abea871e4209f95f92c52a94bca0f 100755 (executable)
@@ -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 (<STDIN>) {
     $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__