Last active
December 17, 2016 01:03
-
-
Save sestaton/d9de56fe1b3b0e78208ff515cbe796d8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use 5.010; | |
use strict; | |
use warnings; | |
use autodie; | |
use List::MoreUtils qw(indexes); | |
my $usage = "$0 ids vcf"; | |
my $ids = shift or die $usage; | |
my $vcf = shift or die $usage; | |
open my $iin, '<', $ids; | |
my %h = map { chomp; s/^\s+|\s+$//; $_ => 1 } <$iin>; | |
close $iin; | |
open my $vin, '<', $vcf; | |
my @indexes; | |
while (my $line = <$vin>) { | |
chomp $line; | |
next if $line =~ /^##/; | |
my @f = split /\s+/, $line; | |
if ($f[0] eq '#CHROM') { | |
for my $k (keys %h) { | |
push @indexes, indexes { $_ =~ /$k/ } @f; | |
} | |
} | |
if (@indexes) { | |
say join "\t", @f[0..8,@indexes]; | |
} | |
else { | |
say "No genotypes from $ids found in $vcf."; | |
last; | |
} | |
} | |
close $vin; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment