4 use Time
::HiRes qw
( gettimeofday tv_interval
);
10 our($opt_i, $opt_o, $opt_v,$opt_b);
13 \t-i Add_ref files list (./indsnp.lst)
14 \t-o Output PWM file (snp.pwm)
15 \t-v show verbose info to STDOUT
16 \t-b No pause for batch runs
18 # \t-d dbSNP SQLite data file (_tdbSNP.sqlite)
22 $opt_i='./indsnp.lst' if ! defined $opt_i;
23 $opt_o='snp.pwm' if ! $opt_o;
25 print STDERR
"From [$opt_i] to [$opt_o]\n";
26 if (! $opt_b) {print STDERR
'press [Enter] to continue...'; <>;}
28 #http://doc.bioperl.org/bioperl-live/Bio/Tools/IUPAC.html#BEGIN1
29 my %IUB = ( A
=> [qw(A)],
48 my $start_time = [gettimeofday
];
51 open L
,'<',$opt_i or die "Error opening $opt_i: $!\n";
54 if (-s
$_) {push @files,$_;}
55 else {warn "[!]$_ not available.\n";}
58 warn '[!]Total: ',scalar @files," files.\n";
61 open O
,'>',$opt_o or die "Error opening $opt_o: $!\n";
62 for my $file (@files) {
63 open I
,'<',$file or die "Error opening $file: $!\n";
66 my ($chr,$pos,$bases) = split /\t/;
68 my @base = split / /,$bases;
69 print O
"$chr\t$pos\t$base[0]\t";
72 # print ">$chr\t$pos\t$base[0]\t$bases\n";
74 print ">$chr\t$pos\t" if $opt_v;
75 my ($d,$i,%counter,%stat);
76 $stat{1}=$stat{2}=$stat{3}=$stat{4}=0;
78 my $arr=$IUB{$_} or next; # So, $i != @base;
80 print "$_$d" if $opt_v;
89 print O
"$i,$stat{1},$stat{2},$stat{3},$stat{4}\t";
91 for (sort {$counter{$b} <=> $counter{$a}} keys %counter) {
92 push @base,sprintf('%s:%f',"$_",$counter{$_}/$i);
94 print O
join(',',@base),"\n";
95 print "\n$i,$stat{1},$stat{2},$stat{3},$stat{4}\t",join(',',@base),"\n\n" if $opt_v;
101 warn "[!]Total: $snpcount SNPs.\n[!]Done !\n";
103 my $stop_time = [gettimeofday
];
105 print STDERR
"\n Time Elapsed:\t",tv_interval
( $start_time, $stop_time )," second(s)\n";