| 1 | # | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # BioPerl module for Bio::AlignIO::psi | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # Please direct questions and support issues to <bioperl-l@bioperl.org> | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||||||||||||||||
| 6 | # Cared for by Jason Stajich <jason@bioperl.org> | ||||||||||||||||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||||||||||||||||
| 8 | # Copyright Jason Stajich | ||||||||||||||||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||||||||||||||||
| 10 | # You may distribute this module under the same terms as perl itself | ||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | # POD documentation - main docs before the code | ||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | Bio::AlignIO::psi - Read/Write PSI-BLAST profile alignment files | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | This module will parse PSI-BLAST output of the format seqid XXXX | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | This is a parser for psi-blast blocks. | ||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | =head1 FEEDBACK | ||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | =head2 Mailing Lists | ||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | User feedback is an integral part of the evolution of this and other | ||||||||||||||||||||||||||||||||||||||||||
| 31 | Bioperl modules. Send your comments and suggestions preferably to | ||||||||||||||||||||||||||||||||||||||||||
| 32 | the Bioperl mailing list. Your participation is much appreciated. | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | bioperl-l@bioperl.org - General discussion | ||||||||||||||||||||||||||||||||||||||||||
| 35 | http://bioperl.org/wiki/Mailing_lists - About the mailing lists | ||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | =head2 Support | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | Please direct usage questions or support issues to the mailing list: | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | I<bioperl-l@bioperl.org> | ||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | rather than to the module maintainer directly. Many experienced and | ||||||||||||||||||||||||||||||||||||||||||
| 44 | reponsive experts will be able look at the problem and quickly | ||||||||||||||||||||||||||||||||||||||||||
| 45 | address it. Please include a thorough description of the problem | ||||||||||||||||||||||||||||||||||||||||||
| 46 | with code and data examples if at all possible. | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | =head2 Reporting Bugs | ||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | Report bugs to the Bioperl bug tracking system to help us keep track | ||||||||||||||||||||||||||||||||||||||||||
| 51 | of the bugs and their resolution. Bug reports can be submitted via | ||||||||||||||||||||||||||||||||||||||||||
| 52 | the web: | ||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | https://github.com/bioperl/bioperl-live/issues | ||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | =head1 AUTHOR - Jason Stajich | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | Email jason@bioperl.org | ||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | =head1 APPENDIX | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | The rest of the documentation details each of the object methods. | ||||||||||||||||||||||||||||||||||||||||||
| 63 | Internal methods are usually preceded with a _ | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | # Let the code begin... | ||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | package Bio::AlignIO::psi; | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 3 | $Bio::AlignIO::psi::VERSION = '1.7.8'; | |||||||||||||||||||||||||||||||||||||||||
| 73 | 3 | ▶ | use vars qw($BlockLen $IdLength); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 3 | $BlockLen = 100; | |||||||||||||||||||||||||||||||||||||||||
| 77 | 3 | $IdLength = 13; | |||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | # Object preamble - inherits from Bio::Root::Root | ||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | 3 | ▶ | use Bio::SimpleAlign; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | 3 | ▶ | use Bio::LocatableSeq; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 3 | ▶ | use base qw(Bio::AlignIO); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | =head2 new | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | Title : new | ||||||||||||||||||||||||||||||||||||||||||
| 89 | Usage : my $obj = Bio::AlignIO::psi->new(); | ||||||||||||||||||||||||||||||||||||||||||
| 90 | Function: Builds a new Bio::AlignIO::psi object | ||||||||||||||||||||||||||||||||||||||||||
| 91 | Returns : Bio::AlignIO::psi | ||||||||||||||||||||||||||||||||||||||||||
| 92 | Args : | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | =head2 next_aln | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | Title : next_aln | ||||||||||||||||||||||||||||||||||||||||||
| 99 | Usage : $aln = $stream->next_aln() | ||||||||||||||||||||||||||||||||||||||||||
| 100 | Function: returns the next alignment in the stream | ||||||||||||||||||||||||||||||||||||||||||
| 101 | Returns : Bio::Align::AlignI object | ||||||||||||||||||||||||||||||||||||||||||
| 102 | Args : NONE | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | See L<Bio::Align::AlignI> | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | 6 | ▶ | sub next_aln { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
next_aln: called CC=8 SCAR=21.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | 6 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 110 | 6 | my $aln; | |||||||||||||||||||||||||||||||||||||||||
| 111 | my %seqs; | ||||||||||||||||||||||||||||||||||||||||||
| 112 | 6 | my @order; | |||||||||||||||||||||||||||||||||||||||||
| 113 | 6 | ▶ | while( defined ($_ = $self->_readline ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 5466 | ▶ | next if( /^\s+$/); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | 5376 | ▶ | if( !defined $aln ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 6 | $aln = Bio::SimpleAlign->new(); | |||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||
| 118 | 5376 | my ($id,$s) = split; | |||||||||||||||||||||||||||||||||||||||||
| 119 | 5376 | ▶ | push @order, $id if( ! defined $seqs{$id}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | 5376 | $seqs{$id} .= $s; | |||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||
| 122 | 6 | foreach my $id ( @order) { | |||||||||||||||||||||||||||||||||||||||||
| 123 | 336 | my $gaps = $seqs{$id} =~ tr/-/-/; | |||||||||||||||||||||||||||||||||||||||||
| 124 | my $seq = Bio::LocatableSeq->new(-seq => $seqs{$id}, | ||||||||||||||||||||||||||||||||||||||||||
| 125 | -id => $id, | ||||||||||||||||||||||||||||||||||||||||||
| 126 | -start => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 127 | 336 | -end => length($seqs{$id}) - $gaps, | |||||||||||||||||||||||||||||||||||||||||
| 128 | -alphabet => $self->alphabet, | ||||||||||||||||||||||||||||||||||||||||||
| 129 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 130 | 336 | $aln->add_seq($seq); | |||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||
| 132 | 6 | ▶ | return $aln if defined $aln && $aln->num_sequences; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $aln and $aln->num_sequences
MC/DC0%0/2
defined $aln and $aln->num_sequences
defined $aln
$aln->num_sequences
Truth table33%1/3
A and B
A= defined $alnB= $aln->num_sequences
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | =head2 write_aln | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | Title : write_aln | ||||||||||||||||||||||||||||||||||||||||||
| 139 | Usage : $stream->write_aln(@aln) | ||||||||||||||||||||||||||||||||||||||||||
| 140 | Function: writes the NCBI psi-format object (.aln) into the stream | ||||||||||||||||||||||||||||||||||||||||||
| 141 | Returns : 1 for success and 0 for error | ||||||||||||||||||||||||||||||||||||||||||
| 142 | Args : Bio::Align::AlignI object | ||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | L<Bio::Align::AlignI> | ||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | 1 | ▶ | sub write_aln { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write_aln: called CC=9 SCAR=23.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | 1 | my ($self,$aln) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 150 | 1 | ▶ | unless( defined $aln && ref($aln) && | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $aln and ref $aln and $aln->isa("Bio::Align::AlignI")
defined $aln and ref $aln
MC/DC0%0/3
defined $aln and ref $aln and $aln->isa("Bio::Align::AlignI")
defined $aln
ref $aln
$aln->isa("Bio::Align::AlignI")
Truth table25%1/4
A and B and C
A= defined $alnB= ref $alnC= $aln->isa("Bio::Align::AlignI")
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | $aln->isa('Bio::Align::AlignI') ) { | ||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | $self->warn("Must provide a valid Bio::Align::AlignI to write_aln"); | |||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||
| 155 | 1 | my $ct = 0; | |||||||||||||||||||||||||||||||||||||||||
| 156 | 1 | my @seqs = $aln->each_seq; | |||||||||||||||||||||||||||||||||||||||||
| 157 | 1 | my $len = 1; | |||||||||||||||||||||||||||||||||||||||||
| 158 | 1 | my $alnlen = $aln->length; | |||||||||||||||||||||||||||||||||||||||||
| 159 | 1 | my $idlen = $IdLength; | |||||||||||||||||||||||||||||||||||||||||
| 160 | 1 | my @ids = map { substr($_->display_id,0,$idlen) } @seqs; | |||||||||||||||||||||||||||||||||||||||||
| 161 | 1 | ▶ | while( $len < ($alnlen + 1) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | 5 | my $start = $len; | |||||||||||||||||||||||||||||||||||||||||
| 163 | 5 | my $end = $len + $BlockLen; | |||||||||||||||||||||||||||||||||||||||||
| 164 | 5 | ▶ | $end = $alnlen if ( $end > $alnlen ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | 5 | my $c = 0; | |||||||||||||||||||||||||||||||||||||||||
| 166 | 5 | foreach my $seq ( @seqs ) { | |||||||||||||||||||||||||||||||||||||||||
| 167 | 30 | $self->_print(sprintf("%-".$idlen."s %s\n", | |||||||||||||||||||||||||||||||||||||||||
| 168 | $ids[$c++], | ||||||||||||||||||||||||||||||||||||||||||
| 169 | $seq->subseq($start,$end))); | ||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||
| 171 | 5 | $self->_print("\n"); | |||||||||||||||||||||||||||||||||||||||||
| 172 | 5 | $len += $BlockLen+1; | |||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||
| 174 | 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
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||