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