#!/usr/bin/perl sub read_fasta { my $filename = $_[0]; my @LINES; if ( defined ( $filename ) ) { open FASTA, $filename or die("Unable to open FASTA.\n"); while () { push @LINES , $_; } close FASTA; } else { while () { push @LINES , $_; } } my @fasta; my $seqentry = -1; foreach my $line ( @LINES ) { chomp $line; if ($line=~ m/^>(.*)/) { $seqentry++; my $id = $1 if $line =~ /^>(\S+)/; my $comment = $1 if $line =~ /^>\S+\s+(.*)/; $fasta[$seqentry]{comment} = $comment if defined $comment; $fasta[$seqentry]{seqentry} = $seqentry; $fasta[$seqentry]{id} = $id; } elsif ($line =~ m/^([A-Za-z\-]+)/) { $fasta[$seqentry]{seq} .= uc ( $1 ); } } return @fasta; } 1;