1 #!/usr/bin/perl 2 3 use strict; 4 use warnings; 5 6 my $input = $ARGV[0];my $name = $ARGV[1];my $start = $ARGV[2];my $cut_start=$ARGV[3];my $cut_end=$ARGV[4]; 7 8 my $all_start=$ARGV[5];my $all_end =$ARGV[6]; 9 10 my $cut = &store ($input);my %cut = %$cut; 11 12 my ($list,$average) = &count(%cut); 13 14 print "$name $list $average $cut_start $cut_end $all_start $all_end "; 15 16 #####sub######## 17 18 sub count{ 19 20 my %cut = @_; 21 22 my @arr;my @all; 23 24 foreach my $key(keys %cut) 25 { 26 my $long = $cut{$key};my @split = split //,$long; 27 28 push @arr,[@split]; 29 } 30 31 my $i=0;my $j=0; 32 33 for($j=0;$j<10;$j++) 34 { 35 my %list; 36 37 for($i=0;$i<$#arr+1;$i++) 38 { 39 $list{$arr[$i][$j]}++; 40 } 41 42 my $key = (sort {$list{$b} <=> $list{$a}} keys%list)[0]; 43 44 my $max = $key eq '-'?0:$list{$key}; 45 46 my $rate = $max/($#arr+1); 47 48 $all[$j]=sprintf "%.2f",$rate; 49 } 50 51 my $list = join("|",@all); 52 53 my $sum =0; 54 55 foreach(@all) 56 { 57 $sum += $_; 58 } 59 60 my $average = $sum/10; 61 62 return $list,$average; 63 } 64 65 sub store{ 66 67 open FA,$input; 68 69 my @arr; 70 71 my $id; 72 73 my %cut; 74 75 while(my $line = <FA>) 76 { 77 chomp $line; 78 79 if($line =~ />(w*)/) 80 { 81 $id = $1; 82 } 83 else 84 { 85 $cut{$id} = substr ($line,$start-1 ,10); 86 } 87 } 88 return %cut; 89 }