Bio::SeqIO swiss
SummaryIncluded librariesPackage variablesSynopsisDescriptionGeneral documentationMethods
Summary
Bio::SeqIO::swiss - Swissprot sequence input/output stream
Package variables
Privates (from "my" definitions)
$commobj = Bio::Annotation::Comment->new()
$seq = $self->sequence_factory->create (-verbose => $self->verbose, %params, -seq => $seqc, -desc => $desc, -features =>\@ features, -annotation => $annotation, )
$ftunit = $self->_read_FTHelper_swissprot($_)
@accs = split(/[; ]+/, $1)
($database,$primaryid,$optional,$comment) = ($1,$2,$3,$4)
$dblinkobj = Bio::Annotation::DBLink->new (-database => $database, -primary_id => $primaryid, -optional_id => $optional, -comment => $comment, )
($junk, $division) = split q(_), $name
$species = $self->_read_swissprot_Species($_)
$refs = $self->_read_swissprot_References($_)
$line = $1
$gn = Bio::Annotation::StructuredValue->new()
$update = Bio::Annotation::SimpleValue->new( -tagname => 'seq_update', -value => $1 )
@kw = split(/\s*\;\s*/,$1)
($date, $version) = split(' ', $line, 2)
$j = 0
Included modules
Bio::Annotation::Collection
Bio::Annotation::Comment
Bio::Annotation::DBLink
Bio::Annotation::Reference
Bio::Annotation::SimpleValue
Bio::Annotation::StructuredValue
Bio::Seq::SeqFactory
Bio::SeqFeature::Generic
Bio::SeqIO::FTHelper
Bio::Species
Bio::Tools::SeqStats
Inherit
Bio::SeqIO
Synopsis
It is probably best not to use this object directly, but
rather go through the SeqIO handler system:
    use Bio::SeqIO;
