| 1 | # | ||||||||||||||||||||||||||||
| 2 | # BioPerl module for Bio::AlignIO::largemultifasta | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | # based on the Bio::SeqIO::largefasta module | ||||||||||||||||||||||||||||
| 5 | # by Ewan Birney <birney@ebi.ac.uk> | ||||||||||||||||||||||||||||
| 6 | # and Lincoln Stein <lstein@cshl.org> | ||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||
| 8 | # and the SimpleAlign.pm module of Ewan Birney | ||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||
| 10 | # Copyright Albert Vilella | ||||||||||||||||||||||||||||
| 11 | # | ||||||||||||||||||||||||||||
| 12 | # You may distribute this module under the same terms as perl itself | ||||||||||||||||||||||||||||
| 13 | # _history | ||||||||||||||||||||||||||||
| 14 | # January 20, 2004 | ||||||||||||||||||||||||||||
| 15 | # POD documentation - main docs before the code | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | =head1 NAME | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | Bio::AlignIO::largemultifasta - Largemultifasta MSA Sequence | ||||||||||||||||||||||||||||
| 20 | input/output stream | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | Do not use this module directly. Use it via the L<Bio::AlignIO> class. | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | This object can transform L<Bio::SimpleAlign> objects to and from | ||||||||||||||||||||||||||||
| 29 | largemultifasta flat file databases. This is for the fasta sequence | ||||||||||||||||||||||||||||
| 30 | format NOT FastA analysis program. To process the pairwise alignments | ||||||||||||||||||||||||||||
| 31 | from a FastA (FastX, FastN, FastP, tFastA, etc) use the Bio::SearchIO | ||||||||||||||||||||||||||||
| 32 | module. | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | Reimplementation of Bio::AlignIO::fasta modules so that creates | ||||||||||||||||||||||||||||
| 35 | temporary files instead of keeping the whole sequences in memory. | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | =head1 FEEDBACK | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | =head2 Support | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | Please direct usage questions or support issues to the mailing list: | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | I<bioperl-l@bioperl.org> | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | rather than to the module maintainer directly. Many experienced and | ||||||||||||||||||||||||||||
| 46 | reponsive experts will be able look at the problem and quickly | ||||||||||||||||||||||||||||
| 47 | address it. Please include a thorough description of the problem | ||||||||||||||||||||||||||||
| 48 | with code and data examples if at all possible. | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | =head2 Reporting Bugs | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | Report bugs to the Bioperl bug tracking system to help us keep track | ||||||||||||||||||||||||||||
| 53 | the bugs and their resolution. Bug reports can be submitted via the | ||||||||||||||||||||||||||||
| 54 | web: | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | https://github.com/bioperl/bioperl-live/issues | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | =head1 AUTHORS - Albert Vilella, Heikki Lehvaslaiho | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | Email: avilella-at-gmail-dot-com, heikki-at-bioperl-dot-org | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | =head1 APPENDIX | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | The rest of the documentation details each of the object | ||||||||||||||||||||||||||||
| 66 | methods. Internal methods are usually preceded with a _ | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | =cut | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | # Let the code begin... | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | package Bio::AlignIO::largemultifasta; | ||||||||||||||||||||||||||||
| 73 | 2 | $Bio::AlignIO::largemultifasta::VERSION = '1.7.8'; | |||||||||||||||||||||||||||
| 74 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 2 | ▶ | use Bio::Seq::LargeLocatableSeq; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 77 | 2 | ▶ | use Bio::Seq::SeqFactory; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 2 | ▶ | use base qw(Bio::AlignIO Bio::SeqIO Bio::SimpleAlign); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 2 | ▶ | sub _initialize { | ||||||||||||||||||||||||||
|
Subroutine
_initialize: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 83 | 2 | my($self,@args) = @_; | |||||||||||||||||||||||||||
| 84 | 2 | $self->SUPER::_initialize(@args); | |||||||||||||||||||||||||||
| 85 | 2 | ▶ | if( ! defined $self->sequence_factory ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | 2 | $self->sequence_factory(Bio::Seq::SeqFactory->new( | |||||||||||||||||||||||||||
| 87 | -verbose => $self->verbose(), | ||||||||||||||||||||||||||||
| 88 | -type => 'Bio::Seq::LargeLocatableSeq' | ||||||||||||||||||||||||||||
| 89 | )); | ||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | =head2 next_seq | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | Title : next_seq | ||||||||||||||||||||||||||||
| 96 | Usage : $seq = $stream->next_seq() | ||||||||||||||||||||||||||||
| 97 | Function: returns the next sequence in the stream while taking care | ||||||||||||||||||||||||||||
| 98 | of the length | ||||||||||||||||||||||||||||
| 99 | Returns : Bio::Seq object | ||||||||||||||||||||||||||||
| 100 | Args : NONE | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | =cut | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 7 | ▶ | sub next_seq { | ||||||||||||||||||||||||||
|
Subroutine
next_seq: called CC=10 SCAR=23.4
Pod
documented
| |||||||||||||||||||||||||||||
| 105 | 7 | my ($self) = @_; | |||||||||||||||||||||||||||
| 106 | 7 | my $largeseq = $self->sequence_factory->create(-alphabet=>$self->alphabet); | |||||||||||||||||||||||||||
| 107 | 7 | my ($id,$fulldesc,$entry); | |||||||||||||||||||||||||||
| 108 | 7 | my $count = 0; | |||||||||||||||||||||||||||
| 109 | 7 | my $seen = 0; | |||||||||||||||||||||||||||
| 110 | 7 | ▶ | while( defined ($entry = $self->_readline) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | 17 | ▶ | if( $seen == 1 && $entry =~ /^\s*>/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$seen == 1 and $entry =~ /^\s*>/
MC/DC100%2/2
$seen == 1 and $entry =~ /^\s*>/
$seen == 1
$entry =~ /^\s*>/
Truth table100%3/3
A and B
A= $seen == 1B= $entry =~ /^\s*>/
| |||||||||||||||||||||||||||||
| 112 | 5 | $self->_pushback($entry); | |||||||||||||||||||||||||||
| 113 | 5 | return $largeseq; | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | 12 | ▶ | if ( $entry eq '>' ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 116 | 0 | $seen = 1; next; | |||||||||||||||||||||||||||
| 117 | } elsif( $entry =~ /\s*>(.+?)$/ ) { | ||||||||||||||||||||||||||||
| 118 | 6 | $seen = 1; | |||||||||||||||||||||||||||
| 119 | 6 | ▶ | ($id,$fulldesc) = ($1 =~ /^\s*(\S+)\s*(.*)$/) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | or $self->warn("Can't parse fasta header"); | ||||||||||||||||||||||||||||
| 121 | 6 | $largeseq->display_id($id); | |||||||||||||||||||||||||||
| 122 | 6 | $largeseq->primary_id($id); | |||||||||||||||||||||||||||
| 123 | 6 | $largeseq->desc($fulldesc); | |||||||||||||||||||||||||||
| 124 | } else { | ||||||||||||||||||||||||||||
| 125 | 6 | $entry =~ s/\s+//g; | |||||||||||||||||||||||||||
| 126 | 6 | $largeseq->add_sequence_as_string($entry); | |||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | 12 | ▶ | (++$count % 1000 == 0 && $self->verbose() > 0) && print "line $count\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
++$count % 1000 == 0 and $self->verbose > 0
MC/DC0%0/2
++$count % 1000 == 0 and $self->verbose > 0
++$count % 1000 == 0
$self->verbose > 0
Truth table33%1/3
A and B
A= ++$count % 1000 == 0B= $self->verbose > 0
| |||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | 2 | ▶ | if( ! $seen ) { return; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 131 | 1 | return $largeseq; | |||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | =head2 next_aln | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | Title : next_aln | ||||||||||||||||||||||||||||
| 138 | Usage : $aln = $stream->next_aln() | ||||||||||||||||||||||||||||
| 139 | Function: returns the next alignment in the stream. | ||||||||||||||||||||||||||||
| 140 | Returns : L<Bio::Align::AlignI> object - returns 0 on end of file | ||||||||||||||||||||||||||||
| 141 | or on error | ||||||||||||||||||||||||||||
| 142 | Args : NONE | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | =cut | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 1 | ▶ | sub next_aln { | ||||||||||||||||||||||||||
|
Subroutine
next_aln: called CC=5 SCAR=17.0
Pod
documented
| |||||||||||||||||||||||||||||
| 147 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 148 | 1 | my $largeseq; | |||||||||||||||||||||||||||
| 149 | 1 | my $aln = Bio::SimpleAlign->new(); | |||||||||||||||||||||||||||
| 150 | 1 | ▶ | while (defined ($largeseq = $self->next_seq) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 151 | 6 | $aln->add_seq($largeseq); | |||||||||||||||||||||||||||
| 152 | 6 | $self->debug("sequence readed\n"); | |||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | 1 | my $alnlen = $aln->length; | |||||||||||||||||||||||||||
| 156 | 1 | foreach my $largeseq ( $aln->each_seq ) { | |||||||||||||||||||||||||||
| 157 | 6 | ▶ | if( $largeseq->length < $alnlen ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 158 | 0 | my ($diff) = ($alnlen - $largeseq->length); | |||||||||||||||||||||||||||
| 159 | 0 | $largeseq->seq("-" x $diff); | |||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | 1 | ▶ | return $aln if $aln->num_sequences; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 164 | 0 | return; | |||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | =head2 write_aln | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | Title : write_aln | ||||||||||||||||||||||||||||
| 171 | Usage : $stream->write_aln(@aln) | ||||||||||||||||||||||||||||
| 172 | Function: writes the $aln object into the stream in largemultifasta format | ||||||||||||||||||||||||||||
| 173 | Returns : 1 for success and 0 for error | ||||||||||||||||||||||||||||
| 174 | Args : L<Bio::Align::AlignI> object | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | =cut | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | 1 | ▶ | sub write_aln { | ||||||||||||||||||||||||||
|
Subroutine
write_aln: called CC=11 SCAR=26.5
Pod
documented
| |||||||||||||||||||||||||||||
| 180 | 1 | my ($self,@aln) = @_; | |||||||||||||||||||||||||||
| 181 | 1 | my ($seq,$desc,$rseq,$name,$count,$length,$seqsub); | |||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | 1 | foreach my $aln (@aln) { | |||||||||||||||||||||||||||
| 184 | 1 | ▶ | if( ! $aln || ! $aln->isa('Bio::Align::AlignI') ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$aln and $aln->isa("Bio::Align::AlignI")
MC/DC0%0/2
$aln and $aln->isa("Bio::Align::AlignI")
$aln
$aln->isa("Bio::Align::AlignI")
Truth table33%1/3
A and B
A= $alnB= $aln->isa("Bio::Align::AlignI")
| |||||||||||||||||||||||||||||
| 185 | 0 | $self->warn("Must provide a Bio::Align::AlignI object when calling write_aln"); | |||||||||||||||||||||||||||
| 186 | 0 | next; | |||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||
| 188 | 1 | foreach $rseq ( $aln->each_seq() ) { | |||||||||||||||||||||||||||
| 189 | 6 | $name = $aln->displayname($rseq->get_nse()); | |||||||||||||||||||||||||||
| 190 | 6 | $seq = $rseq->seq(); | |||||||||||||||||||||||||||
| 191 | 6 | ▶ | $desc = $rseq->description || ''; | ||||||||||||||||||||||||||
|
Condition50%1/2
$rseq->description || ''
MC/DC0%0/1
$rseq->description || ''
$rseq->description
Truth table50%1/2
A
A= $rseq->description
| |||||||||||||||||||||||||||||
| 192 | 6 | ▶ | $self->_print (">$name $desc\n") or return ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 193 | 6 | $count =0; | |||||||||||||||||||||||||||
| 194 | 6 | $length = length($seq); | |||||||||||||||||||||||||||
| 195 | 6 | ▶ | while( ($count * 60 ) < $length ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 196 | 12 | $seqsub = substr($seq,$count*60,60); | |||||||||||||||||||||||||||
| 197 | 12 | ▶ | $self->_print ("$seqsub\n") or return ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 198 | 12 | $count++; | |||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||
| 202 | 1 | ▶ | $self->flush if $self->_flush_on_write && defined $self->_fh; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->_flush_on_write and defined $self->_fh
MC/DC0%0/2
$self->_flush_on_write and defined $self->_fh
$self->_flush_on_write
defined $self->_fh
Truth table33%1/3
A and B
A= $self->_flush_on_writeB= defined $self->_fh
| |||||||||||||||||||||||||||||
| 203 | 1 | return 1; | |||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | 2 | 1; | |||||||||||||||||||||||||||