Jeremy Volkening
and 1 contributors


BioX::Seq - a (very) basic biological sequence object


    use BioX::Seq;

    my $seq = BioX::Seq->new();

    for (qw/AATG TAGG CCAT TTGA/) {
        $seq .= $_;

    $seq->id( 'test_seq' );

    my $rc = $seq->rev_com(); # original untouched
    print $seq->as_fasta();

    # >test_seq

    $seq->rev_com(); # original modified in-place
    print $seq->as_fastq(22);

    # @test_seq
    # +
    # 7777777777777777

    print $seq->range(3,6)->as_fasta();

    # >test_seq
    # AAAT


BioX::Seq is a simple sequence class that can be used to represent biological sequences. It was designed as a compromise between using simple strings and hashes to hold sequences and using the rather bloated objects of Bioperl. Features (or, depending on your viewpoint, bugs) include auto-stringification and context-dependent transformations. It is meant be used primarily as the return object of the BioX::Seq::Fastx parser, but there may be occasions where it is useful in its own right.

BioX::Seq current implements a small subset of the transformations most commonly used by the author (reverse complement, translate, subrange) - more methods may be added in the future as use suggests and time permits, but the core object will be kept as simple as possible and should be limited to the four current properties - sequence, ID, description, and quality - that satisfy 99% of the author's needs.

Some design decisions have been made for the sake of speed over ease of use. For instance, there is no sanity-checking of the object properties upon creation of a new object or use of the accessor methods. Parameters to the constructor are positional rather than named (testing indicates that this reduces execution times by ~ 40%).



Create a new BioX::Seq object (empty by default). All arguments are optional but are positional and, if provided, must be given in order.

    $seq = BioX::Seq->new( SEQ, ID, DESC, QUALITY );

Returns a new BioX::Seq object.

seq, id, desc, qual

Accessors to the object properties named accordingly. Properties can also be accessed directly as hash keys. This is probably frowned upon by some, but can be useful at times e.g. to perform substution on a property in-place.

    $seq->{id} =~ s/^Unnecessary_prefix//;

Takes zero or one arguments. If an argument is given, assigns that value to the property in question. Returns the current value of the property.


Extract a subsequence from START to END. Coordinates are 1-based.

Returns a new BioX::Seq object, or undef if the coordinates are outside the limits of the parent sequence.


Reverse complement the sequence.

Behavior is context-dependent. In scalar or list context, returns a new BioX::Seq object containing the reverse-complemented sequence, leaving the original sequence untouched. In void context, updates the original sequence in-place and returns TRUE if successful.

translate FRAME

Translate a nucleic acid sequence to a peptide sequence.

FRAME specifies the starting point of the translation. The default is zero. A FRAME value of 0-2 will return the translation of each of the three forward reading frames, respectively, while a value of 3-5 will return the translation of each of the three reverse reading frames, respectively.

as_fasta LINE_LENGTH

Returns a string representation of the sequence in FASTA format. Requires that, at a minimum, the <seq> and <id> properties be defined. LINE_LENGTH, if given, specifies the line length for wrapping purposes (default: 60).


Returns a string representation of the sequence in FASTQ format. Requires that, at a minimum, the <seq> and <id> properties be defined. DEFAULT_QUALITY, if given, specifies the default Phred quality score to be assigned to each base if missing - for instance, if converting from FASTA to FASTQ (default: 20).


No input validation is performed during construction or modification of the object properties.

Performing certain operations (for instance, s///) on a BioX::Seq object relying on auto-stringification may convert the object into a simple unblessed scalar containing the sequence string. You will likely know if this happens (you are using strict and using warnings, right?) because your script will throw an error if you try to perform a class method on the (now) unblessed scalar.

Please report bugs to the author.


Jeremy Volkening <jeremy *at*>


Copyright 2014 Jeremy Volkening

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <>.