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

NAME

FASTX::Reader - A lightweight FASTA and FASTQ reader based on Heng Li's parser.

VERSION

version 0.05

SYNOPSIS

  use FASTX::Reader;
  my $filepath = '/path/to/assembly.fastq';
  die "Input file not found: $filepath\n" unless (-e "$filepath");
  my $fasta_reader = FASTX::Reader->new({ filename => "$filepath" });

  while (my $seq = $fasta_reader->getRead() ) {
    print $seq->{name}, "\t", $seq->{seq}, "\t", $seq->{qual}, "\n";
  }

NAME

FASTX::Reader - a lightweight module to parse FASTA and FASTQ files, using Heng Li's readfq() method https://github.com/lh3/readfq, packaged in an object oriented parser.

METHODS

new()

Initialize a new FASTX::Reader object passing 'filename' argument. Will open a filehandle stored as $object->{fh}.

  my $seq_from_file = FASTX::Reader->({ filename => "$file" });

To read from STDIN either pass {{STDIN}} as filename, or don't pass a filename at all:

  my $seq_from_stdin = FASTX::Reader->();

getRead()

Will return the next sequence in the FASTA / FASTQ file using Heng Li's implementation of the readfq() algorithm. The returned object has these attributes:

name

header of the sequence (identifier)

comment

any string after the first whitespace in the header

seq

actual sequence

qual

quality if the file is FASTQ

getFastqRead()

If the file is FASTQ, this method returns the same read object as getRead() but with a faster parser. Attributes of the returned object are name, comment, seq, qual (as for getRead()).

getFileFormat(filename)

This subroutine returns 'fasta', 'fastq' or <undef> for a given filepath (this is not a method of the instantiated object)

ACKNOWLEDGEMENTS

Heng Li's readfq()

This mnodule is a wrapper around the readfq() subroutine originally written by Heng Li, that I adapted to retain sequence comments.

See: readfq repository

CONTRIBUTORS

Fabrizio Levorin

has substantially contributed to the development of this module, and is a collaborator in the GitHub repository

AUTHOR

Andrea Telatin <andrea.telatin@quadram.ac.uk>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2019 by Andrea Telatin.

This is free software, licensed under:

  The MIT (X11) License