| 1 | # | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # BioPerl module for Bio::SeqIO::gcg | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # Please direct questions and support issues to <bioperl-l@bioperl.org> | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||||||||||||||||
| 6 | # Cared for by Ewan Birney <birney@ebi.ac.uk> | ||||||||||||||||||||||||||||||||||||||||||
| 7 | # and Lincoln Stein <lstein@cshl.org> | ||||||||||||||||||||||||||||||||||||||||||
| 8 | # | ||||||||||||||||||||||||||||||||||||||||||
| 9 | # Copyright Ewan Birney & Lincoln Stein | ||||||||||||||||||||||||||||||||||||||||||
| 10 | # | ||||||||||||||||||||||||||||||||||||||||||
| 11 | # You may distribute this module under the same terms as perl itself | ||||||||||||||||||||||||||||||||||||||||||
| 12 | # | ||||||||||||||||||||||||||||||||||||||||||
| 13 | # _history | ||||||||||||||||||||||||||||||||||||||||||
| 14 | # October 18, 1999 Largely rewritten by Lincoln Stein | ||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | # POD documentation - main docs before the code | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | Bio::SeqIO::gcg - GCG sequence input/output stream | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | Do not use this module directly. Use it via the Bio::SeqIO class. | ||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | This object can transform Bio::Seq objects to and from GCG flat | ||||||||||||||||||||||||||||||||||||||||||
| 29 | file databases. | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | =head1 FEEDBACK | ||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | =head2 Mailing Lists | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | User feedback is an integral part of the evolution of this and other | ||||||||||||||||||||||||||||||||||||||||||
| 36 | Bioperl modules. Send your comments and suggestions preferably to one | ||||||||||||||||||||||||||||||||||||||||||
| 37 | of the Bioperl mailing lists. Your participation is much appreciated. | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | bioperl-l@bioperl.org - General discussion | ||||||||||||||||||||||||||||||||||||||||||
| 40 | http://bioperl.org/wiki/Mailing_lists - About the mailing lists | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | =head2 Support | ||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | Please direct usage questions or support issues to the mailing list: | ||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | I<bioperl-l@bioperl.org> | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | rather than to the module maintainer directly. Many experienced and | ||||||||||||||||||||||||||||||||||||||||||
| 49 | reponsive experts will be able look at the problem and quickly | ||||||||||||||||||||||||||||||||||||||||||
| 50 | address it. Please include a thorough description of the problem | ||||||||||||||||||||||||||||||||||||||||||
| 51 | with code and data examples if at all possible. | ||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | =head2 Reporting Bugs | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | Report bugs to the Bioperl bug tracking system to help us keep track | ||||||||||||||||||||||||||||||||||||||||||
| 56 | the bugs and their resolution. Bug reports can be submitted via the web: | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | https://github.com/bioperl/bioperl-live/issues | ||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | =head1 AUTHORS - Ewan Birney & Lincoln Stein | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | Email: E<lt>birney@ebi.ac.ukE<gt> | ||||||||||||||||||||||||||||||||||||||||||
| 63 | E<lt>lstein@cshl.orgE<gt> | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | =head1 CONTRIBUTORS | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | Jason Stajich, jason@bioperl.org | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | =head1 APPENDIX | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | The rest of the documentation details each of the object | ||||||||||||||||||||||||||||||||||||||||||
| 72 | methods. Internal methods are usually preceded with a _ | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | # Let the code begin... | ||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | package Bio::SeqIO::gcg; | ||||||||||||||||||||||||||||||||||||||||||
| 79 | 6 | $Bio::SeqIO::gcg::VERSION = '1.7.8'; | |||||||||||||||||||||||||||||||||||||||||
| 80 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 6 | ▶ | use Bio::Seq::SeqFactory; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 6 | ▶ | use base qw(Bio::SeqIO); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 8 | ▶ | sub _initialize { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_initialize: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 8 | my($self,@args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 88 | 8 | $self->SUPER::_initialize(@args); | |||||||||||||||||||||||||||||||||||||||||
| 89 | 8 | ▶ | if( ! defined $self->sequence_factory ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 8 | $self->sequence_factory(Bio::Seq::SeqFactory->new | |||||||||||||||||||||||||||||||||||||||||
| 91 | (-verbose => $self->verbose(), | ||||||||||||||||||||||||||||||||||||||||||
| 92 | -type => 'Bio::Seq::RichSeq')); | ||||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | =head2 next_seq | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | Title : next_seq | ||||||||||||||||||||||||||||||||||||||||||
| 99 | Usage : $seq = $stream->next_seq() | ||||||||||||||||||||||||||||||||||||||||||
| 100 | Function: returns the next sequence in the stream | ||||||||||||||||||||||||||||||||||||||||||
| 101 | Returns : Bio::Seq object | ||||||||||||||||||||||||||||||||||||||||||
| 102 | Args : | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | 7 | ▶ | sub next_seq { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
next_seq: called CC=18 SCAR=30.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | 7 | my ($self,@args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 108 | 7 | my($id,$type,$desc,$line,$chksum,$sequence,$date,$len); | |||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | 7 | ▶ | while( defined($_ = $self->_readline()) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | ## Get the descriptive info (anything before the line with '..') | ||||||||||||||||||||||||||||||||||||||||||
| 113 | 13 | ▶ | unless( /\.\.$/ ) { $desc.= $_; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | ## Pull ID, Checksum & Type from the line containing '..' | ||||||||||||||||||||||||||||||||||||||||||
| 115 | 13 | ▶ | /\.\.$/ && do { $line = $_; chomp; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 5 | ▶ | if(/Check\:\s(\d+)\s/) { $chksum = $1; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 5 | ▶ | if(/Type:\s(\w)\s/) { $type = $1; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | 5 | ▶ | if(/(\S+)\s+Length/) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | 5 | { $id = $1; } | |||||||||||||||||||||||||||||||||||||||||
| 120 | 5 | ▶ | if(/Length:\s+(\d+)\s+(\S.+\S)\s+Type/ ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | 5 | { $len = $1; $date = $2;} | |||||||||||||||||||||||||||||||||||||||||
| 122 | 5 | last; | |||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||
| 125 | 7 | ▶ | return if ( !defined $_); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 5 | chomp($desc); # remove last "\n" | |||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | 5 | ▶ | while( defined($_ = $self->_readline()) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | ## This is where we grab the sequence info. | ||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | 70 | ▶ | if( /\.\.$/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | $self->throw("Looks like start of another sequence. See documentation. "); | |||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | 70 | ▶ | next if($_ eq "\n"); ## skip whitespace lines in formatted seq | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | 35 | s/[\d\s\t]//g; ## remove anything that is not alphabet char: preserve anything that is not explicitly specified for removal (Stefan Kirov) | |||||||||||||||||||||||||||||||||||||||||
| 138 | # $_ = uc($_); ## uppercase sequence: NO. Keep the case. HL | ||||||||||||||||||||||||||||||||||||||||||
| 139 | 35 | $sequence .= $_; | |||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||
| 141 | ##If we parsed out a checksum, we might as well test it | ||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | 5 | ▶ | if(defined $chksum) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | 5 | ▶ | unless(_validate_checksum(uc($sequence),$chksum)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | $self->throw("Checksum failure on parsed sequence."); | |||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | ## Remove whitespace from identifier because the constructor | ||||||||||||||||||||||||||||||||||||||||||
| 150 | ## will throw a warning otherwise... | ||||||||||||||||||||||||||||||||||||||||||
| 151 | 5 | ▶ | if(defined $id) { $id =~ s/\s+//g;} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | ## Turn our parsed "Type: N" or "Type: P" (if found) into the appropriate | ||||||||||||||||||||||||||||||||||||||||||
| 154 | ## keyword that the constructor expects... | ||||||||||||||||||||||||||||||||||||||||||
| 155 | 5 | ▶ | if(defined $type) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | ▶ | if($type eq "N") { $type = "dna"; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | 5 | ▶ | if($type eq "P") { $type = "prot"; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | 5 | return $self->sequence_factory->create(-seq => $sequence, | |||||||||||||||||||||||||||||||||||||||||
| 161 | -id => $id, | ||||||||||||||||||||||||||||||||||||||||||
| 162 | -desc => $desc, | ||||||||||||||||||||||||||||||||||||||||||
| 163 | -type => $type, | ||||||||||||||||||||||||||||||||||||||||||
| 164 | -dates => [ $date ] | ||||||||||||||||||||||||||||||||||||||||||
| 165 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||
| 168 | =head2 write_seq | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | Title : write_seq | ||||||||||||||||||||||||||||||||||||||||||
| 171 | Usage : $stream->write_seq(@seq) | ||||||||||||||||||||||||||||||||||||||||||
| 172 | Function: writes the formatted $seq object into the stream | ||||||||||||||||||||||||||||||||||||||||||
| 173 | Returns : 1 for success and 0 for error | ||||||||||||||||||||||||||||||||||||||||||
| 174 | Args : array of Bio::PrimarySeqI object | ||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | 3 | ▶ | sub write_seq { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write_seq: called CC=18 SCAR=30.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 180 | 3 | my ($self,@seq) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 181 | 3 | for my $seq (@seq) { | |||||||||||||||||||||||||||||||||||||||||
| 182 | 3 | ▶ | $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")
| |||||||||||||||||||||||||||||||||||||||||||
| 183 | unless defined $seq && ref($seq) && $seq->isa('Bio::PrimarySeqI'); | ||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||
| 185 | 3 | ▶ | $self->warn("No whitespace allowed in GCG ID [". $seq->display_id. "]") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 186 | if $seq->display_id =~ /\s/; | ||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | 3 | my $str = $seq->seq; | |||||||||||||||||||||||||||||||||||||||||
| 189 | 3 | ▶ | my $comment = $seq->desc || ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$seq->desc || ''
MC/DC0%0/1
$seq->desc || ''
$seq->desc
Truth table50%1/2
A
A= $seq->desc
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | 3 | my $id = $seq->id; | |||||||||||||||||||||||||||||||||||||||||
| 191 | 3 | ▶ | my $type = ( $seq->alphabet() =~ /[dr]na/i ) ? 'N' : 'P'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 192 | 3 | my $timestamp; | |||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||
| 194 | 3 | ▶ | if( $seq->can('get_dates') ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 195 | 3 | ($timestamp) = $seq->get_dates; | |||||||||||||||||||||||||||||||||||||||||
| 196 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | $timestamp = localtime(time); | |||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||
| 199 | 3 | my($sum,$offset,$len,$i,$j,$cnt,@out); | |||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | 3 | $len = length($str); | |||||||||||||||||||||||||||||||||||||||||
| 202 | ## Set the offset if we have any non-standard numbering going on | ||||||||||||||||||||||||||||||||||||||||||
| 203 | 3 | $offset=1; | |||||||||||||||||||||||||||||||||||||||||
| 204 | # checksum | ||||||||||||||||||||||||||||||||||||||||||
| 205 | 3 | $sum = $self->GCG_checksum($seq); | |||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | #Output the sequence header info | ||||||||||||||||||||||||||||||||||||||||||
| 208 | 3 | push(@out,"$comment\n"); | |||||||||||||||||||||||||||||||||||||||||
| 209 | 3 | push(@out,"$id Length: $len $timestamp Type: $type Check: $sum ..\n\n"); | |||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||
| 211 | #Format the sequence | ||||||||||||||||||||||||||||||||||||||||||
| 212 | 3 | $i = $#out + 1; | |||||||||||||||||||||||||||||||||||||||||
| 213 | 3 | ▶ | for($j = 0 ; $j < $len ; ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | 108 | ▶ | if( $j % 50 == 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 215 | 24 | $out[$i] = sprintf("%8d ",($j+$offset)); #numbering | |||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||
| 217 | 108 | $out[$i] .= sprintf("%s",substr($str,$j,10)); | |||||||||||||||||||||||||||||||||||||||||
| 218 | 108 | $j += 10; | |||||||||||||||||||||||||||||||||||||||||
| 219 | 108 | ▶ | if( $j < $len && $j % 50 != 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$j < $len and $j % 50 != 0
MC/DC100%2/2
$j < $len and $j % 50 != 0
$j < $len
$j % 50 != 0
Truth table100%3/3
A and B
A= $j < $lenB= $j % 50 != 0
| |||||||||||||||||||||||||||||||||||||||||||
| 220 | 84 | $out[$i] .= " "; | |||||||||||||||||||||||||||||||||||||||||
| 221 | }elsif($j % 50 == 0 ) { | ||||||||||||||||||||||||||||||||||||||||||
| 222 | 21 | $out[$i++] .= "\n\n"; | |||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||
| 225 | 3 | local($^W) = 0; | |||||||||||||||||||||||||||||||||||||||||
| 226 | 3 | ▶ | if($j % 50 != 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 227 | 3 | $out[$i] .= "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||
| 229 | 3 | $out[$i] .= "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 230 | 3 | ▶ | return unless $self->_print(@out); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||
| 233 | 3 | ▶ | $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
| |||||||||||||||||||||||||||||||||||||||||||
| 234 | 3 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | =head2 GCG_checksum | ||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||
| 239 | Title : GCG_checksum | ||||||||||||||||||||||||||||||||||||||||||
| 240 | Usage : $cksum = $gcgio->GCG_checksum($seq); | ||||||||||||||||||||||||||||||||||||||||||
| 241 | Function : returns a gcg checksum for the sequence specified | ||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||
| 243 | This method can also be called as a class method. | ||||||||||||||||||||||||||||||||||||||||||
| 244 | Example : | ||||||||||||||||||||||||||||||||||||||||||
| 245 | Returns : a GCG checksum string | ||||||||||||||||||||||||||||||||||||||||||
| 246 | Argument : a Bio::PrimarySeqI implementing object | ||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||
| 248 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||
| 250 | 25 | ▶ | sub GCG_checksum { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
GCG_checksum: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 251 | 25 | my ($self,$seqobj) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 252 | 25 | my $index = 0; | |||||||||||||||||||||||||||||||||||||||||
| 253 | 25 | my $checksum = 0; | |||||||||||||||||||||||||||||||||||||||||
| 254 | 25 | my $char; | |||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||
| 256 | 25 | my $seq = $seqobj->seq(); | |||||||||||||||||||||||||||||||||||||||||
| 257 | 25 | $seq =~ tr/a-z/A-Z/; | |||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||
| 259 | 25 | foreach $char ( split(/[\.\-]*/, $seq)) { | |||||||||||||||||||||||||||||||||||||||||
| 260 | 6280 | $index++; | |||||||||||||||||||||||||||||||||||||||||
| 261 | 6280 | ▶ | $checksum += ($index * (unpack("c",$char) || 0) ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
unpack('c', $char) || 0
MC/DC100%1/1
unpack('c', $char) || 0
unpack('c', $char)
Truth table100%2/2
A
A= unpack('c', $char)
| |||||||||||||||||||||||||||||||||||||||||||
| 262 | 6280 | ▶ | if( $index == 57 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 263 | 105 | $index = 0; | |||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||
| 267 | 25 | return ($checksum % 10000); | |||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||
| 270 | =head2 _validate_checksum | ||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||
| 272 | Title : _validate_checksum | ||||||||||||||||||||||||||||||||||||||||||
| 273 | Usage : n/a - internal method | ||||||||||||||||||||||||||||||||||||||||||
| 274 | Function: if parsed gcg sequence contains a checksum field | ||||||||||||||||||||||||||||||||||||||||||
| 275 | : we compare it to a value computed here on the parsed | ||||||||||||||||||||||||||||||||||||||||||
| 276 | : sequence. A checksum mismatch would indicate some | ||||||||||||||||||||||||||||||||||||||||||
| 277 | : type of parsing failure occurred. | ||||||||||||||||||||||||||||||||||||||||||
| 278 | : | ||||||||||||||||||||||||||||||||||||||||||
| 279 | Returns : 1 for success, 0 for failure | ||||||||||||||||||||||||||||||||||||||||||
| 280 | Args : string containing parsed seq, value of parsed checksum | ||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||
| 283 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||
| 285 | 5 | ▶ | sub _validate_checksum { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_checksum: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 286 | 5 | my($seq,$parsed_sum) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 287 | 5 | my($i,$len,$computed_sum,$cnt); | |||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||
| 289 | 5 | $len = length($seq); | |||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||
| 291 | #Generate the GCG Checksum value | ||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||
| 293 | 5 | ▶ | for($i=0; $i<$len ;$i++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 294 | 1578 | $cnt++; | |||||||||||||||||||||||||||||||||||||||||
| 295 | 1578 | $computed_sum += $cnt * ord(substr($seq,$i,1)); | |||||||||||||||||||||||||||||||||||||||||
| 296 | 1578 | ▶ | ($cnt == 57) && ($cnt=0); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||||||||||||
| 298 | 5 | $computed_sum %= 10000; | |||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||
| 300 | ## Compare and decide if success or failure | ||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||
| 302 | 5 | ▶ | if($parsed_sum == $computed_sum) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 303 | 5 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | } else { return 0; } | |||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||
| 309 | 6 | 1; | |||||||||||||||||||||||||||||||||||||||||