TIGR::FASTA::Iterator - TIGR::FASTA::Iterator class for parsing and navigating FASTA format files and streams. An object of this class can parse FASTA records from STDIN and from a pipe.
use TIGR::FASTA::Iterator; my $obj_instance = new TIGR::FASTA::Iterator ($foundation_obj_ref, $error_array_ref, $fasta_file_name);
This module iterates over a FASTA formatted file stream. It provides data extraction and simple analysis routines. This module utilizes acceptance validation of FASTA formatted files via the TIGR::FASTA::Grammar module.
This method returns a new instance of a TIGR::FASTA::Iterator object. It takes three optional parameters: a TIGR::Foundation object ($foundation_object), a reference to an array for logging user error messages ($error_array_ref), and a FASTA file ($db_file) or stream. The filename "-" describes stdin. The new instance is returned on success. If the file supplied cannot be opened or is invalid, this method returns undefined. This method also returns undefined if the parameters supplied are invalid. Errors in parsing are written to the array $error_array_ref, the error file and the log file.
$foundation_object
$error_array_ref
$db_file
This method opens a FASTA file or pipe for reading. It takes in the filename to be opened. If the file name is "-" the input is taken from stdin. On success, this method returns 1. If the file cannot be opened or parsing fails, this method returns undefined.
This method closes the object file stream and resets all internal data structures. The result of the operation is returned. If the file stream is closed successfully, this object returns true (1), otherwise false (undefined).
This method returns true (1) if there are more elements beyond the current element in the filestream. If not, this method returns false (undefined).
This method selects the next record in the file stream for parsing. If the record parses, it is returned, else the method returns undefined. If there is no record in the file stream, the method returns undefined.
This method returns the current TIGR::FASTA::Record object (active record). If the current object (active record) is undefined, this method returns undefined.
To use this module, load the TIGR::FASTA::Iterator package via the use function. Then, create a new instance of the object via the new() method, as shown below. There are several invocations possible for this method since all parameters to new() are optional.
TIGR::FASTA::Iterator
use
new()
To access records from the TIGR::FASTA::Iterator instance, the TIGR::FASTA::Record package must be loaded via the use function.
TIGR::FASTA::Record
An example script using this module follows. The TIGR::Foundation module is included for completeness but does not have to be used.
TIGR::Foundation
#!/usr/local/bin/perl -w # This script accepts FASTA files with the '-i' option # on the command line and validates every record in the file. # Parse errors for each record are collected to the # '@errors_list' array and written to the .error file. # This program concatenates all of the correct records together to # one output file specified with the '-o' option. # NOTE: The '-i' option must be specified before every input file. use strict; use TIGR::FASTA::Iterator; use TIGR::FASTA::Record; MAIN: { my $tf_object = new TIGR::Foundation; my @errors_list = (); my @input_files = (); my $output_file = undef; # Capture the return code from the TIGR::Foundation method my $result = $tf_object->TIGR_GetOptions('i=s' => \@input_files, 'o=s' => \$output_file); if ( $result != 1 ) { $tf_object->bail("Invalid command line options."); } # Create a TIGR::FASTA::Iterator instance using TIGR::Foundation and # an error message list. my $fasta_iterator = new TIGR::FASTA::Iterator $tf_object, \@errors_list; if ( !( defined ( $output_file ) && open OUTFILE, ">$output_file" ) ) { $tf_object->bail("Cannot open output file for writing."); } foreach my $in_file ( @input_files ) { $fasta_iterator->open($in_file) or $tf_object->logLocal("Cannot open or read file $in_file", 2); if ( scalar(@errors_list) > 0 ) { # are there parse errors? while ( @errors_list ) { # get the messages from the list my $message = shift @errors_list; print STDERR $message, "\n"; } } # while ( $fasta_iterator->hasNext() ) { # print each record to OUTFILE my $record = $fasta_iterator->next(); # print each record to OUTFILE if(defined $record) { print OUTFILE $record->toString(); } } } }
1 POD Error
The following errors were encountered while parsing the POD:
You forgot a '=back' before '=head1'
To install TIGR, copy and paste the appropriate command in to your terminal.
cpanm
cpanm TIGR
CPAN shell
perl -MCPAN -e shell install TIGR
For more information on module installation, please visit the detailed CPAN module installation guide.