| 1 | # | ||||||||||||||||||||||||||||
| 2 | # BioPerl module for Bio::AlignIO::selex | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | # based on the Bio::SeqIO::selex 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 Peter Schattner | ||||||||||||||||||||||||||||
| 11 | # | ||||||||||||||||||||||||||||
| 12 | # You may distribute this module under the same terms as perl itself | ||||||||||||||||||||||||||||
| 13 | # _history | ||||||||||||||||||||||||||||
| 14 | # September 5, 2000 | ||||||||||||||||||||||||||||
| 15 | # POD documentation - main docs before the code | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | =head1 NAME | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | Bio::AlignIO::selex - selex sequence input/output stream | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | # Do not use this module directly. Use it via the L<Bio::AlignIO> class. | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | use Bio::AlignIO; | ||||||||||||||||||||||||||||
| 26 | use strict; | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | my $in = Bio::AlignIO->new(-format => 'selex', | ||||||||||||||||||||||||||||
| 29 | -file => 't/data/testaln.selex'); | ||||||||||||||||||||||||||||
| 30 | while( my $aln = $in->next_aln ) { | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | This object can transform L<Bio::Align::AlignI> objects to and from selex flat | ||||||||||||||||||||||||||||
| 37 | file databases. | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | =head1 FEEDBACK | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | =head2 Support | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | Please direct usage questions or support issues to the mailing list: | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | I<bioperl-l@bioperl.org> | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | rather than to the module maintainer directly. Many experienced and | ||||||||||||||||||||||||||||
| 48 | reponsive experts will be able look at the problem and quickly | ||||||||||||||||||||||||||||
| 49 | address it. Please include a thorough description of the problem | ||||||||||||||||||||||||||||
| 50 | with code and data examples if at all possible. | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | =head2 Reporting Bugs | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | Report bugs to the Bioperl bug tracking system to help us keep track | ||||||||||||||||||||||||||||
| 55 | the bugs and their resolution. Bug reports can be submitted via the | ||||||||||||||||||||||||||||
| 56 | web: | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | https://github.com/bioperl/bioperl-live/issues | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | =head1 AUTHORS - Peter Schattner | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | Email: schattner@alum.mit.edu | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | =head1 CONTRIBUTORS | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | Jason Stajich, jason-at-bioperl.org | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | =head1 APPENDIX | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | The rest of the documentation details each of the object | ||||||||||||||||||||||||||||
| 71 | methods. Internal methods are usually preceded with a _ | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | =cut | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | # Let the code begin... | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | package Bio::AlignIO::selex; | ||||||||||||||||||||||||||||
| 78 | 3 | $Bio::AlignIO::selex::VERSION = '1.7.8'; | |||||||||||||||||||||||||||
| 79 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 3 | ▶ | use base qw(Bio::AlignIO); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | =head2 next_aln | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | Title : next_aln | ||||||||||||||||||||||||||||
| 86 | Usage : $aln = $stream->next_aln() | ||||||||||||||||||||||||||||
| 87 | Function: returns the next alignment in the stream. Tries to read *all* selex | ||||||||||||||||||||||||||||
| 88 | It reads all non whitespace characters in the alignment | ||||||||||||||||||||||||||||
| 89 | area. For selexs with weird gaps (eg ~~~) map them by using | ||||||||||||||||||||||||||||
| 90 | $al->map_chars('~','-') | ||||||||||||||||||||||||||||
| 91 | Returns : L<Bio::Align::AlignI> object | ||||||||||||||||||||||||||||
| 92 | Args : NONE | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | =cut | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 10 | ▶ | sub next_aln { | ||||||||||||||||||||||||||
|
Subroutine
next_aln: called CC=9 SCAR=23.8
Pod
documented
| |||||||||||||||||||||||||||||
| 97 | 10 | my $self = shift; | |||||||||||||||||||||||||||
| 98 | 10 | my $entry; | |||||||||||||||||||||||||||
| 99 | 10 | my ($start,$end,%align,$name,$seqname,%hash,@c2name, %accession,%desc); | |||||||||||||||||||||||||||
| 100 | 10 | my $aln = Bio::SimpleAlign->new(-source => 'selex'); | |||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | # in selex format, every non-blank line that does not start | ||||||||||||||||||||||||||||
| 103 | # with '#=' is an alignment segment; the '#=' lines are mark up lines. | ||||||||||||||||||||||||||||
| 104 | # Of particular interest are the '#=GF <name/st-ed> AC <accession>' | ||||||||||||||||||||||||||||
| 105 | # lines, which give accession numbers for each segment | ||||||||||||||||||||||||||||
| 106 | 10 | ▶ | while( $entry = $self->_readline) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | 1250 | ▶ | if( $entry =~ /^\#=GS\s+(\S+)\s+AC\s+(\S+)/ ) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 108 | 0 | $accession{ $1 } = $2; | |||||||||||||||||||||||||||
| 109 | 0 | next; | |||||||||||||||||||||||||||
| 110 | } elsif( $entry =~ /^\#=GS\s+(\S+)\s+DE\s+(.+)\s*$/ ) { | ||||||||||||||||||||||||||||
| 111 | 0 | $desc{$1} .= $2; | |||||||||||||||||||||||||||
| 112 | } elsif ( $entry =~ /^([^\#]\S+)\s+([A-Za-z\.\-\*]+)\s*/ ) { | ||||||||||||||||||||||||||||
| 113 | 520 | my ($name,$seq) = ($1,$2); | |||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 520 | ▶ | if( ! defined $align{$name} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | 20 | push @c2name, $name; | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | 520 | $align{$name} .= $seq; | |||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | # ok... now we can make the sequences | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 10 | foreach my $name ( @c2name ) { | |||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 20 | ▶ | if( $name =~ /(\S+)\/(\d+)-(\d+)/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | 0 | $seqname = $1; | |||||||||||||||||||||||||||
| 127 | 0 | $start = $2; | |||||||||||||||||||||||||||
| 128 | 0 | $end = $3; | |||||||||||||||||||||||||||
| 129 | } else { | ||||||||||||||||||||||||||||
| 130 | 20 | $seqname=$name; | |||||||||||||||||||||||||||
| 131 | 20 | $start = 1; | |||||||||||||||||||||||||||
| 132 | 20 | $end = length($align{$name}); | |||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | my $seq = Bio::LocatableSeq->new | ||||||||||||||||||||||||||||
| 135 | ('-seq' => $align{$name}, | ||||||||||||||||||||||||||||
| 136 | '-display_id' => $seqname, | ||||||||||||||||||||||||||||
| 137 | '-start' => $start, | ||||||||||||||||||||||||||||
| 138 | '-end' => $end, | ||||||||||||||||||||||||||||
| 139 | '-description' => $desc{$name}, | ||||||||||||||||||||||||||||
| 140 | 20 | '-accession_number' => $accession{$name}, | |||||||||||||||||||||||||||
| 141 | '-alphabet' => $self->alphabet, | ||||||||||||||||||||||||||||
| 142 | ); | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 20 | $aln->add_seq($seq); | |||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 10 | ▶ | return $aln if $aln->num_sequences; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 148 | 0 | return; | |||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | =head2 write_aln | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | Title : write_aln | ||||||||||||||||||||||||||||
| 155 | Usage : $stream->write_aln(@aln) | ||||||||||||||||||||||||||||
| 156 | Function: writes the $aln object into the stream in selex format | ||||||||||||||||||||||||||||
| 157 | Returns : 1 for success and 0 for error | ||||||||||||||||||||||||||||
| 158 | Args : L<Bio::Align::AlignI> object | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | =cut | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | 2 | ▶ | sub write_aln { | ||||||||||||||||||||||||||
|
Subroutine
write_aln: called CC=6 SCAR=18.5
Pod
documented
| |||||||||||||||||||||||||||||
| 164 | 2 | my ($self,@aln) = @_; | |||||||||||||||||||||||||||
| 165 | 2 | my ($namestr,$seq,$add); | |||||||||||||||||||||||||||
| 166 | 2 | my ($maxn); | |||||||||||||||||||||||||||
| 167 | 2 | foreach my $aln (@aln) { | |||||||||||||||||||||||||||
| 168 | 2 | $maxn = $aln->maxdisplayname_length(); | |||||||||||||||||||||||||||
| 169 | 2 | foreach $seq ( $aln->each_seq() ) { | |||||||||||||||||||||||||||
| 170 | 8 | $namestr = $aln->displayname($seq->get_nse()); | |||||||||||||||||||||||||||
| 171 | 8 | $add = $maxn - length($namestr) + 2; | |||||||||||||||||||||||||||
| 172 | 8 | $namestr .= " " x $add; | |||||||||||||||||||||||||||
| 173 | 8 | ▶ | $self->_print (sprintf("%s %s\n",$namestr,$seq->seq())) or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||
| 176 | 2 | ▶ | $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
| |||||||||||||||||||||||||||||
| 177 | 2 | return 1; | |||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | 3 | 1; | |||||||||||||||||||||||||||