forked from johnomics/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse_rad_bd_data.pl
executable file
·54 lines (46 loc) · 1.35 KB
/
parse_rad_bd_data.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/env perl
use strict;
use warnings;
use Carp;
use English;
use Getopt::Long;
use Pod::Usage;
use Data::Dumper;
use Memoize;
use Parallel::ForkManager;
use Term::ExtendedColor qw/:all/;
use List::Util qw/min max/;
$OUTPUT_AUTOFLUSH = 1;
open my $vcf, '<', "/whale-data/jd626/edinburgh/isilon/heliconius/scaffolding/PstI/PstI.Hmel_primaryScaffs_NoMito_Yb-scaff.pass1.vcf" or croak "Can't open VCF file";
my %markers;
while (my $vcfline = <$vcf>) {
if ($vcfline =~ /^scf7180001249824/) {
chomp $vcfline;
my @F = split /\t/, $vcfline;
my $scf = $F[0];
my $pos = $F[1];
my $f0gm = $F[-3];
my $f1mo = $F[-2];
my $f1fa = $F[-1];
my @pgts = map {(split /:/, $_)[0]} ($f0gm, $f1mo, $f1fa);
my %pgts;
map {$pgts{$_}++} @pgts;
next if defined $pgts{'./.'};
next if keys %pgts == 1;
my $pgt = "@pgts";
my @ogts = map {(split /:/, $_)[0]} @F[9..($#F-3)];
$markers{$pgt}{$pos}="@ogts";
}
}
close $vcf;
for my $pgt (keys %markers) {
for my $pos (sort {$a<=>$b} keys %{$markers{$pgt}}) {
print gts_to_pattern($pgt);
print "\t$pos\t";
print gts_to_pattern($markers{$pgt}{$pos});
print "\n";
}
}
sub gts_to_pattern {
return map {$_ eq '0/0' ? 'A' : $_ eq '0/1' ? 'H' : $_ eq '1/1' ? 'B' : '-'} split / /, shift;
}