new file: pixi.toml
[GalaxyCodeBases.git] / projects / recombineMap / sperm_by_fw / snp_calling / matrix_pirs2soapsnp.pl
blobd06bcdbb07b200f59a3d692f17161b58688309b5
1 #!/usr/bin/perl
3 =head1 Name
5 matrix_pirs2soapsnp.pl -- convert pirs matrix to soapsnp format
7 =head1 Description
11 =head1 Version
13 Author: Fan Wei, fanw@genomics.org.cn
14 Version: 1.0, Date: 2006-12-6
15 Note:
17 =head1 Usage
19 matrix_pirs2soapsnp.pl <*pirs.matrix>
20 --help output help information to screen
22 =head1 Exmple
26 =cut
28 use strict;
29 use Getopt::Long;
30 use FindBin qw($Bin $Script);
31 use File::Basename qw(basename dirname);
32 use Data::Dumper;
33 use File::Path; ## function " mkpath" and "rmtree" deal with directory
35 ##get options from command line into variables and set default values
36 my ($Verbose,$Help);
37 GetOptions(
38 "verbose"=>\$Verbose,
39 "help"=>\$Help
41 die `pod2text $0` if (@ARGV == 0 || $Help);
43 my $Ref_num = 0;
44 my $Qual_num = 0;
45 my $Cyc_num = 0;
46 my $Base_num = 0;
47 my $head;
48 my %data;
50 my %BaseNum = ("A",0,"C",1,"G",2,"T",3);
52 while (<>) {
53 if (/^\#/) {
54 $head .= $_;
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+)/);
61 if (/^\w/) {
62 my @t = split /\s+/;
63 my $ref = shift @t;
64 my $cycle = shift @t;
65 pop @t;
66 $ref = $BaseNum{$ref};
67 $cycle -= 1;
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];
79 if(/^</){
80 last;
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";
86 #print Dumper \%data;
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) {
91 print "$qual\t$cyc";
92 my $cyc_p = $qual_p->{$cyc};
93 foreach my $ref (sort {$a<=>$b} keys %$cyc_p) {
94 my $ref_p = $cyc_p->{$ref};
95 my $total = 0;
96 foreach my $base (sort {$a<=>$b} keys %$ref_p) {
97 my $freq = $ref_p->{$base};
98 $freq = 1 if($freq == 0);
99 $total += $freq;
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);
108 print "\n";