[Bioperl-l] {SPECS] Sequence meta data

Heikki Lehvaslaiho heikki at ebi.ac.uk
Mon Mar 31 11:28:56 EST 2003


I have put together a sequence class interface which tackles in
generic way storage of any kind of residue-based meta
information. There are already classes in BioPerl which work with
specific types of meta information, and more are likely to added, but
they do not work together.

The types of sequence meta data in question include:

  Type                                       Module or person

- sequence quality data                      Bio::Seq::PrimaryQual
- nucleotide alignments with translations    Bio::Seq::EncodedSeq
- RNA secondary structure                    Peter Schattner
- protein secondary structure                -
- protein hydrophobicity                     Bio::Tools::OddCodes
- other simplified amino acid alphabets      Bio::Tools::OddCodes

...more?

I've written two modules: Bio::Seq::MetaI and a generic, pure perl
implementation Bio::Seq::Meta which can store and manipulate any meta
data encoding that uses exactly one character per residue.

The idea is that meta data makes sense only in the context of the
sequence and should be stored as an integral part of the sequence
object. 

Fasta format should be easy extend to create a text format for
serialisation of this kind of data. E.g:

< myseq1
LIVHGGRPA
& myseq1
aaa  bbbb
< myseq2
...

but I have not tried it out yet.

Bio::Seq::Meta name space should be preferably used to for more specific
implementations with more methods.

Please comment before I commit. POD docs more the modules are below
together with some tests.

        -Heikki

------------------------------------------------------------------------

NAME
    Bio::Seq::MetaI - Interface for sequence objects with residue-based
meta
    information

SYNOPSIS
      # get a Bio::Seq::MetaI compliant object somehow

      # to test this is a meta seq object
      $obj->isa("Bio::Seq::MetaI")
         || $obj->throw("$obj not a Bio::Seq::MetaI");

      # accessors
      $string     = $obj->meta;
      $string     = $obj->meta_text;
      $substring  = $obj->submeta(12,50);
      $unique_key = $obj->accession_number();

DESCRIPTION
    This class defines an abstract interface for basic residue-based 
    meta information. Examples of this kind of meta data are secondary 
    structures (RNA and protein), protein hydrophobicity assignments, 
    or other alternative alphabets for polypeptides, sequence quality 
    data and nucleotide alignments with translations.

    The length of the meta data sequence is not dependent on the amount 
    of the quality information. The meta information always covers all 
    the residues, but a blank value is used to denote unavailable 
    information. If necessary the implementation quietly truncates or 
    extends metain formation with blank values. Definition of blank is 
    implementation dependent. Gaps in MSAs should not have meta 
    information.

    At this point a residue in a sequence object can have only one meta
    value. If you need more, use multiple copies of the sequence object.

    Meta data storage can be implemented in various ways, e.g: string, 
    array of scalars, array of hashes, array of objects.

    Bio::Seq::Meta provides basic, pure perl implementation of sequences
    with meta information. See Bio::Seq::Meta. Application specific
    implementations will override and add to these methods.

SEE ALSO
    Bio::Seq::Meta, Bio::Seq::EncodedSeq, Bio::Tools::OddCodes,
    Bio::Seq::PrimaryQual, Bio::Seq::SeqWithQuality

FEEDBACK
    ...

AUTHOR - Heikki Lehvaslaiho
    Email heikki at ebi.ac.uk

CONTRIBUTORS
    Chad Matsalla, bioinformatics at dieselwurks.com; Aaron Mackey,
    amackey at virginia.edu

