-
Notifications
You must be signed in to change notification settings - Fork 5
/
fastphase2ped.pl
71 lines (69 loc) · 1.51 KB
/
fastphase2ped.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/perl
use strict;
use warnings;
my $line_number;
my $current_sample;
my @samples;
my %data;
my $n_markers;
my $header = 1;
my @contigs;
my $current_contig;
my %contig_markers;
my %geno;
my %t;
$t{"0"} = "A";
$t{"1"} = "C";
while(<STDIN>){
chomp;
if ($_ =~ m/BEGIN GENOTYPES/){
$line_number = 1;
$header = 0;
$current_contig++;
push(@contigs, $current_contig);
next;
}elsif ($_ =~ m/END GENOTYPES/){
$header = 1;
next;
}
if ($header){next;}
if ($line_number){
if ($line_number == 1){
my $sample = $_;
$sample =~ s/# //g;
push(@samples,$sample) unless grep{$_ eq $sample} @samples;
$current_sample = $sample;
$line_number++;
next;
}elsif($line_number == 2){
my @a = split(/ /,$_);
$contig_markers{$current_contig} = $#a;
foreach my $i (0..$#a){
$data{$current_sample}{$current_contig}{$i}{1}= $t{$a[$i]};
}
$line_number++;
next;
}elsif($line_number == 3){
my @a = split(/ /,$_);
foreach my $i (0..$#a){
$data{$current_sample}{$current_contig}{$i}{2}= $t{$a[$i]};
}
foreach my $i (0..$#a){
$geno{$current_sample} .= " $data{$current_sample}{$current_contig}{$i}{1} $data{$current_sample}{$current_contig}{$i}{2}";
}
undef(%data);
$line_number = 1;
next;
}
}
}
my $first_line;
foreach my $sample (@samples){
if($first_line){
print "\n";
}else{
$first_line++;
}
print "$sample $sample 0 0 0 0";
print "$geno{$sample}";
}