line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Bio::Oxbench::Util; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
121086
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
40
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
5
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
78
|
|
6
|
1
|
|
|
1
|
|
2779
|
use English qw/-no_match_vars/; |
|
1
|
|
|
|
|
6562
|
|
|
1
|
|
|
|
|
6
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub fasta2bloc { |
9
|
0
|
|
|
0
|
0
|
|
my ( $in, $out ) = @_; |
10
|
|
|
|
|
|
|
|
11
|
0
|
|
|
|
|
|
my $ifh; |
12
|
0
|
0
|
|
|
|
|
if ( $in eq q{-} ) { |
13
|
0
|
|
|
|
|
|
$ifh = \*STDIN; |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
else { |
16
|
0
|
0
|
|
|
|
|
open $ifh, '<', $in or die "$!: $in\n"; |
17
|
|
|
|
|
|
|
} |
18
|
0
|
|
|
|
|
|
my $alignment = read_fasta($ifh); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# Write data |
21
|
0
|
|
|
|
|
|
my $ofh; |
22
|
0
|
0
|
|
|
|
|
if ( $out eq '-' ) { |
23
|
0
|
|
|
|
|
|
$ofh = \*STDOUT; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
else { |
26
|
0
|
0
|
|
|
|
|
open $ofh, '>', $out or die "$!: $out\n"; |
27
|
|
|
|
|
|
|
} |
28
|
0
|
|
|
|
|
|
write_bloc( $ofh, $alignment ); |
29
|
0
|
|
|
|
|
|
return; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub write_bloc { |
33
|
0
|
|
|
0
|
0
|
|
my ( $fh, $align ) = @_; |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
for my $id ( @{ $align->{id} } ) { |
|
0
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
print {$fh} ">$id\n"; |
|
0
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
} |
38
|
0
|
|
|
|
|
|
print {$fh} "* iteration 1\n"; |
|
0
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
for my $i ( 0 .. $align->{alen} - 1 ) { |
40
|
0
|
|
|
|
|
|
for my $seq ( @{ $align->{seq} } ) { |
|
0
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
print {$fh} substr( $seq, $i, 1 ); |
|
0
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
} |
43
|
0
|
|
|
|
|
|
print {$fh} "\n"; |
|
0
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
} |
45
|
0
|
|
|
|
|
|
print {$fh} "*\n"; |
|
0
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
return; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub read_fasta { |
50
|
0
|
|
|
0
|
0
|
|
my $fh = shift; |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
my $align = { |
53
|
|
|
|
|
|
|
seq => [], |
54
|
|
|
|
|
|
|
id => [], |
55
|
|
|
|
|
|
|
}; |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
while (<$fh>) { |
58
|
0
|
|
|
|
|
|
chomp; |
59
|
0
|
0
|
|
|
|
|
if (/^>/) { |
60
|
0
|
|
|
|
|
|
my $label = substr $_, 1; |
61
|
0
|
|
|
|
|
|
$label =~ s/ .*//; |
62
|
0
|
|
|
|
|
|
push @{ $align->{id} }, $label; |
|
0
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
push @{ $align->{seq} }, q{}; |
|
0
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
else { |
66
|
0
|
|
|
|
|
|
$align->{seq}->[-1] .= $_; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
} |
69
|
0
|
|
|
|
|
|
$align->{alen} = length $align->{seq}[0]; |
70
|
0
|
|
|
|
|
|
$align->{nseq} = @{ $align->{seq} }; |
|
0
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
return $align; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
1; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
__END__ |