APPENDIX
    The rest of the documentation details each of the object methods.
    Internal methods are usually preceded with a _

  meta
     Title   : meta
     Usage   : $meta_values  = $obj->meta($values_string);
     Function:

               Get and set method for the meta data starting from 
               residue
               position one. Since it is dependent on the length of the
               sequence, it needs to be manipulated after the sequence.

               The implementation may choose to accept argument values 
               in
               a string or in an array (reference) or in a hash
               (reference).

               Implementation should warn or throw an error if user 
               tries to set mata information to a gap character.

               The return value may be a string or an array reference,
               depending on the implentation. If in doubt, use 
               meta_text()
               which is a variant guarantied to return a string.  See
               L<meta_text>.

               The length of the returned value always matches the 
               length of the sequence.

     Returns : A reference to an array or a string
     Args    : new value, optional

  meta_text
     Title   : meta_text()
     Usage   : $meta_values  = $obj->meta_text($values_arrayref);
     Function: Variant of meta() guarantied to return a textual 
               representation  of meta data. For details, see L<meta>.
     Returns : a string
     Args    : new value, optional

  submeta
     Title   : submeta
     Usage   : $subset_of_meta_values = $obj->submeta(10, 20, 
                                                    $value_string);
               $subset_of_meta_values = $obj->submeta(10, undef, 
                                                  $value_string);
     Function:

               Get and set method for meta data for subsequences.

               Numbering starts from 1 and the number is inclusive, ie 
               1-2
               are the first two residue of the sequence. Start cannot 
               be larger than end but can be equal.

               If the second argument is missing the returned values
               should extend to the end of the sequence.

               If implementation tries to set values beyond the current
               sequence, they should be ignored.

               The return value may be a string or an array reference,
               depending on the implentation. If in doubt, use
               submeta_text() which is a variant guarantied to return a
               string.  See L<submeta_text>.

     Returns : A reference to an array or a string
     Args    : integer, start position
               integer, end position, optional when a third argument 
               present new value, optional

  submeta_text
     Title   : submeta_text
     Usage   : $meta_values  = $obj->submeta_text(20, $value_string);
     Function: Variant of meta() guarantied to return a textual
               representation  of meta data. For details, see L<meta>.
     Returns : a string
     Args    : new value, optional

  revcom
     Title   : revcom
     Usage   : $newseq = $seq->revcom();
     Function: Produces a new Bio::Seq::MetaI implementing object where
               the order of residues and their meta information is
reversed.
     Returns : A new (fresh) Bio::Seq::MetaI object
     Args    : none

  trunc
     Title   : trunc
     Usage   : $subseq = $myseq->trunc(10,100);
     Function: Provides a truncation of a sequence
     Returns : a fresh Bio::Seq::MetaI implementing object
     Args    : Two integers denoting first and last residue of the
sub-sequence.

------------------------------------------------------------------------

NAME
    Bio::Seq::MetaI - Generic superclass for sequence objects with
    residue-based meta information

