[Bio] / FigKernelScripts / get_families_final.pl Repository:
ViewVC logotype

Diff of /FigKernelScripts/get_families_final.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1, Thu Jan 30 20:20:42 2014 UTC revision 1.2, Fri Mar 7 16:04:44 2014 UTC
# Line 47  Line 47 
47    
48  my @sets;  my @sets;
49  my $last = <FAMS>;  my $last = <FAMS>;
50  while ($last && ($last =~ /^(\S[^\t]+\S)\t(\d+)\t(\S+)/))  while ($last && ($last =~ /^(\S[^\t]*)\t(\d+)\t(\S+)/))
51  {  {
52      my $fam = $1;      my $fam = $1;
53      my $subfam = $2;      my $subfam = $2;
54      my @set;      my @set;
55      while ($last && ($last =~ /^(\S[^\t]+\S)\t(\d+)\t(\S+)/) && ($fam eq $1) && ($subfam == $2))      while ($last && ($last =~ /^(\S[^\t]*\S)\t(\d+)\t(\S+)/) && ($fam eq $1) && ($subfam == $2))
56      {      {
57          push(@set,[$1,$2,$3]);          push(@set,[$1,$2,$3]);
58          $last = <FAMS>;          $last = <FAMS>;
59      }      }
60      push(@sets,\@set);      push(@sets,\@set);
61  }  }
62    if ($last) { die "POORLY FORMATTED FAMILY: CHECK $last" }
63  my $famN = 1;  my $famN = 1;
64  foreach my $set (sort { (@$b <=> @$a) or  foreach my $set (sort { (@$b <=> @$a) or
65                          ($a->[0] cmp $b->[0]) or                          ($a->[0] cmp $b->[0]) or
# Line 72  Line 72 
72          my $ln = length($to_seq{$tuple->[2]});          my $ln = length($to_seq{$tuple->[2]});
73          push(@lens,$ln);          push(@lens,$ln);
74      }      }
75      my($mean,$std_dev) = &gjostat::mean_stddev(@lens);      my($mean,$std_dev) = &mean_stddev(@lens);
76    
77      foreach my $tuple (@$set)      foreach my $tuple (@$set)
78      {      {
# Line 84  Line 84 
84      }      }
85      $famN++;      $famN++;
86  }  }
87    
88    sub mean_stddev
89    {
90        my $n = @_;
91        return $n ? ( shift, undef) : ( undef, undef ) if $n < 2;
92        my ( $sum, $sum2 ) = ( 0, 0 );
93        foreach ( @_ ) { $sum += $_; $sum2 += $_ * $_ }
94        my $x = $sum / $n;
95        my $to_check = ( $sum2 - ($n * $x * $x )) / ( $n - 1 );
96        ( $x, ($to_check > 0) ? sqrt($to_check) : 0);
97    }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3