blib/lib/Bio/Gonzales/Align/IO.pm

filter: Statementstmt 77.7% 77 / 99 Branchbran 57.1% 16 / 28 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 91.6% 11 / 12 Podpod 50.0% 1 / 2 totaltotal 74.4% 105 / 141 CC 17 SCAR 15.3
CC
17
Cov
73%
_seq_phylip_slurp
12.0
phylip_spew
5.4
_int_phylip_slurp
5.0
CRAP 4.6
« blib/lib/Bio/Gonzales/Seq/IO/fastq.pm ↑ Summary blib/lib/Bio/Gonzales/Util/Graphics/Color/Generator.pm »
1 package Bio::Gonzales::Align::IO;
2  
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use Bio::Gonzales::Seq;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use Bio::Gonzales::Util::File qw/open_on_demand/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Bio::Gonzales::Util qw/flatten/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 our ( @EXPORT, @EXPORT_OK, %EXPORT_TAGS );
13 1 our $VERSION = '0.058'; # VERSION
14  
15 1 @EXPORT = qw();
16 1 %EXPORT_TAGS = ();
17 1 @EXPORT_OK = qw(phylip_spew phylip_slurp);
18  
19 sub phylip_spew {
20 3 ▶ my ( $file_or_fh, $mode, @rest ) = @_;
Subroutine phylip_spew: called CC=5 SCAR=16.8
Pod documented
21 3 my @seqs = flatten(@rest);
22  
23 3 my ( $fh, $fh_was_open ) = open_on_demand( $file_or_fh, '>' );
24 3 ▶ if ( ref $mode eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $mode eq 'HASH') { } 2 1 3
25 2 ▶ if ( $mode->{sequential} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode->{'sequential'}) { } 2 0 2
26 2 _seq_phylip_spew( $fh, \@seqs, $mode->{relaxed} );
27 } else {
28 0 confess 'function not implemented, yet';
29 }
30  
31 } else {
32 1 my $relaxed = $mode =~ s/^r(?:elax(?:ed)?)?\W//;
33 1 ▶ if ( $mode =~ /^s(?:eq(?:uential)?)?$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode =~ /^s(?:eq(?:uential)?)?$/) { } 1 0 1
34 1 _seq_phylip_spew( $fh, \@seqs, $relaxed );
35 } else {
36 0 croak "you have to supply a mode";
37 }
38 }
39  
40 3 ▶ $fh->close unless ($fh_was_open);
Branch: 1 branch
BranchTrueFalseTotal
unless $fh_was_open 3 0 3
41 }
42  
43 sub _seq_phylip_spew {
44 3 ▶ my ( $fh, $seqs, $relaxed ) = @_;
Subroutine _seq_phylip_spew: called CC=4 SCAR=13.9
45  
46 3 ▶ croak "You have to supply an array of Bio::Gonzales::Seq objects"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $seqs eq "ARRAY" 0 3 3
47 unless ( ref $seqs eq 'ARRAY' );
48  
49 3 print $fh scalar(@$seqs) . " " . $seqs->[0]->length, "\n";
50  
51 3 for my $seq (@$seqs) {
52 12 my $id;
53 12 ▶ if ($relaxed) {
Branch: 1 branch
BranchTrueFalseTotal
if ($relaxed) { } 8 4 12
54 8 ( $id = $seq->id ) =~ s/\s/_/g;
55 8 $id .= " ";
56 } else {
57 4 $id = sprintf( "%-10s", substr( $seq->id, 0, 10 ) );
58 }
59 12 print $fh $id . $seq->seq, "\n";
60 }
61 }
62  
63 sub phylip_slurp {
64 1 ▶ my ( $file_or_fh, $mode ) = @_;
Subroutine phylip_slurp: called CC=4 SCAR=15.0
Pod undocumented
65  
66 1 my $seqs;
67 1 my ( $fh, $fh_was_open ) = open_on_demand( $file_or_fh, '<' );
68 1 my $relaxed = $mode =~ s/^r(?:elax(?:ed)?)?\W//;
69 1 ▶ if ( $mode =~ /^s(?:eq(?:uential)?)?$/ ) { $seqs = _seq_phylip_slurp( $fh, $relaxed ) }
Branch: 2 branches
BranchTrueFalseTotal
if ($mode =~ /^s(?:eq(?:uential)?)?$/) { } 0 1 1
elsif ($mode =~ /^i(?:nter(?:leaved)?)?$/) { } 1 0 1
70 1 elsif ( $mode =~ /^i(?:nter(?:leaved)?)?$/ ) { $seqs = _int_phylip_slurp( $fh, $relaxed ) }
71 0 else { croak "you have to supply a mode" }
72  
73 1 ▶ $fh->close unless ($fh_was_open);
Branch: 1 branch
BranchTrueFalseTotal
unless $fh_was_open 1 0 1
74 1 return $seqs;
75 }
76  
77 sub _seq_phylip_slurp {
78 0 ▶ my ( $fh, $relaxed ) = @_;
Subroutine _seq_phylip_slurp: not called CC=3 SCAR=24.8
79  
80 0 my $header = <$fh>;
81 0 $header =~ s/\r\n/\n/;
82 0 chomp $header;
83 0 my ( $taxa, $chars ) = split /\s+/, $header;
84  
85 0 my @seqs;
86 0 ▶ while ( my $line = <$fh> ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $fh)) 0 0 0
87 0 $line =~ s/\r\n/\n/;
88 0 chomp $line;
89  
90 0 my ( $id, $seq_string );
91 0 ▶ if ($relaxed) {
Branch: 1 branch
BranchTrueFalseTotal
if ($relaxed) { } 0 0 0
92 0 ( $id, $seq_string ) = split /\s+/, $line, 2;
93 } else {
94 0 ( $id, $seq_string ) = unpack( 'A10A*', $line );
95 0 $id =~ s/^\s*//;
96 0 $id =~ s/\s*$//;
97 }
98  
99 0 push @seqs, Bio::Gonzales::Seq->new( id => $id, seq => $seq_string );
100 }
101  
102 0 return \@seqs;
103 }
104  
105 sub _int_phylip_slurp {
106 1 ▶ my ( $fh, $relaxed ) = @_;
Subroutine _int_phylip_slurp: called CC=5 SCAR=16.1
107  
108 1 my $header = <$fh>;
109 1 $header =~ s/\r\n/\n/;
110 1 chomp $header;
111 1 my ( $taxa, $chars ) = split /\s+/, $header;
112  
113 1 my @idseq_strings;
114 1 my $i = 0;
115 1 ▶ while ( my $line = <$fh> ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $fh)) 9 1 10
116 9 $line =~ s/\r\n/\n/;
117 9 chomp $line;
118 9 ▶ next if ( $line =~ /^\s*$/ );
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^\s*$/ 1 8 9
119  
120 8 my $idx = $i++ % $taxa;
121  
122 8 $idseq_strings[$idx] .= $line;
123 }
124  
125 1 my @seqs;
126 1 for my $idseq_string (@idseq_strings) {
127 4 my ( $id, $seq_string );
128 4 ▶ if ($relaxed) {
Branch: 1 branch
BranchTrueFalseTotal
if ($relaxed) { } 0 4 4
129 0 ( $id, $seq_string ) = split /\s+/, $idseq_string, 2;
130 } else {
131 4 ( $id, $seq_string ) = unpack( 'A10A*', $idseq_string );
132 4 $id =~ s/^\s*//;
133 4 $id =~ s/\s*$//;
134 }
135  
136 4 push @seqs, Bio::Gonzales::Seq->new( id => $id, seq => $seq_string );
137 }
138  
139 1 return \@seqs;
140 }
141  
142 1 1;
143  
144 __END__
145  
146 =head1 NAME
147  
148 Bio::Gonzales::Align::Util - Utility functions for aligment stuff
149  
150 =head1 SYNOPSIS
151  
152 use Bio::Gonzales::Align::Util qw(phylip_spew);
153  
154 =head1 DESCRIPTION
155  
156 =head1 OPTIONS
157  
158 =head1 SUBROUTINES
159  
160 =over 4
161  
162 =item B<< phylip_spew($file_or_fh, $mode, $seqs) >>
163  
164 Spew out the seqs to a file or file handle. Following modes are available:
165  
166 =over 4
167  
168 =item s|seq|sequential
169  
170 Sequential format, cuts of the ID at 10 characters starting from the beginning
171  
172 =item r|relax|relaxed s|seq|sequential
173  
174 The relaxed phylip format.
175  
176 =back
177  
178 =back
179  
180 =head1 SEE ALSO
181  
182 =head1 AUTHOR
183  
184 jw bargsten, C<< <joachim.bargsten at wur.nl> >>
185  
186 =cut
« blib/lib/Bio/Gonzales/Seq/IO/fastq.pm ↑ Summary blib/lib/Bio/Gonzales/Util/Graphics/Color/Generator.pm »