| 1 | # | ||||||||||
| 2 | # BioPerl module for Bio::AlignIO::bl2seq | ||||||||||
| 3 | |||||||||||
| 4 | # based on the Bio::SeqIO modules | ||||||||||
| 5 | # by Ewan Birney <birney@ebi.ac.uk> | ||||||||||
| 6 | # and Lincoln Stein <lstein@cshl.org> | ||||||||||
| 7 | # | ||||||||||
| 8 | # the Bio::Tools::BPlite modules by | ||||||||||
| 9 | # Ian Korf (ifkorf at ucdavis.edu, http://www.bioperl.org/wiki/Ian_Korf), | ||||||||||
| 10 | # Lorenz Pollak (lorenz@ist.org, bioperl port) | ||||||||||
| 11 | # | ||||||||||
| 12 | # and the SimpleAlign.pm module of Ewan Birney | ||||||||||
| 13 | # | ||||||||||
| 14 | # Copyright Peter Schattner | ||||||||||
| 15 | # | ||||||||||
| 16 | # You may distribute this module under the same terms as perl itself | ||||||||||
| 17 | # _history | ||||||||||
| 18 | # September 5, 2000 | ||||||||||
| 19 | # POD documentation - main docs before the code | ||||||||||
| 20 | |||||||||||
| 21 | =head1 NAME | ||||||||||
| 22 | |||||||||||
| 23 | Bio::AlignIO::bl2seq - bl2seq sequence input/output stream | ||||||||||
| 24 | |||||||||||
| 25 | =head1 SYNOPSIS | ||||||||||
| 26 | |||||||||||
| 27 | Do not use this module directly. Use it via the L<Bio::AlignIO> class, as in: | ||||||||||
| 28 | |||||||||||
| 29 | use Bio::AlignIO; | ||||||||||
| 30 | |||||||||||
| 31 | $in = Bio::AlignIO->new(-file => "inputfilename" , | ||||||||||
| 32 | -format => "bl2seq", | ||||||||||
| 33 | -report_type => "blastn"); | ||||||||||
| 34 | $aln = $in->next_aln(); | ||||||||||
| 35 | |||||||||||
| 36 | |||||||||||
| 37 | =head1 DESCRIPTION | ||||||||||
| 38 | |||||||||||
| 39 | This object can create L<Bio::SimpleAlign> sequence alignment objects (of | ||||||||||
| 40 | two sequences) from C<bl2seq> BLAST reports. | ||||||||||
| 41 | |||||||||||
| 42 | A nice feature of this module is that - in combination with | ||||||||||
| 43 | L<Bio::Tools::Run::StandAloneBlast.pm> or a remote BLAST - it can be used to | ||||||||||
| 44 | align two sequences and make a L<Bio::SimpleAlign> object from them which | ||||||||||
| 45 | can then be manipulated using any L<Bio::SimpleAlign> methods, eg: | ||||||||||
| 46 | |||||||||||
| 47 | # Get two sequences | ||||||||||
| 48 | $str = Bio::SeqIO->new(-file=>'t/amino.fa' , '-format' => 'Fasta', ); | ||||||||||
| 49 | my $seq3 = $str->next_seq(); | ||||||||||
| 50 | my $seq4 = $str->next_seq(); | ||||||||||
| 51 | |||||||||||
| 52 | # Run bl2seq on them | ||||||||||
| 53 | $factory = Bio::Tools::StandAloneBlast->new('program' => 'blastp', | ||||||||||
| 54 | 'outfile' => 'bl2seq.out'); | ||||||||||
| 55 | my $bl2seq_report = $factory->bl2seq($seq3, $seq4); | ||||||||||
| 56 | # Note that report is a Bio::SearchIO object | ||||||||||
| 57 | |||||||||||
| 58 | # Use AlignIO.pm to create a SimpleAlign object from the bl2seq report | ||||||||||
| 59 | $str = Bio::AlignIO->new(-file=> 'bl2seq.out','-format' => 'bl2seq'); | ||||||||||
| 60 | $aln = $str->next_aln(); | ||||||||||
| 61 | |||||||||||
| 62 | =head1 FEEDBACK | ||||||||||
| 63 | |||||||||||
| 64 | =head2 Mailing Lists | ||||||||||
| 65 | |||||||||||
| 66 | User feedback is an integral part of the evolution of this and other | ||||||||||
| 67 | Bioperl modules. Send your comments and suggestions preferably to one | ||||||||||
| 68 | of the Bioperl mailing lists. Your participation is much appreciated. | ||||||||||
| 69 | |||||||||||
| 70 | bioperl-l@bioperl.org - General discussion | ||||||||||
| 71 | http://bioperl.org/wiki/Mailing_lists - About the mailing lists | ||||||||||
| 72 | |||||||||||
| 73 | =head2 Support | ||||||||||
| 74 | |||||||||||
| 75 | Please direct usage questions or support issues to the mailing list: | ||||||||||
| 76 | |||||||||||
| 77 | I<bioperl-l@bioperl.org> | ||||||||||
| 78 | |||||||||||
| 79 | rather than to the module maintainer directly. Many experienced and | ||||||||||
| 80 | reponsive experts will be able look at the problem and quickly | ||||||||||
| 81 | address it. Please include a thorough description of the problem | ||||||||||
| 82 | with code and data examples if at all possible. | ||||||||||
| 83 | |||||||||||
| 84 | =head2 Reporting Bugs | ||||||||||
| 85 | |||||||||||
| 86 | Report bugs to the Bioperl bug tracking system to help us keep track | ||||||||||
| 87 | the bugs and their resolution. Bug reports can be submitted via the | ||||||||||
| 88 | web: | ||||||||||
| 89 | |||||||||||
| 90 | https://github.com/bioperl/bioperl-live/issues | ||||||||||
| 91 | |||||||||||
| 92 | =head1 AUTHOR - Peter Schattner | ||||||||||
| 93 | |||||||||||
| 94 | Email: schattner@alum.mit.edu | ||||||||||
| 95 | |||||||||||
| 96 | =head1 APPENDIX | ||||||||||
| 97 | |||||||||||
| 98 | The rest of the documentation details each of the object | ||||||||||
| 99 | methods. Internal methods are usually preceded with a _ | ||||||||||
| 100 | |||||||||||
| 101 | =cut | ||||||||||
| 102 | |||||||||||
| 103 | # Let the code begin... | ||||||||||
| 104 | |||||||||||
| 105 | package Bio::AlignIO::bl2seq; | ||||||||||
| 106 | 2 | $Bio::AlignIO::bl2seq::VERSION = '1.7.8'; | |||||||||
| 107 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 108 | |||||||||||
| 109 | 2 | ▶ | use Bio::SearchIO; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 110 | |||||||||||
| 111 | 2 | ▶ | use base qw(Bio::AlignIO); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 112 | |||||||||||
| 113 | =head2 new | ||||||||||
| 114 | |||||||||||
| 115 | Title : new | ||||||||||
| 116 | Usage : my $alignio = Bio::SimpleAlign->new(-format => 'bl2seq', | ||||||||||
| 117 | -file => 'filename', | ||||||||||
| 118 | -report_type => 'blastx'); | ||||||||||
| 119 | Function: Get a L<Bio::SimpleAlign> | ||||||||||
| 120 | Returns : L<Bio::SimpleAlign> object | ||||||||||
| 121 | Args : -report_type => report type (blastn,blastx,tblastx,tblastn,blastp) | ||||||||||
| 122 | |||||||||||
| 123 | =cut | ||||||||||
| 124 | |||||||||||
| 125 | 2 | ▶ | sub _initialize { | ||||||||
|
Subroutine
_initialize: called CC=2 SCAR=6.9
| |||||||||||
| 126 | 2 | my ($self, @args) = @_; | |||||||||
| 127 | 2 | $self->SUPER::_initialize(@args); | |||||||||
| 128 | 2 | my ($rt) = $self->_rearrange([qw(REPORT_TYPE)],@args); | |||||||||
| 129 | 2 | ▶ | defined $rt && $self->report_type($rt); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 130 | } | ||||||||||
| 131 | |||||||||||
| 132 | =head2 next_aln | ||||||||||
| 133 | |||||||||||
| 134 | Title : next_aln | ||||||||||
| 135 | Usage : $aln = $stream->next_aln() | ||||||||||
| 136 | Function: returns the next alignment in the stream. | ||||||||||
| 137 | Returns : L<Bio::Align::AlignI> object on success, | ||||||||||
| 138 | undef on error or end of file | ||||||||||
| 139 | Args : none | ||||||||||
| 140 | |||||||||||
| 141 | =cut | ||||||||||
| 142 | |||||||||||
| 143 | 2 | ▶ | sub next_aln { | ||||||||
|
Subroutine
next_aln: called CC=8 SCAR=23.9
Pod
documented
| |||||||||||
| 144 | 2 | my $self = shift; | |||||||||
| 145 | 2 | ▶ | unless (exists $self->{'_searchio'}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 146 | 2 | $self->{'_searchio'} = Bio::SearchIO->new(-fh => $self->_fh, | |||||||||
| 147 | -format => 'blast', | ||||||||||
| 148 | -report_type => $self->report_type); | ||||||||||
| 149 | } | ||||||||||
| 150 | 2 | while (1) { | |||||||||
| 151 | 2 | ▶ | if (!exists $self->{'_result'}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 152 | 2 | $self->{'_result'} = $self->{'_searchio'}->next_result; | |||||||||
| 153 | } | ||||||||||
| 154 | 2 | ▶ | return if !defined $self->{'_result'}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 155 | 2 | ▶ | if (!exists $self->{'_hit'}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 156 | 2 | $self->{'_hit'} = $self->{'_result'}->next_hit; | |||||||||
| 157 | } | ||||||||||
| 158 | # out of hits for this result? | ||||||||||
| 159 | 2 | ▶ | if (!defined $self->{'_hit'}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 160 | 0 | delete $self->{'_result'}; | |||||||||
| 161 | 0 | next; | |||||||||
| 162 | } | ||||||||||
| 163 | 2 | my $hsp = $self->{'_hit'}->next_hsp; | |||||||||
| 164 | # out of hsps for this hit? | ||||||||||
| 165 | 2 | ▶ | if (!defined $hsp) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 166 | 0 | delete $self->{'_hit'}; | |||||||||
| 167 | 0 | next; | |||||||||
| 168 | } | ||||||||||
| 169 | 2 | ▶ | $hsp ? return $hsp->get_aln: return; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 170 | } | ||||||||||
| 171 | } | ||||||||||
| 172 | |||||||||||
| 173 | |||||||||||
| 174 | =head2 write_aln (NOT IMPLEMENTED) | ||||||||||
| 175 | |||||||||||
| 176 | Title : write_aln | ||||||||||
| 177 | Usage : $stream->write_aln(@aln) | ||||||||||
| 178 | Function: writes the $aln object into the stream in bl2seq format | ||||||||||
| 179 | Returns : 1 for success and 0 for error | ||||||||||
| 180 | Args : L<Bio::Align::AlignI> object | ||||||||||
| 181 | |||||||||||
| 182 | |||||||||||
| 183 | =cut | ||||||||||
| 184 | |||||||||||
| 185 | 0 | ▶ | sub write_aln { | ||||||||
|
Subroutine
write_aln: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 186 | 0 | my ($self,@aln) = @_; | |||||||||
| 187 | 0 | $self->throw_not_implemented(); | |||||||||
| 188 | } | ||||||||||
| 189 | |||||||||||
| 190 | =head2 report_type | ||||||||||
| 191 | |||||||||||
| 192 | Title : report_type | ||||||||||
| 193 | Usage : $obj->report_type($newval) | ||||||||||
| 194 | Function: Sets the report type (blastn, blastp...) | ||||||||||
| 195 | Returns : value of report_type (a scalar) | ||||||||||
| 196 | Args : on set, new value (a scalar or undef, optional) | ||||||||||
| 197 | |||||||||||
| 198 | |||||||||||
| 199 | =cut | ||||||||||
| 200 | |||||||||||
| 201 | 3 | ▶ | sub report_type{ | ||||||||
|
Subroutine
report_type: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 202 | 3 | my $self = shift; | |||||||||
| 203 | 3 | ▶ | return $self->{'report_type'} = shift if @_; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 204 | 2 | return $self->{'report_type'}; | |||||||||
| 205 | } | ||||||||||
| 206 | |||||||||||
| 207 | 2 | 1; | |||||||||