-sub fasta_format_ok
-{
- # Martin A. Hansen, March 2007.
-
- # Checks if a given FASTA file is formatted with
- # one header per line and one sequence per line.
- # returns 1 if so, else 0.
-
- my ( $path, # full path to FASTA file
- ) = @_;
-
- # Returns boolean
-
- my ( $fh, $line, $count );
-
- $fh = Maasha::Common::read_open( $path );
-
- $count = 0;
-
- while ( $line = <$fh> )
- {
- if ( not $count % 2 and substr( $line, 0, 1 ) ne ">" ) {
- return 0;
- }
-
- $count++;
- }
-
- close $fh;
-
- return 1;
-}
-
-
-sub get_entries
-{
- # Martin A. Hansen, December 2006.
-
- # Parses a fasta file and returns a list of headers and sequence tuples.
-
- my ( $path, # full path to FASTA file
- $count, # number of sequences to read - OPTIONAL
- ) = @_;
-
- # returns list of tuples
-
- my ( $fh, $entry, @entries );
-
- $fh = Maasha::Common::read_open( $path );
-
- while ( $entry = get_entry( $fh ) )
- {
- push @entries, $entry;
-
- if ( $count and $count == @entries ) {
- last;
- }
- }
-
- close $fh;
-
- return wantarray ? @entries : \@entries;
-}
-
-
-sub put_entries
-{
- # Martin A. Hansen, March 2004.
-
- # writes fasta sequences to STDOUT or file
-
- my ( $entries, # list of fasta entries
- $path, # full path to file - OPTIONAL
- $wrap, # line width - OPTIONAL
- ) = @_;
-
- my ( $fh );
-
- $fh = Maasha::Common::write_open( $path ) if $path;
-
- map { put_entry( $_, $fh, $wrap ) } @{ $entries };
-
- close $fh if defined;
-}
-
-
-sub wrap
-{
- # Martin A. Hansen, June 2007
-
- # Wraps the sequence of a given FASTA entry
- # to a given length.
-
- my ( $entry, # FASTA entry
- $wrap, # wrap length
- ) = @_;
-
- # Returns nothing.
-
- Maasha::Seq::wrap( \$entry->[ SEQ ], $wrap );
-}
-
-