| 1 | # | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # BioPerl module for Bio::SeqIO::ace | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # Please direct questions and support issues to <bioperl-l@bioperl.org> | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||||||||||||||||
| 6 | # Cared for by James Gilbert <jgrg@sanger.ac.uk> | ||||||||||||||||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||||||||||||||||
| 8 | # You may distribute this module under the same terms as perl itself | ||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | # POD documentation - main docs before the code | ||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | Bio::SeqIO::ace - ace sequence input/output stream | ||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | Do not use this module directly. Use it via the Bio::SeqIO class. | ||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | This object can transform Bio::Seq objects to and | ||||||||||||||||||||||||||||||||||||||||||
| 23 | from ace file format. It only parses a DNA or | ||||||||||||||||||||||||||||||||||||||||||
| 24 | Peptide objects contained in the ace file, | ||||||||||||||||||||||||||||||||||||||||||
| 25 | producing PrimarySeq objects from them. All | ||||||||||||||||||||||||||||||||||||||||||
| 26 | other objects in the files will be ignored. It | ||||||||||||||||||||||||||||||||||||||||||
| 27 | doesn't attempt to parse any annotation attached | ||||||||||||||||||||||||||||||||||||||||||
| 28 | to the containing Sequence or Protein objects, | ||||||||||||||||||||||||||||||||||||||||||
| 29 | which would probably be impossible, since | ||||||||||||||||||||||||||||||||||||||||||
| 30 | everyone's ACeDB schema can be different. | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | It won't parse ace files containing Timestamps | ||||||||||||||||||||||||||||||||||||||||||
| 33 | correctly either. This can easily be added if | ||||||||||||||||||||||||||||||||||||||||||
| 34 | considered necessary. | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | =head1 FEEDBACK | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | =head2 Mailing Lists | ||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | User feedback is an integral part of the evolution of this and other | ||||||||||||||||||||||||||||||||||||||||||
| 41 | Bioperl modules. Send your comments and suggestions preferably to one | ||||||||||||||||||||||||||||||||||||||||||
| 42 | of the Bioperl mailing lists. Your participation is much appreciated. | ||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | bioperl-l@bioperl.org - General discussion | ||||||||||||||||||||||||||||||||||||||||||
| 45 | http://bioperl.org/wiki/Mailing_lists - About the mailing lists | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | =head2 Support | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | Please direct usage questions or support issues to the mailing list: | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | I<bioperl-l@bioperl.org> | ||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | rather than to the module maintainer directly. Many experienced and | ||||||||||||||||||||||||||||||||||||||||||
| 54 | reponsive experts will be able look at the problem and quickly | ||||||||||||||||||||||||||||||||||||||||||
| 55 | address it. Please include a thorough description of the problem | ||||||||||||||||||||||||||||||||||||||||||
| 56 | with code and data examples if at all possible. | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | =head2 Reporting Bugs | ||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | Report bugs to the Bioperl bug tracking system to help us keep track | ||||||||||||||||||||||||||||||||||||||||||
| 61 | the bugs and their resolution. | ||||||||||||||||||||||||||||||||||||||||||
| 62 | Bug reports can be submitted via the web: | ||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | https://github.com/bioperl/bioperl-live/issues | ||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | =head1 AUTHORS - James Gilbert | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | Email: jgrg@sanger.ac.uk | ||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | =head1 APPENDIX | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | The rest of the documentation details each of the object | ||||||||||||||||||||||||||||||||||||||||||
| 73 | methods. Internal methods are usually preceded with a _ | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | #' | ||||||||||||||||||||||||||||||||||||||||||
| 78 | # Let the code begin... | ||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | package Bio::SeqIO::ace; | ||||||||||||||||||||||||||||||||||||||||||
| 81 | 3 | $Bio::SeqIO::ace::VERSION = '1.7.8'; | |||||||||||||||||||||||||||||||||||||||||
| 82 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 3 | ▶ | use Bio::Seq; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 3 | ▶ | use Bio::Seq::SeqFactory; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | 3 | ▶ | use base qw(Bio::SeqIO); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 4 | ▶ | sub _initialize { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_initialize: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 4 | my($self,@args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 91 | 4 | $self->SUPER::_initialize(@args); | |||||||||||||||||||||||||||||||||||||||||
| 92 | 4 | ▶ | if( ! defined $self->sequence_factory ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | 4 | $self->sequence_factory(Bio::Seq::SeqFactory->new(-verbose => $self->verbose(), -type => 'Bio::PrimarySeq')); | |||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | =head2 next_seq | ||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | Title : next_seq | ||||||||||||||||||||||||||||||||||||||||||
| 100 | Usage : $seq = $stream->next_seq() | ||||||||||||||||||||||||||||||||||||||||||
| 101 | Function: returns the next sequence in the stream | ||||||||||||||||||||||||||||||||||||||||||
| 102 | Returns : Bio::Seq object | ||||||||||||||||||||||||||||||||||||||||||
| 103 | Args : NONE | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | { | ||||||||||||||||||||||||||||||||||||||||||
| 108 | 3 | my %bio_mol_type = ( | |||||||||||||||||||||||||||||||||||||||||
| 109 | 'dna' => 'dna', | ||||||||||||||||||||||||||||||||||||||||||
| 110 | 'peptide' => 'protein', | ||||||||||||||||||||||||||||||||||||||||||
| 111 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | 6 | ▶ | sub next_seq { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
next_seq: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 6 | my( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 115 | 6 | local $/ = ""; # Split input on blank lines | |||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | 6 | my $fh = $self->_filehandle; | |||||||||||||||||||||||||||||||||||||||||
| 118 | 6 | my( $type, $id ); | |||||||||||||||||||||||||||||||||||||||||
| 119 | 6 | ▶ | while (<$fh>) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | 10 | ▶ | if (($type, $id) = /^(DNA|Peptide)[\s:]+(.+?)\s*\n/si) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | 5 | s/^.+$//m; # Remove first line | |||||||||||||||||||||||||||||||||||||||||
| 122 | 5 | s/\s+//g; # Remove whitespace | |||||||||||||||||||||||||||||||||||||||||
| 123 | 5 | last; | |||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||
| 126 | # Return if there weren't any DNA or peptide objects | ||||||||||||||||||||||||||||||||||||||||||
| 127 | 6 | ▶ | return unless $type; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | # Choose the molecule type | ||||||||||||||||||||||||||||||||||||||||||
| 130 | 5 | ▶ | my $mol_type = $bio_mol_type{lc $type} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | or $self->throw("Can't get Bio::Seq molecule type for '$type'"); | ||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | # Remove quotes from $id | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 5 | $id =~ s/^"|"$//g; | |||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | # Un-escape forward slashes, double quotes, percent signs, | ||||||||||||||||||||||||||||||||||||||||||
| 137 | # semi-colons, tabs, and backslashes (if you're mad enough | ||||||||||||||||||||||||||||||||||||||||||
| 138 | # to have any of these as part of object names in your acedb | ||||||||||||||||||||||||||||||||||||||||||
| 139 | # database). | ||||||||||||||||||||||||||||||||||||||||||
| 140 | 5 | $id =~ s/\\([\/"%;\t\\])/$1/g; | |||||||||||||||||||||||||||||||||||||||||
| 141 | #" | ||||||||||||||||||||||||||||||||||||||||||
| 142 | # Called as next_seq(), so give back a Bio::Seq | ||||||||||||||||||||||||||||||||||||||||||
| 143 | 5 | return $self->sequence_factory->create( | |||||||||||||||||||||||||||||||||||||||||
| 144 | -seq => $_, | ||||||||||||||||||||||||||||||||||||||||||
| 145 | -primary_id => $id, | ||||||||||||||||||||||||||||||||||||||||||
| 146 | -display_id => $id, | ||||||||||||||||||||||||||||||||||||||||||
| 147 | -alphabet => $mol_type, | ||||||||||||||||||||||||||||||||||||||||||
| 148 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | =head2 write_seq | ||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | Title : write_seq | ||||||||||||||||||||||||||||||||||||||||||
| 155 | Usage : $stream->write_seq(@seq) | ||||||||||||||||||||||||||||||||||||||||||
| 156 | Function: writes the $seq object into the stream | ||||||||||||||||||||||||||||||||||||||||||
| 157 | Returns : 1 for success and 0 for error | ||||||||||||||||||||||||||||||||||||||||||
| 158 | Args : Bio::Seq object(s) | ||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | 3 | ▶ | sub write_seq { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write_seq: called CC=10 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | 4 | my ($self, @seq) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | 4 | foreach my $seq (@seq) { | |||||||||||||||||||||||||||||||||||||||||
| 167 | 4 | ▶ | $self->throw("Did not provide a valid Bio::PrimarySeqI object") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $seq and ref $seq and $seq->isa("Bio::PrimarySeqI")
defined $seq and ref $seq
MC/DC0%0/3
defined $seq and ref $seq and $seq->isa("Bio::PrimarySeqI")
defined $seq
ref $seq
$seq->isa("Bio::PrimarySeqI")
Truth table25%1/4
A and B and C
A= defined $seqB= ref $seqC= $seq->isa("Bio::PrimarySeqI")
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | unless defined $seq && ref($seq) && $seq->isa('Bio::PrimarySeqI'); | ||||||||||||||||||||||||||||||||||||||||||
| 169 | 4 | my $mol_type = $seq->alphabet; | |||||||||||||||||||||||||||||||||||||||||
| 170 | 4 | my $id = $seq->display_id; | |||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | # Escape special charachers in id | ||||||||||||||||||||||||||||||||||||||||||
| 173 | 4 | $id =~ s/([\/"%;\t\\])/\\$1/g; | |||||||||||||||||||||||||||||||||||||||||
| 174 | #" | ||||||||||||||||||||||||||||||||||||||||||
| 175 | # Print header for DNA or Protein object | ||||||||||||||||||||||||||||||||||||||||||
| 176 | 4 | ▶ | if ($mol_type eq 'dna') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 177 | 3 | $self->_print( | |||||||||||||||||||||||||||||||||||||||||
| 178 | qq{\nSequence : "$id"\nDNA "$id"\n}, | ||||||||||||||||||||||||||||||||||||||||||
| 179 | qq{\nDNA : "$id"\n}, | ||||||||||||||||||||||||||||||||||||||||||
| 180 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||
| 182 | elsif ($mol_type eq 'protein') { | ||||||||||||||||||||||||||||||||||||||||||
| 183 | 1 | $self->_print( | |||||||||||||||||||||||||||||||||||||||||
| 184 | qq{\nProtein : "$id"\nPeptide "$id"\n}, | ||||||||||||||||||||||||||||||||||||||||||
| 185 | qq{\nPeptide : "$id"\n}, | ||||||||||||||||||||||||||||||||||||||||||
| 186 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||
| 188 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | $self->throw("Don't know how to produce ACeDB output for '$mol_type'"); | |||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||
| 192 | # Print the sequence | ||||||||||||||||||||||||||||||||||||||||||
| 193 | 4 | my $str = $seq->seq; | |||||||||||||||||||||||||||||||||||||||||
| 194 | 4 | my( $formatted_seq ); | |||||||||||||||||||||||||||||||||||||||||
| 195 | 4 | ▶ | while ($str =~ /(.{1,60})/g) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | 21 | $formatted_seq .= "$1\n"; | |||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||
| 198 | 4 | $self->_print($formatted_seq, "\n"); | |||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | 4 | ▶ | $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
| |||||||||||||||||||||||||||||||||||||||||||
| 202 | 4 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||
| 205 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||