-
Notifications
You must be signed in to change notification settings - Fork 0
/
VCF_splitter.pl
56 lines (45 loc) · 1.21 KB
/
VCF_splitter.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/perl
#############################################################
### given a large vcf, extract the individuals wanted ###
### using their IDs ###
### INPUT: list of IDs ###
### STDIN: VCF file ###
### chris clarkson [email protected] ###
#############################################################
use strict;
use warnings;
use List::MoreUtils qw(first_index);
my $indvs = $ARGV[0];
open (INDVS, $indvs) || die "shit the bed";
my @allindv;
while (my $line = <INDVS>){
chomp($line);
push(@allindv, $line);
}
my @indexes;
while (my $line = <STDIN>){
if ($line =~ m/^\#\#/ ) {
print "$line";
}
if ($line =~ m/^\#CHROM/ ){
my @temp = split(/\t/ , $line);
foreach my $place (@allindv) {
push @indexes, first_index { $_ eq $place } @temp;
}
my @header = @temp[0..8];
print join("\t", @header);
print "\t";
print join("\t", @allindv);
print "\n";
}
if ($line =~ m/^2L|^2R|^3L|^3R|^X/) {
my @tempoo = split(/\t/ , $line);
my @columns = @tempoo[0..8];
my @chosen = @tempoo[@indexes[0..11]];
print join ("\t", @columns);
print "\t";
print join ("\t", @chosen);
print "\n";
}
}
close INDVS;