-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlengths_alignment.pl
67 lines (42 loc) · 1.17 KB
/
lengths_alignment.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env perl
#Calculate range of lengths for aligned COGs in a non-interleaved format. Calculate proportion of gaps in the alignment
#and average length for each aligned COG
use strict;
use warnings;
my @files= glob "*.fas";
my @lengths;
my $total_no_aminoacids;
my $total_no_gaps;
my $total_length;
my $length;
foreach (@files) {
if ($length) {push (@lengths, $length);}
open my $fh, '<', $_ or die;
my %hash;
my $header;
while (my $line=<$fh>) {
chomp $line;
if ($line =~ m/>/) { $header=$line;}
else {
$hash{$header}=$line;
$length= length $line;
$total_no_aminoacids+= $length;
for (my $i=0; $i<$length; ++$i) {
my $aa=substr ($line,$i,1);
if ($aa eq "-") {++$total_no_gaps;}
}
}
}
$total_length+=$length;
}
my @lengths_sorted= sort {$a <=> $b} @lengths;
my $sum;
foreach (@lengths) {
$sum+=$_;
}
my $average=$sum/3983;
my $prop_gaps= $total_no_gaps/$total_no_aminoacids;
print "$total_length\n\n";
print "Proportion of gaps: $prop_gaps\n\n";
print "Average length: $average\n\n";
print "Lengths:\n@lengths_sorted\n\n";