$stream = Bio::SeqIO->new(-file => $filename, -format => 'swiss'); while ( my $seq = $stream->next_seq() ) { # do something with $seq }
Description
This object can transform Bio::Seq objects to and from Swissprot flat
file databases.
There is a lot of flexibility here about how to dump things which needs
to be documented.
   _show_dna()
   (output only) shows the dna or not
   _post_sort()
   (output only) provides a sorting func which is applied to the FTHelpers
before printing
   _id_generation_func()
   This is function which is called as
   print "ID   ", $func($seq), "\n";
   To generate the ID line. If it is not there, it generates a sensible ID
line using a number of tools.
   If you want to output annotations in Swissprot format they need to be
stored in a Bio::Annotation::Collection object which is accessible
through the Bio::SeqI interface method annotation().
   The following are the names of the keys which are polled from a
Bio::Annotation::Collection object.
 reference   - Should contain Bio::Annotation::Reference objects
comment - Should contain Bio::Annotation::Comment objects
dblink - Should contain Bio::Annotation::DBLink objects
gene_name - Should contain Bio::Annotation::SimpleValue object
Methods
_initialize
No description
Code
next_seqDescriptionCode
write_seqDescriptionCode
_generateCRCTableDescriptionCode
_crc32DescriptionCode
_crc64DescriptionCode
_print_swissprot_FTHelperDescriptionCode
_read_swissprot_ReferencesDescriptionCode
_read_swissprot_SpeciesDescriptionCode
_read_FTHelper_swissprotDescriptionCode
_write_line_swissprotDescriptionCode
_write_line_swissprot_regexDescriptionCode
_post_sortDescriptionCode
_show_dnaDescriptionCode
_id_generation_funcDescriptionCode
_ac_generation_funcDescriptionCode
_sv_generation_funcDescriptionCode
_kw_generation_funcDescriptionCode
Methods description
next_seqcode    nextTop
 Title   : next_seq
Usage : $seq = $stream->next_seq()
Function: returns the next sequence in the stream
Returns : Bio::Seq object
Args :
write_seqcodeprevnextTop
 Title   : write_seq
Usage : $stream->write_seq($seq)
Function: writes the $seq object (must be seq) to the stream
Returns : 1 for success and 0 for error
Args : array of 1 to n Bio::SeqI objects
_generateCRCTablecodeprevnextTop
 Title   : _generateCRCTable
Usage :
Function:
Example :
Returns :
Args :
_crc32codeprevnextTop
 Title   : _crc32
Usage :
Function:
Example :
Returns :
Args :
_crc64codeprevnextTop
 Title   : _crc64
Usage :
Function:
Example :
Returns :
Args :
_print_swissprot_FTHelpercodeprevnextTop
 Title   : _print_swissprot_FTHelper
Usage :
Function:
Example :
Returns :
Args :
_read_swissprot_ReferencescodeprevnextTop
 Title   : _read_swissprot_References
Usage :
Function: Reads references from swissprot format. Internal function really
Example :
Returns :
Args :
_read_swissprot_SpeciescodeprevnextTop
 Title   : _read_swissprot_Species
Usage :
Function: Reads the swissprot Organism species and classification
lines.
Able to deal with unconventional species names.
Example : OS Unknown prokaryotic organism
$genus = undef ; $species = Unknown prokaryotic organism
Returns : A Bio::Species object
Args :
_read_FTHelper_swissprotcodeprevnextTop
 Title   : _read_FTHelper_swissprot
Usage : _read_FTHelper_swissprot(\$buffer)
Function: reads the next FT key line
Example :
Returns : Bio::SeqIO::FTHelper object
Args :
_write_line_swissprotcodeprevnextTop
 Title   : _write_line_swissprot
Usage :
Function: internal function
Example :
Returns :
Args :
_write_line_swissprot_regexcodeprevnextTop
 Title   : _write_line_swissprot_regex
Usage :
Function: internal function for writing lines of specified
length, with different first and the next line
left hand headers and split at specific points in the
text
Example :
Returns : nothing
Args : file handle, first header, second header, text-line, regex for line breaks, total line length
_post_sortcodeprevnextTop
 Title   : _post_sort
Usage : $obj->_post_sort($newval)
Function:
Returns : value of _post_sort
Args : newvalue (optional)
_show_dnacodeprevnextTop
 Title   : _show_dna
Usage : $obj->_show_dna($newval)
Function:
Returns : value of _show_dna
Args : newvalue (optional)
_id_generation_funccodeprevnextTop
 Title   : _id_generation_func
Usage : $obj->_id_generation_func($newval)
Function:
Returns : value of _id_generation_func
Args : newvalue (optional)
_ac_generation_funccodeprevnextTop
 Title   : _ac_generation_func
Usage : $obj->_ac_generation_func($newval)
Function:
Returns : value of _ac_generation_func
Args : newvalue (optional)
_sv_generation_funccodeprevnextTop
 Title   : _sv_generation_func
Usage : $obj->_sv_generation_func($newval)
Function:
Returns : value of _sv_generation_func
Args : newvalue (optional)
_kw_generation_funccodeprevnextTop
 Title   : _kw_generation_func
Usage : $obj->_kw_generation_func($newval)
Function:
Returns : value of _kw_generation_func
Args : newvalue (optional)
Methods code
_initializedescriptionprevnextTop
sub _initialize {
  my($self,@args) = @_;
  $self->SUPER::_initialize(@args);
   
  # hash for functions for decoding keys.
$self->{'_func_ftunit_hash'} = {}; $self->_show_dna(1); # sets this to one by default. People can change it
if( ! defined $self->sequence_factory ) { $self->sequence_factory(new Bio::Seq::SeqFactory (-verbose => $self->verbose(), -type => 'Bio::Seq::RichSeq')); }
}
next_seqdescriptionprevnextTop
sub next_seq {
   my ($self,@args) = @_;
   my ($pseq,$c,$line,$name,$desc,$acc,$seqc,$mol,$div, $sptr,$seq_div,
       $date,$comment,@date_arr);
   my $genename = "";
   my ($annotation, %params, @features) = ( new Bio::Annotation::Collection);

   local $_;

   while( defined($_ = $self->_readline) && /^\s+$/ ) { 
   }
   return unless defined $_ && /^ID\s/;

   # fixed to allow _DIVISION to be optional for bug #946
# see bug report for more information
#
# 9/6/06 Note: Swiss/TrEMBL sequences have no division acc. to UniProt
# release notes; this is fixed to simplify the regex parsing
# STANDARD (SwissProt) and PRELIMINARY (TrEMBL) added to namespace()
unless( m{^
ID \s+ #
(\S+) \s+ #
$1 entryname
([^\s;]+); \s+ #
$2 DataClass
(?:PRT;)? \s+ # Molecule Type (optional)
[0-9]+[ ]AA \. # Sequencelength (capture?)
$
}ox
) { # I couldn't find any new current UniProt sequences
# that matched this format:
# || m/^ID\s+(\S+)\s+(_([^\s_]+))? /ox ) {
$self->throw("swissprot stream with no ID. Not swissprot in my book");
}
write_seqdescriptionprevnextTop
sub write_seq {
    my ($self,@seqs) = @_;
    foreach my $seq ( @seqs ) {
    $self->throw("Attempting to write with no seq!") unless defined $seq;

    if( ! ref $seq || ! $seq->isa('Bio::SeqI') ) {
        $self->warn(" $seq is not a SeqI compliant module. Attempting to dump, but may fail!");
    }

    my $i;
    my $str = $seq->seq;

    my $div;
    my $ns = ($seq->can('namespace')) && $seq->namespace();
    my $len = $seq->length();

    if ( !$seq->can('division') || ! defined ($div = $seq->division()) ) {
        $div = 'UNK';
    }
    
    # namespace dictates database, takes precedent over division. Sorry!
if (defined($ns)) { $div = ($ns eq 'Swiss-Prot') ? 'Reviewed' : ($ns eq 'TrEMBL') ? 'Unreviewed' : $ns; } else { $ns = 'Swiss-Prot'; # division not reset; acts as fallback
} $self->warn("No whitespace allowed in SWISS-PROT display id [". $seq->display_id. "]") if $seq->display_id =~ /\s/; my $temp_line; if( $self->_id_generation_func ) { $temp_line = &{$self->_id_generation_func}($seq); } else { #$temp_line = sprintf ("%10s STANDARD; %3s; %d AA.",
# $seq->primary_id()."_".$div,$mol,$len);
# Reconstructing the ID relies heavily upon the input source having
# been in a format that is parsed as this routine expects it -- that is,
# by this module itself. This is bad, I think, and immediately breaks
# if e.g. the Bio::DB::GenPept module is used as input.
# Hence, switch to display_id(); _every_ sequence is supposed to have
# this. HL 2000/09/03
# Changed to reflect ID line changes in UniProt
# Oct 2006 - removal of molecule type - see bug 2134
$temp_line = sprintf ("%-24s%-12s%9d AA.", $seq->display_id(), $div.';', $len); } $self->_print( "ID $temp_line\n"); # if there, write the accession line
local($^W) = 0; # supressing warnings about uninitialized fields
if( $self->_ac_generation_func ) { $temp_line = &{$self->_ac_generation_func}($seq); $self->_print( "AC $temp_line\n"); } else { if ($seq->can('accession_number') ) { $self->_print("AC ",$seq->accession_number,";"); if ($seq->can('get_secondary_accessions') ) { foreach my $sacc ($seq->get_secondary_accessions) { $self->_print(" ",$sacc,";"); } $self->_print("\n"); } else { $self->_print("\n"); } } # otherwise - cannot print <sigh>
} # Date lines and sequence versions (changed 6/15/2006)
# This is rebuilt from scratch using the current SwissProt/UniProt format
if( $seq->can('get_dates') ) { my @dates = $seq->get_dates(); my $ct = 1; my $seq_version = $seq->version; my ($update_version) = $seq->get_Annotations("seq_update"); foreach my $dt (@dates){ $self->_write_line_swissprot_regex("DT ","DT ", $dt.', integrated into UniProtKB/'.$ns, "\\s\+\|\$",80) if $ct == 1; $self->_write_line_swissprot_regex("DT ","DT ", $dt.", sequence version $update_version.", "\\s\+\|\$",80) if $ct == 2; $self->_write_line_swissprot_regex("DT ","DT ", $dt.", entry version $seq_version.", "\\s\+\|\$",80) if $ct == 3; $ct++; } } #Definition lines
$self->_write_line_swissprot_regex("DE ","DE ",$seq->desc(),"\\s\+\|\$",80); #Gene name
if ((my @genes = $seq->annotation->get_Annotations('gene_name') ) ) { $self->_print("GN ", join(' OR ', map { $_->isa("Bio::Annotation::StructuredValue") ? $_->value(-joins => [" AND ", " OR "]) : $_->value(); } @genes), ".\n"); } # Organism lines
if ($seq->can('species') && (my $spec = $seq->species)) { my @class = $spec->classification(); shift(@class); my $species = $spec->species; my $genus = $spec->genus; my $OS = $spec->scientific_name; if ($class[-1] =~ /viruses/i) { $OS = $species; $OS .= " ". $spec->sub_species if $spec->sub_species; } foreach (($spec->variant, $spec->common_name)) { $OS .= " ($_)" if $_; } $self->_print( "OS $OS.\n"); my $OC = join('; ', reverse(@class)) .'.'; $self->_write_line_swissprot_regex("OC ","OC ",$OC,"\;\|\$ ",80); if ($spec->organelle) { $self->_write_line_swissprot_regex("OG ","OG ",$spec->organelle,"\;\|\$ ",80); } if ($spec->ncbi_taxid) { $self->_print("OX NCBI_TaxID=".$spec->ncbi_taxid.";\n"); } } # Reference lines
my $t = 1; foreach my $ref ( $seq->annotation->get_Annotations('reference') ) { $self->_print( "RN [$t]\n"); # changed by lorenz 08/03/00
# j.gilbert and h.lapp agreed that the rp line in swissprot seems
# more like a comment than a parseable value, so print it as is
if ($ref->rp) { $self->_write_line_swissprot_regex("RP ","RP ",$ref->rp, "\\s\+\|\$",80); } if ($ref->comment) { $self->_write_line_swissprot_regex("RC ","RC ",$ref->comment, "\\s\+\|\$",80); } if ($ref->medline) { # new RX format in swissprot LP 09/17/00
if ($ref->pubmed) { $self->_write_line_swissprot_regex("RX ","RX ", "MEDLINE=".$ref->medline. "; PubMed=".$ref->pubmed.";", "\\s\+\|\$",80); } else { $self->_write_line_swissprot_regex("RX MEDLINE; ","RX MEDLINE; ", $ref->medline.".","\\s\+\|\$",80); } } my $author = $ref->authors .';' if($ref->authors); my $title = $ref->title .';' if( $ref->title); my $rg = $ref->rg . ';' if $ref->rg; $self->_write_line_swissprot_regex("RG ","RG ",$rg,"\\s\+\|\$",80) if $rg; $self->_write_line_swissprot_regex("RA ","RA ",$author,"\\s\+\|\$",80) if $author; $self->_write_line_swissprot_regex("RT ","RT ",$title,"\\s\+\|\$",80) if $title; $self->_write_line_swissprot_regex("RL ","RL ",$ref->location,"\\s\+\|\$",80); $t++; } # Comment lines
foreach my $comment ( $seq->annotation->get_Annotations('comment') ) { foreach my $cline (split ("\n", $comment->text)) { while (length $cline > 74) { $self->_print("CC ",(substr $cline,0,74),"\n"); $cline = substr $cline,74; } $self->_print("CC ",$cline,"\n"); } } foreach my $dblink ( $seq->annotation->get_Annotations('dblink') ) { my ($primary_id) = $dblink->primary_id; if (defined($dblink->comment) && ($dblink->comment) ) { $self->_print("DR ",$dblink->database,"; ",$primary_id,"; ", $dblink->optional_id,"; ",$dblink->comment,".\n"); } elsif($dblink->optional_id) { $self->_print("DR ",$dblink->database,"; ", $primary_id,"; ", $dblink->optional_id,".\n"); } else { $self->_print("DR ",$dblink->database, "; ",$primary_id,"; ","-.\n"); } } # if there, write the kw line
{ my( $kw ); if( my $func = $self->_kw_generation_func ) { $kw = &{$func}($seq); } elsif( $seq->can('keywords') ) { $kw = $seq->keywords; if( ref($kw) =~ /ARRAY/i ) { $kw = join("; ", @$kw); } $kw .= '.' if( $kw !~ /\.$/ ); } $self->_write_line_swissprot_regex("KW ","KW ", $kw, "\\s\+\|\$",80); } #Check if there is seqfeatures before printing the FT line
my @feats = $seq->can('top_SeqFeatures') ? $seq->top_SeqFeatures : (); if ($feats[0]) { if( defined $self->_post_sort ) { # we need to read things into an array. Process. Sort them. Print 'em
my $post_sort_func = $self->_post_sort(); my @fth; foreach my $sf ( @feats ) { push(@fth,Bio::SeqIO::FTHelper::from_SeqFeature($sf,$seq)); } @fth = sort { &$post_sort_func($a,$b) } @fth; foreach my $fth ( @fth ) { $self->_print_swissprot_FTHelper($fth); } } else { # not post sorted. And so we can print as we get them.
# lower memory load...
foreach my $sf ( @feats ) { my @fth = Bio::SeqIO::FTHelper::from_SeqFeature($sf,$seq); foreach my $fth ( @fth ) { if( ! $fth->isa('Bio::SeqIO::FTHelper') ) { $sf->throw("Cannot process FTHelper... $fth"); } $self->_print_swissprot_FTHelper($fth); } } } if( $self->_show_dna() == 0 ) { return; } } # finished printing features.
# molecular weight
my $mw = ${Bio::Tools::SeqStats->get_mol_wt($seq->primary_seq)}[0]; # checksum
# was crc32 checksum, changed it to crc64
my $crc64 = $self->_crc64(\$str); $self->_print( sprintf("SQ SEQUENCE %4d AA; %d MW; %16s CRC64;\n", $len,$mw,$crc64)); $self->_print( " "); my $linepos; for ($i = 0; $i < length($str); $i += 10) { $self->_print( substr($str,$i,10), " "); $linepos += 11; if( ($i+10)%60 == 0 && (($i+10) < length($str))) { $self->_print( "\n "); } } $self->_print( "\n//\n"); $self->flush if $self->_flush_on_write && defined $self->_fh; return 1; }
}
_generateCRCTabledescriptionprevnextTop
sub _generateCRCTable {
  # 10001000001010010010001110000100
# 32
my $poly = 0xEDB88320; my ($self) = shift; $self->{'_crcTable'} = []; foreach my $i (0..255) { my $crc = $i; for (my $j=8; $j > 0; $j--) { if ($crc & 1) { $crc = ($crc >> 1) ^ $poly; } else { $crc >>= 1; } } ${$self->{'_crcTable'}}[$i] = $crc; }
}
_crc32descriptionprevnextTop
sub _crc32 {
  my( $self, $str ) = @_;
  
  $self->throw("Argument to crc32() must be ref to scalar")
    unless ref($str) eq 'SCALAR';
  
  $self->_generateCRCTable() unless exists $self->{'_crcTable'};
  
  my $len = length($$str);
  
  my $crc = 0xFFFFFFFF;
  for (my $i = 0; $i < $len; $i++) {
    # Get upper case value of each letter
my $int = ord uc substr $$str, $i, 1; $crc = (($crc >> 8) & 0x00FFFFFF) ^ ${$self->{'_crcTable'}}[ ($crc ^ $int) & 0xFF ]; } return $crc;
}
_crc64descriptionprevnextTop
sub _crc64 {
    my ($self, $sequence) = @_;
    my $POLY64REVh = 0xd8000000;
    my @CRCTableh = 256;
    my @CRCTablel = 256;
    my $initialized;       
    

    my $seq = $$sequence;
      
    my $crcl = 0;
    my $crch = 0;
    if (!$initialized) {
    $initialized = 1;
    for (my $i=0; $i<256; $i++) {
        my $partl = $i;
        my $parth = 0;
        for (my $j=0; $j<8; $j++) {
        my $rflag = $partl & 1;
        $partl >>= 1;
        $partl |= (1 << 31) if $parth & 1;
        $parth >>= 1;
        $parth ^= $POLY64REVh if $rflag;
        }
        $CRCTableh[$i] = $parth;
        $CRCTablel[$i] = $partl;
    }
    }
    
    foreach (split '', $seq) {
    my $shr = ($crch & 0xFF) << 24
my $temp1h = $crch >> 8;
my $temp1l = ($crcl >> 8) | $shr;
my $tableindex = ($crcl ^ (unpack "C", $_)) & 0xFF;
$crch = $temp1h ^ $CRCTableh[$tableindex];
$crcl = $temp1l ^ $CRCTablel[$tableindex];
}
my $crc64 = sprintf("%08X%08X", $crch, $crcl);

return $crc64;

}
_print_swissprot_FTHelperdescriptionprevnextTop
sub _print_swissprot_FTHelper {
   my ($self,$fth,$always_quote) = @_;
   $always_quote ||= 0;
   my ($start,$end) = ('?', '?');
   
   if( ! ref $fth || ! $fth->isa('Bio::SeqIO::FTHelper') ) {
       $fth->warn("$fth is not a FTHelper class. ".
          "Attempting to print, but there could be tears!");
   }
   my $desc = "";

   for my $tag ( qw(description gene note product) ) {
       if( exists $fth->field->{$tag} ) {
       $desc = @{$fth->field->{$tag}}[0].".";
       last;
       }
   }
   $desc =~ s/\.$//;
   
   my $key =substr($fth->key,0,8);
   my $loc = $fth->loc;
   if( $loc =~ /(\?|\d+|\>\d+|<\d+)?\.\.(\?|\d+|<\d+|>\d+)?/ ) {
       $start = $1 if defined $1;
       $end = $2 if defined $2;

       # to_FTString only returns one value when start == end, #JB955
# so if no match is found, assume it is both start and end #JB955
} elsif ( $loc =~ /join\((\d+)((?:,\d+)+)?\)/) { my @y = ($1); if( defined( my $m = $2) ) { $m =~ s/^\,//; push @y, split(/,/,$m); } for my $x ( @y ) { $self->_write_line_swissprot_regex( sprintf("FT %-8s %6s %6s ", $key, $x ,$x), "FT ", $desc.'.','\s+|$',80); } return; } else { $start = $end = $fth->loc; } $self->_write_line_swissprot_regex(sprintf("FT %-8s %6s %6s ", $key, $start ,$end), "FT ", $desc.'.','\s+|$',80);
}
_read_swissprot_ReferencesdescriptionprevnextTop
sub _read_swissprot_References {
   my ($self,$line) = @_;
   my ($b1, $b2, $rp, $rg, $title, $loc, $au, $med, $com, $pubmed);
   my @refs;
   local $_ = $line;
   while( defined $_ ) {
       if( /^[^R]/ || /^RN/ ) { 
       if( $rp ) { 
           $rg =~ s/;\s*$//g if defined($rg);
               if (defined($au)) {
                   $au =~ s/;\s*$//;
               } else {
                   $au = $rg;
               }
               $title =~ s/;\s*$//g if defined($title);
           push @refs, Bio::Annotation::Reference->new(-title   => $title,
                               -start   => $b1,
                               -end     => $b2,
                               -authors => $au,
                               -location=> $loc,
                               -medline => $med,
                               -pubmed  => $pubmed,
                               -comment => $com,
                               -rp      => $rp,
                                                           -rg      => $rg);
               # reset state for the next reference
$rp = ''; } if (index($_,'R') != 0) { $self->_pushback($_); # want this line to go back on the list
last; # may be the safest exit point HL 05/11/2000
} # don't forget to reset the state for the next reference
$b1 = $b2 = $rg = $med = $com = $pubmed = undef; $title = $loc = $au = undef; } elsif ( /^RP\s{3}(.+? OF (\d+)-(\d+).*)/) { $rp .= $1; $b1 = $2; $b2 = $3; } elsif ( /^RP\s{3}(.*)/) { if($rp) { $rp .= " ".$1 } else { $rp = $1 } } elsif( /^RX\s{3}MEDLINE;\s+(\d+)(?!<;)/ ) { $med = $1; } elsif( /^RX\s{3}MEDLINE=(\d+);\s+PubMed=(\d+);/ ) { $med = $1; $pubmed= $2; } elsif( /^RX\s{3}PubMed=(\d+);/ ) { # can start with pubmed only
$pubmed = $1; } elsif( /^RA\s{3}(.*)/ ) { $au .= $au ? " $1" : $1; } elsif( /^RG\s{3}(.*)/ ) { $rg .= $rg ? " $1" : $1; } elsif ( /^RT\s{3}(.*)/ ) { if ($title) { my $tline = $1; $title .= ($title =~ /[\w;,:\?!]$/) ? " $tline" : $tline; } else { $title = $1; } } elsif (/^RL\s{3}(.*)/ ) { $loc .= $loc ? " $1" : $1; } elsif ( /^RC\s{3}(.*)/ ) { $com .= $com ? " $1" : $1; } #/^CC/ && last;
#/^SQ/ && last; # there may be sequences without CC lines! HL 05/11/2000
$_ = $self->_readline; } return\@ refs;
}
_read_swissprot_SpeciesdescriptionprevnextTop
sub _read_swissprot_Species {
    my( $self,$line ) = @_;
    my $org;
    local $_ = $line;

    my( $sub_species, $species, $genus, $common, $variant, $ncbi_taxid, $sci_name, $class_lines, $descr );
    my $osline = "";
    while ( defined $_ ) {
        last unless /^O[SCGX]/;
        # believe it or not, but OS may come multiple times -- at this time
# we can't capture multiple species
if(/^OS\s+(\S.+)/ && (! defined($sci_name))) { $osline .= " " if $osline; $osline .= $1; if($osline =~ s/(,|, and|\.)$//) { ($sci_name, $descr) = $osline =~ /(\S[^\(]+)(.*)/; $sci_name =~ s/\s+$//; while($descr =~ /\(([^\)]+)\)/g) { my $item = $1; # strain etc may not necessarily come first (yes, swissprot
# is messy)
if((! defined($variant)) && (($item =~ /(^|[^\(\w])([Ss]train|isolate|serogroup|serotype|subtype|clone)\b/) || ($item =~ /^(biovar|pv\.|type\s+)/))) { $variant = $item; } elsif($item =~ s/^subsp\.\s+//) { if(! $sub_species) { $sub_species = $item; } elsif(! $variant) { $variant = $item; } } elsif(! defined($common)) { # we're only interested in the first common name
$common = $item; if((index($common, '(') >= 0) && (index($common, ')') < 0)) { $common .= ')'; } } } } } elsif (s/^OC\s+(\S.+)$//) { $class_lines .= $1; } elsif (/^OG\s+(.*)/) { $org = $1; } elsif (/^OX\s+(.*)/ && (! defined($ncbi_taxid))) { my $taxstring = $1; # we only keep the first one and ignore all others
if ($taxstring =~ /NCBI_TaxID=([\w\d]+)/) { $ncbi_taxid = $1; } else { $self->throw("$taxstring doesn't look like NCBI_TaxID"); } } $_ = $self->_readline; } $self->_pushback($_); # pushback the last line because we need it
$sci_name || return; #if the organism belongs to taxid 32644 then no Bio::Species object.
# return if grep { /^\Q$sci_name$/ } @Unknown_names;
return if grep { $_ eq $sci_name } @Unknown_names; # Convert data in classification lines into classification array.
# only split on ';' or '.' so that classification that is 2 or more words
# will still get matched, use map() to remove trailing/leading/intervening
# spaces
my @class = map { s/^\s+//; s/\s+$//; s/\s{2,}/ /g; $_; } split /[;\.]+/, $class_lines; if ($class[0] =~ /viruses/i) { # viruses have different OS/OC syntax
my @virusnames = split(/\s+/, $sci_name); $species = (@virusnames > 1) ? pop(@virusnames) : ''; $genus = join(" ", @virusnames); $sub_species = $descr; } else { # do we have a genus?
my $possible_genus = $class[-1]; $possible_genus .= "|$class[-2]" if $class[-2]; if ($sci_name =~ /^($possible_genus)/) { $genus = $1; ($species) = $sci_name =~ /^$genus\s+(.+)/; } else { $species = $sci_name; } # is this organism of rank species or is it lower?
# (doesn't catch everything, but at least the guess isn't dangerous)
if ($species =~ /subsp\.|var\./) { ($species, $sub_species) = $species =~ /(.+)\s+((?:subsp\.|var\.).+)/; } } # Bio::Species array needs array in Species -> Kingdom direction
unless ($class[-1] eq $sci_name) { push(@class, $sci_name); } @class = reverse @class; my $taxon = Bio::Species->new(); $taxon->scientific_name($sci_name); $taxon->classification(@class); $taxon->common_name($common) if $common; $taxon->sub_species($sub_species) if $sub_species; $taxon->organelle($org) if $org; $taxon->ncbi_taxid($ncbi_taxid) if $ncbi_taxid; $taxon->variant($variant) if $variant; # done
return $taxon;
}
_read_FTHelper_swissprotdescriptionprevnextTop
sub _read_FTHelper_swissprot {
    my ($self,$line ) = @_;
    # initial version implemented by HL 05/10/2000
# FIXME this may not be perfect, so please review
# lots of cleaning up by JES 2004/07/01, still may not be perfect =)
local $_ = $line; my ($key, # The key of the feature
$loc, # The location line from the feature
$desc, # The descriptive text
); if( m/^FT\s{3}(\w+)\s+([\d\?\<]+)\s+([\d\?\>]+)\s*(.*)$/ox) { $key = $1; my $loc1 = $2; my $loc2 = $3; $loc = "$loc1..$loc2"; if($4 && (length($4) > 0)) { $desc = $4; chomp($desc); } else { $desc = ""; } } while ( defined($_ = $self->_readline) && /^FT\s{20,}(\S.*)$/ ) { if( $desc) { $desc .= " $1" } else { $desc = $1 } chomp($desc); } $self->_pushback($_); unless( $key ) { # No feature key. What's this?
$self->warn("No feature key in putative feature table line: $line"); return; } # Make the new FTHelper object
my $out = new Bio::SeqIO::FTHelper(-verbose => $self->verbose()); $out->key($key); $out->loc($loc); # store the description if there is one
if( $desc && length($desc) ) { $desc =~ s/\.$//; push(@{$out->field->{"description"}}, $desc); } return $out;
}
_write_line_swissprotdescriptionprevnextTop
sub _write_line_swissprot {
   my ($self,$pre1,$pre2,$line,$length) = @_;

   $length || $self->throw( "Miscalled write_line_swissprot without length. Programming error!");
   my $subl = $length - length $pre2;
   my $linel = length $line;
   my $i;

   my $sub = substr($line,0,$length - length $pre1);

   $self->_print( "$pre1$sub\n");
   
   for($i= ($length - length $pre1);$i < $linel;) {
       $sub = substr($line,$i,($subl));
       $self->_print( "$pre2$sub\n");
       $i += $subl;
   }
}
_write_line_swissprot_regexdescriptionprevnextTop
sub _write_line_swissprot_regex {
   my ($self,$pre1,$pre2,$line,$regex,$length) = @_;
   
   #print STDOUT "Going to print with $line!\n";
$length || $self->throw( "Miscalled write_line_swissprot without length. Programming error!"); if( length $pre1 != length $pre2 ) { $self->warn( "len 1 is ". length ($pre1) . " len 2 is ". length ($pre2) . "\n"); $self->throw( "Programming error - cannot called write_line_swissprot_regex with different length\n pre1 ($pre1) and\n pre2 ($pre2) tags!"); } my $subl = $length - (length $pre1) -1 ; my @lines; while($line =~ m/(.{1,$subl})($regex)/g) { push(@lines, $1.$2); } my $s = shift @lines; $self->_print( "$pre1$s\n"); foreach my $s ( @lines ) { $self->_print( "$pre2$s\n"); }
}
_post_sortdescriptionprevnextTop
sub _post_sort {
   my $obj = shift;
   if( @_ ) {
      my $value = shift;
      $obj->{'_post_sort'} = $value;
    }
    return $obj->{'_post_sort'};
}
_show_dnadescriptionprevnextTop
sub _show_dna {
   my $obj = shift;
   if( @_ ) {
      my $value = shift;
      $obj->{'_show_dna'} = $value;
    }
    return $obj->{'_show_dna'};
}
_id_generation_funcdescriptionprevnextTop
sub _id_generation_func {
   my $obj = shift;
   if( @_ ) {
      my $value = shift;
      $obj->{'_id_generation_func'} = $value;
    }
    return $obj->{'_id_generation_func'};
}
_ac_generation_funcdescriptionprevnextTop
sub _ac_generation_func {
   my $obj = shift;
   if( @_ ) {
      my $value = shift;
      $obj->{'_ac_generation_func'} = $value;
    }
    return $obj->{'_ac_generation_func'};
}
_sv_generation_funcdescriptionprevnextTop
sub _sv_generation_func {
   my $obj = shift;
   if( @_ ) {
      my $value = shift;
      $obj->{'_sv_generation_func'} = $value;
    }
    return $obj->{'_sv_generation_func'};
}
_kw_generation_funcdescriptionprevnextTop
sub _kw_generation_func {
   my $obj = shift;
   if( @_ ) {
      my $value = shift;
      $obj->{'_kw_generation_func'} = $value;
    }
    return $obj->{'_kw_generation_func'};
}
General documentation
FEEDBACKTop
Mailing ListsTop
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://bioperl.org/wiki/Mailing_lists - About the mailing lists
Reporting BugsTop
Report bugs to the Bioperl bug tracking system to help us keep track
the bugs and their resolution.
Bug reports can be submitted via the web:
  http://bugzilla.open-bio.org/
AUTHOR - Elia StupkaTop
Email elia@tll.org.sg
APPENDIXTop
The rest of the documentation details each of the object methods.
Internal methods are usually preceded with a _
_filehandleTop
 Title   : _filehandle
Usage : $obj->_filehandle($newval)
Function:
Example :
Returns : value of _filehandle
Args : newvalue (optional)