5 matrix_pirs2soapsnp.pl -- convert pirs matrix to soapsnp format
13 Author: Fan Wei, fanw@genomics.org.cn
14 Version: 1.0, Date: 2006-12-6
19 matrix_pirs2soapsnp.pl <*pirs.matrix>
20 --help output help information to screen
30 use FindBin
qw($Bin $Script);
31 use File::Basename qw(basename dirname);
33 use File
::Path
; ## function " mkpath" and "rmtree" deal with directory
35 ##get options from command line into variables and set default values
41 die `pod2text $0` if (@ARGV == 0 || $Help);
50 my %BaseNum = ("A",0,"C",1,"G",2,"T",3);
55 $Ref_num = $1 if (/Ref_base_number (\d+)/);
56 $Qual_num = $1 if (/Quality_number (\d+)/);
57 $Cyc_num = $1 if (/Cycle_number (\d+)/);
58 $Base_num = $1 if (/Seq_base_num (\d+)/);
66 $ref = $BaseNum{$ref};
69 if (@t % $Qual_num != 0) {
70 print "error #####################\n";
72 for (my $i=0; $i<@t; $i++) {
73 my $qual = $i%$Qual_num;
74 my $base = ($i - $i%$Qual_num)/$Qual_num;
75 $data{$qual}{$cycle}{$ref}{$base} = $t[$i];
84 print "#qual\tcycle\tA->A\tA->C\tA->G\tA->T\tC->A\tC->C\tC->G\tC->T\tG->A\tG->C\tG->G\tG->T\tT->A\tT->C\tT->G\tT->T\n";
88 foreach my $qual (sort {$a<=>$b} keys %data) {
89 my $qual_p = $data{$qual};
90 foreach my $cyc (sort {$a<=>$b} keys %$qual_p) {
92 my $cyc_p = $qual_p->{$cyc};
93 foreach my $ref (sort {$a<=>$b} keys %$cyc_p) {
94 my $ref_p = $cyc_p->{$ref};
96 foreach my $base (sort {$a<=>$b} keys %$ref_p) {
97 my $freq = $ref_p->{$base};
98 $freq = 1 if($freq == 0);
101 foreach my $base (sort {$a<=>$b} keys %$ref_p) {
102 my $freq = $ref_p->{$base};
103 $freq = 1 if($freq == 0);
104 printf("\t%e", $freq/$total);