3 Author: Hu Xuesong @ BIOPIC <galaxy001@gmail.com>
4 Version: 1.0.0 @ 20120720
5 Purpose: Read bcf, get tped for p-link
6 Notes: rad2marker is deprecated.
10 use Data
::Dump
qw(ddx);
15 die "Usage: $0 <tped prefix> [out].chrID.inp\n" if @ARGV<1;
18 unless (defined $outfs) {
19 warn "Using prefix[$prefix] for both input and output.\n";
22 warn "From [$prefix] to [$outfs]\n";
24 my (@Positions,%HapDat,@IDs,@IDab);
25 open I
,'<',$prefix or die "Error opening $prefix : $!\n";
27 if (/^Positions of loci: /) {
28 @Positions = split /\s+/,$_;
29 splice @Positions,0,3;
31 if (/^BEGIN BESTPAIRS1/) {
33 last if /^END BESTPAIRS1/;
35 my $id = (split /\s/,$_)[1];
38 my @basesA = split /\s+/,$_;
40 my @basesB = split /\s+/,$_;
41 for my $base (@basesA,@basesB) {
42 if ($base =~ /^\((\w)\)$/) {
46 $base = '.'.lc($1) if ($base =~ /^\[(\w)\]$/);
51 $HapDat{$id} = [\
@basesA,\
@basesB];
58 open O
,'>',$prefix.'.tsv' or die "Error opening $prefix.tsv : $!\n";
59 print O
"# From: [$prefix]\n",join("\t",'Pos',@IDab),"\n";
60 for my $i (0 .. $#Positions) {
62 push @tmp,$Positions[$i];
64 push @tmp,$HapDat{$id}->[0]->[$i];
65 push @tmp,$HapDat{$id}->[1]->[$i];
67 print O
join("\t",@tmp),"\n";