The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.


  Tie::File::AnyData::Bio::Fasta - Accessing fasta records in a file via a Perl array.


    use Tie::File::AnyData::Bio::Fasta;

    ## Process the fasta records in a file 1 by 1:
    my $fastafile = "seqs.fa"; ## File containing some fasta sequences
    tie my @fa_array, 'Tie::File::AnyData::Bio::Fasta', $fastafile or die $!;
    for my $fa_rec (@fa_array){
       ## Process the record
    untie @fa_array;

    ## Take randomly 10 fasta sequences from a file and put them in another one:
    use Fcntl qw/O_RDONLY O_RDWR O_CREAT/;
    use List::Util qw/shuffle/;
    tie my @in,  'Tie::File::AnyData::Bio::Fasta', $in_fasta, mode => O_RDONLY or die $!;
    tie my @out, 'Tie::File::AnyData::Bio::Fasta', $out_fasta, mode => O_RDWR | O_CREAT or die $!;
    @out = (shuffle @in)[0..10];
    untie @in;
    untie @out;

    ## All the array operations are allowed:
    push @fa_array, $fasta_rec; ## Append a fasta record at the end of the file
    unshift @fa_array, $fasta_red; ## Put a fasta record at the beginning of the file
    my $fasta_rec = pop  @fa_array; ## Remove the last record of the file (assigned to $fasta_rec)
    my $fasta_rec = shift @fa_array; ## Remove the first record of the file (assigned to $fasta_rec)


  C<Tie::File::AnyData::Bio::Fasta> allows the management of fasta files via a Perl array
  through C<Tie::File::AnyData>, so read the documentation of this module for further details on its internals.


  This module accepts the same parameters as C<Tie::File> except C<recsep>,
  that is always assigned to C<\r\n> if it is run on a Windows machine or C<\n> otherwise.


  Miguel Pignatelli

  Please send any comment to:

  The most recent version of this module, should be available at CPAN.


  Please report any bugs or feature requests to
  C<bug-tie-file-anydata at>, or through the web interface at

You can find documentation for this module with the perldoc command:

     perldoc Tie::File::AnyData


  Copyright 2007 Miguel Pignatelli, all rights reserved.

  This library is free software; you may redistribute it and/or modify it
  under the same terms as Perl itself.


  This module comes with ABSOLUTELY NO WARRANTY.