SYNOPSIS
      # get a Bio::Seq::MetaI compliant object somehow, e.g.:
      # use an existing sequence object
      my $seq = Bio::LocatableSeq(-id=>'test',
                                  -seq=>'ACTGCTAGCT',
                                  -varbose=>1, # to see warnings 
                                 );
      bless $seq, Bio::Seq::Meta;

      # to test this is a meta seq object

      $obj->isa("Bio::Seq::MetaI")
         || $obj->throw("$obj does not implement the Bio::Seq::MetaI
interface");

      # accessors

      $string     = $obj->meta();
      $substring  = $obj->submeta(2,5);
      $unique_key = $obj->accession_number();
                         # unique biological id

DESCRIPTION
    This class implements generic methods for sequences with
    residue-basedmeta information. Meta sequences with meta data are 
    Bio::LocatableSeq
    objects with additional methods to store that meta information. See
    Bio::LocatableSeq and Bio::Seq::MetaI.

    The meta information is always one character per residue long and 
    blank values are space characters (ASCII 32).

    The length of the meta data sequence is not dependent on the amount 
    of
    the meta information. The meta information always covers all the
    residues. If necessary, the implementation quietly truncates or 
    extends metainformation with blank values.

    It is assumed that meta data values do not depend on the nucleotide
    sequence strand value.

    Application specific implementations should inherit from this class 
    to
    override and add to these methods.

SEE ALSO
    Bio::LocatableSeq

FEEDBACK
    ...

AUTHOR - Heikki Lehvaslaiho
    Email heikki at ebi.ac.uk

CONTRIBUTORS
    Chad Matsalla, bioinformatics at dieselwurks.com Aaron Mackey,
    amackey at virginia.edu

APPENDIX
    The rest of the documentation details each of the object methods.
    Internal methods are usually preceded with a _

  new
     Title   : new
     Usage   : $metaseq = Bio::Seq::Meta->new
                    ( -meta => 'aaaaaaaabbbbbbbb',
                      -seq =>  'TKLMILVSHIVILSRM'
                      -id  => 'human_id',
                      -accession_number => 'S000012',
                    );
     Function: Constructor for Bio::Seq::Meta class, meta data being in 
               a string. Note that you can provide an empty quality 
               string.
     Returns : a new Bio::Seq::Meta object

  meta
     Title   : meta
     Usage   : $meta_values  = $obj->meta($values_string);
     Function:

               Get and set method for the meta data starting from 
               residue
               position one. Since it is dependent on the length of the
               sequence, it needs to be manipulated after the sequence.

               The length of the returned value always matches the 
               length of the sequence.

     Returns : meta data in a string
     Args    : new value, string, optional

  _test_gap_positions
     Title   : _test_gap_positions
     Usage   : $meta_values  = $obj->meta_text($values_arrayref);
     Function: Internal test for correct position of gap characters.
               Gap being only '-' this time.

               This method is called from meta() when setting meta data
               but only if verbose is positive as this can be an 
               expensive
               process on very long sequences. Set verbose(1) to see
               warnings when gaps do not align in sequence and meta data
               and turn them into errors by setting verbose(2).

     Returns : true on success, prints warnings
     Args    : none

  meta_text
     Title   : meta_text
     Usage   : $meta_values  = $obj->meta_text($values_arrayref);
     Function: Variant of meta() guarantied to return a textual
               representation  of meta data. For details, see L<meta>.
     Returns : a string
     Args    : new value, optional

  submeta
     Title   : submeta
     Usage   : $subset_of_meta_values = $obj->submeta(10, 20, 
                                                    $value_string);
               $subset_of_meta_values = $obj->submeta(10, undef,
                                                     $value_string);
     Function:

               Get and set method for meta data for subsequences.

               Numbering starts from 1 and the number is inclusive, ie 
               1-2
               are the first two residue of the sequence. Start cannot 
               be larger than end but can be equal.

               If the second argument is missing the returned values
               should extend to the end of the sequence.

               The return value may be a string or an array reference,
               depending on the implentation. If in doubt, use
               submeta_text() which is a variant guarantied to return a
               string.  See L<submeta_text>.

     Returns : A reference to an array or a string
     Args    : integer, start position
               integer, end position, optional when a third argument 
               present
               new value, optional

  submeta_text
     Title   : submeta_text
     Usage   : $meta_values  = $obj->submeta_text(20, $value_string);
     Function: Variant of meta() guarantied to return a textual 
               representation  of meta data. For details, see L<meta>.
     Returns : a string
     Args    : new value, optional

  revcom
     Title   : revcom
     Usage   : $newseq = $seq->revcom();
     Function: Produces a new Bio::Seq::MetaI implementing object where
               the order of residues and their meta information is 
               reversed.
     Returns : A new (fresh) Bio::Seq::MetaI object
     Args    : none

  trunc
     Title   : trunc
     Usage   : $subseq = $seq->trunc(10,100);
     Function: Provides a truncation of a sequence together with meta 
               data
     Returns : a fresh Bio::Seq::MetaI implementing object
     Args    : Two integers denoting first and last residue of the
sub-sequence.

------------------------------------------------------------------------

ok  my $seq = Bio::Seq::Meta->new
    ( -seq => "",
      -meta => "",
      -alphabet => 'dna',
      -id => 'no sequence and no quality but with an id'
    );

# create a random sequence object
ok $seq = Bio::Seq::Meta->new( -seq => "AT-CGATCGA",
                               -id => 'test',
                               -verbose => 2
                             );


ok $seq->meta, "          ";

# create some random meta values, but gap in the wrong place
my $metastring = "a-abb  bb ";
eval {
    $seq->meta($metastring);
};
ok 1 if $@ =~ 'column [2]';
$seq->verbose(1);

# create some random meta values, but not for the last residue
$metastring = "aa-bb  bb";
ok $seq->meta($metastring), $metastring. " ";

# truncate the sequence by assignment
$seq->seq('AT-CGA');
$seq->alphabet('dna');
ok $seq->meta, 'aa-bb ';
ok $seq->meta_text, 'aa-bb ';

# truncate the sequence by trunc method

ok $seq->strand(-1), -1;
ok $seq = $seq->trunc(1,5);
ok $seq->seq, 'AT-CG';
ok $seq->meta, 'aa-bb';
ok $seq->strand, -1;

# revcom

ok $seq = $seq->revcom;
ok $seq->seq, 'CG-AT';
ok $seq->meta, 'bb-aa';
ok $seq->strand, 1;

# submeta

ok $seq->subseq(2,4), 'G-A';
ok $seq->submeta(2,4), 'b-a';
ok $seq->submeta(2,undef, 'c-c'), 'c-c';
ok $seq->submeta(2,4), 'c-c';
ok $seq->meta, 'bc-ca';

ok $seq->meta(''), '     ';
ok $seq->submeta(2,undef, 'c-c'), 'c-c';
ok $seq->meta, ' c-c ';


-- 
______ _/      _/_____________________________________________________
      _/      _/                      http://www.ebi.ac.uk/mutations/
     _/  _/  _/  Heikki Lehvaslaiho          heikki at ebi.ac.uk
    _/_/_/_/_/  EMBL Outstation, European Bioinformatics Institute
   _/  _/  _/  Wellcome Trust Genome Campus, Hinxton
  _/  _/  _/  Cambs. CB10 1SD, United Kingdom
     _/      Phone: +44 (0)1223 494 644   FAX: +44 (0)1223 494 468
___ _/_/_/_/_/________________________________________________________



More information about the Bioperl-l mailing list