FASTX::Reader - A lightweight module to parse FASTA and FASTQ files, based on Heng Li's readfq() method, packaged in an object oriented parser.
version 0.50
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"; }
Each GitHub release of the module is tested by Travis-CI using multiple Perl versions (5.14 to 5.28).
In addition to this, every CPAN release is tested by the CPAN testers grid.
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:
{{STDIN}}
my $seq_from_stdin = FASTX::Reader->();
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:
header of the sequence (identifier)
any string after the first whitespace in the header
actual sequence
quality if the file is FASTQ
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()). It will alter the status attribute of the reader object if the FASTQ format looks terribly wrong.
status
use FASTX::Reader; my $filepath = '/path/to/assembly.fastq'; my $fasta_reader = FASTX::Reader->new({ filename => "$filepath" }); while (my $seq = $fasta_reader->getFastqRead() ) { die "Error parsing $filepath: " . $fasta_reader->{message} if ($fasta_reader->{status} != 1); print $seq->{name}, "\t", $seq->{seq}, "\t", $seq->{qual}, "\n"; }
This subroutine returns 'fasta', 'fastq' or <undef> for a given filepath (this is not a method of the instantiated object)
This module is a has been inspired by the readfq() subroutine originally written by Heng Li, that I updated to retain sequence comments. See: readfq repository
has contributed to the prototyping of this module
The module I would have used if it was available when I started working on this. The .gz reader implementation comes from this module.
Andrea Telatin <andrea@telatin.com>
This software is Copyright (c) 2019 by Andrea Telatin.
This is free software, licensed under:
The MIT (X11) License
To install FASTX::Reader, copy and paste the appropriate command in to your terminal.
cpanm
cpanm FASTX::Reader
CPAN shell
perl -MCPAN -e shell install FASTX::Reader
For more information on module installation, please visit the detailed CPAN module installation guide.