Bio::SeqIO
gcg
Summary
Bio::SeqIO::gcg - GCG sequence input/output stream
Package variables
No package variables defined.
Included modules
Inherit
Synopsis
Do not use this module directly. Use it via the Bio::SeqIO class.
Description
This object can transform Bio::Seq objects to and from GCG flat
file databases.
Methods
Methods description
Title : next_seq
Usage : $seq = $stream->next_seq()
Function: returns the next sequence in the stream
Returns : Bio::Seq object
Args : |
Title : write_seq
Usage : $stream->write_seq(@seq)
Function: writes the formatted $seq object into the stream
Returns : 1 for success and 0 for error
Args : array of Bio::PrimarySeqI object |
Title : GCG_checksum
Usage : $cksum = $gcgio->GCG_checksum($seq);
Function : returns a gcg checksum for the sequence specified
This method can also be called as a class method.
Example :
Returns : a GCG checksum string
Argument : a Bio::PrimarySeqI implementing object |
Title : _validate_checksum
Usage : n/a - internal method
Function: if parsed gcg sequence contains a checksum field
: we compare it to a value computed here on the parsed
: sequence. A checksum mismatch would indicate some
: type of parsing failure occured.
:
Returns : 1 for success, 0 for failure
Args : string containing parsed seq, value of parsed cheksum |
Methods code
sub _initialize
{ my($self,@args) = @_;
$self->SUPER::_initialize(@args);
if( ! defined $self->sequence_factory ) {
$self->sequence_factory(new Bio::Seq::SeqFactory
(-verbose => $self->verbose(),
-type => 'Bio::Seq::RichSeq'));
}} |
sub next_seq
{ my ($self,@args) = @_;
my($id,$type,$desc,$line,$chksum,$sequence,$date,$len);
while( defined($_ = $self->_readline()) ) {
unless( /\.\.$/ ) { $desc.= $_; }
/\.\.$/ && do { $line = $_; chomp;
if(/Check\:\s(\d+)\s/) { $chksum = $1; }
if(/Type:\s(\w)\s/) { $type = $1; }
if(/(\S+)\s+Length/)
{ $id = $1; }
if(/Length:\s+(\d+)\s+(\S.+\S)\s+Type/ )
{ $len = $1; $date = $2;}
last;
}
}
return if ( !defined $_);
chomp($desc);
while( defined($_ = $self->_readline()) ) {
if( /\.\.$/ ) {
$self->throw("Looks like start of another sequence. See documentation. ");
}
next if($_ eq "\n"); s/[^a-zA-Z]//g; $sequence .= $_;
}
if(defined $chksum) {
unless(_validate_checksum($sequence,$chksum)) {
$self->throw("Checksum failure on parsed sequence.");
}
}
if(defined $id) { $id =~ s/\s+//g;}
if(defined $type) {
if($type eq "N") { $type = "dna"; }
if($type eq "P") { $type = "prot"; }
}
return $self->sequence_factory->create(-seq => $sequence,
-id => $id,
-desc => $desc,
-type => $type,
-dates => [ $date ]
);} |
sub write_seq
{ my ($self,@seq) = @_;
for my $seq (@seq) {
$self->throw("Did not provide a valid Bio::PrimarySeqI object")
unless defined $seq && ref($seq) && $seq->isa('Bio::PrimarySeqI');
my $str = $seq->seq;
my $comment = $seq->desc;
my $id = $seq->id;
my $type = ( $seq->alphabet() =~ /[dr]na/i ) ? 'N' : 'P';
my $timestamp;
if( $seq->can('get_dates') ) {
($timestamp) = $seq->get_dates;
} else {
$timestamp = localtime(time);
}
my($sum,$offset,$len,$i,$j,$cnt,@out);
$len = length($str);
$offset=1;
$sum = $self->GCG_checksum($seq);
push(@out,"$comment\n");
push(@out,"$id Length: $len $timestamp Type: $type Check: $sum ..\n\n");
$i = $#out + 1;
for($j = 0 ; $j < $len ; ) {
if( $j % 50 == 0) {
$out[$i] = sprintf("%8d ",($j+$offset)); }
$out[$i] .= sprintf("%s",substr($str,$j,10));
$j += 10;
if( $j < $len && $j % 50 != 0 ) {
$out[$i] .= " ";
}elsif($j % 50 == 0 ) {
$out[$i++] .= "\n\n";
}
}
local($^W) = 0;
if($j % 50 != 0 ) {
$out[$i] .= "\n";
}
$out[$i] .= "\n";
return unless $self->_print(@out);
}
$self->flush if $self->_flush_on_write && defined $self->_fh;
return 1;} |
sub GCG_checksum
{ my ($self,$seqobj) = @_;
my $index = 0;
my $checksum = 0;
my $char;
my $seq = $seqobj->seq();
$seq =~ tr/a-z/A-Z/;
foreach $char ( split(/[\.\-]*/, $seq)) {
$index++;
$checksum += ($index * (unpack("c",$char) || 0) );
if( $index == 57 ) {
$index = 0;
}
}
return ($checksum % 10000);} |
sub _validate_checksum
{ my($seq,$parsed_sum) = @_;
my($i,$len,$computed_sum,$cnt);
$len = length($seq);
for($i=0; $i<$len ;$i++) {
$cnt++;
$computed_sum += $cnt * ord(substr($seq,$i,1));
($cnt == 57) && ($cnt=0);
}
$computed_sum %= 10000;
if($parsed_sum == $computed_sum) {
return 1;
} else { return 0; }} |
General documentation
User feedback is an integral part of the evolution of this
and other Bioperl modules. Send your comments and suggestions preferably
to one of the Bioperl mailing lists.
Your participation is much appreciated.
bioperl-l@bioperl.org - General discussion
http://www.bioperl.org/MailList.shtml - About the mailing lists
Report bugs to the Bioperl bug tracking system to help us keep track
the bugs and their resolution. Bug reports can be submitted via email
or the web:
bioperl-bugs@bio.perl.org
http://bugzilla.bioperl.org/
| AUTHORS - Ewan Birney & Lincoln Stein | Top |
Email: <birney@ebi.ac.uk>
<lstein@cshl.org>
The rest of the documentation details each of the object
methods. Internal methods are usually preceded with a _