-
Notifications
You must be signed in to change notification settings - Fork 2
/
esl-seqstat-indi-composition.pl
47 lines (43 loc) · 1.48 KB
/
esl-seqstat-indi-composition.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
my $usage = "perl esl-seqstat-indi-composition.pl <seqfile> <name for esl-seqstat -a output file>";
if(scalar(@ARGV) != 2) {
die $usage;
}
my ($seqfile, $statfile) = (@ARGV);
system("esl-seqstat -a $seqfile > $statfile");
if($? != 0) { die "ERROR esl-seqstat -a command failed"; }
# first get max seqname width
my $seqnamewidth = 0;
open(IN, $statfile) || die "ERROR unable to open $statfile for reading";
while($line = <IN>) {
if($line =~ /^\=/) {
chomp $line;
@el_A = split(/\s+/, $line);
($seqname, $len) = ($el_A[1], $el_A[2]);
if(length($seqname) > $seqnamewidth) { $seqnamewidth = length($seqname); }
}
}
close(IN);
open(IN, $statfile) || die "ERROR unable to open $statfile for reading on second round";
while($line = <IN>) {
if($line =~ /^\=/) {
chomp $line;
@el_A = split(/\s+/, $line);
($seqname, $len) = ($el_A[1], $el_A[2]);
$seqname2fetch = $seqname;
$seqname2fetch =~ s/\|/\\|/g;
my $seqstat_c_output = `esl-sfetch $seqfile $seqname2fetch | esl-seqstat -c - | grep ^residue`;
my @seqstat_c_A = split(/\n/, $seqstat_c_output);
my $outline = "";
foreach my $resline (@seqstat_c_A) {
if($resline =~ /^residue\:\s+(\S+)\s+(\d+)\s+(\S+)/) {
my($r, $n, $f) = ($1, $2, $3);
my $tok = sprintf("%1s:[%6s]:%-10s", $r, $f, $n);
$outline .= " " . $tok;
}
else {
die "ERROR unable to parse res line: $resline";
}
}
printf("%-*s $outline\n", $seqnamewidth, $seqname);
}
}