666 |
|
|
667 |
=cut |
=cut |
668 |
|
|
|
## |
|
669 |
sub verify_dir { |
sub verify_dir { |
670 |
my($dir) = @_; |
my($dir) = @_; |
671 |
|
|
696 |
(system($cmd) == 0) || confess "FAILED: $cmd"; |
(system($cmd) == 0) || confess "FAILED: $cmd"; |
697 |
} |
} |
698 |
|
|
699 |
|
|
700 |
|
|
701 |
|
=pod |
702 |
|
|
703 |
|
=head1 read_fasta_record(\*FILEHANDLE) |
704 |
|
|
705 |
|
Usage: ( $seq_id, $sequence, $comment ) = &read_fasta_record(\*FILEHANDLE); |
706 |
|
|
707 |
|
Function: Reads a FASTA-formatted sequence file one record at a time. |
708 |
|
The input filehandle defaults to STDIN if not specified. |
709 |
|
Returns a sequence ID, a pointer to the sequence, and an optional |
710 |
|
record comment (NOTE: Record comments are deprecated, as some tools |
711 |
|
such as BLAST do not handle them gracefully). Returns an empty list |
712 |
|
if attempting to read a record results in an undefined value |
713 |
|
(e.g., due to reaching the EOF). |
714 |
|
|
715 |
|
Author: Gordon D. Pusch |
716 |
|
|
717 |
|
Date: 2004-Feb-18 |
718 |
|
|
719 |
|
=cut |
720 |
|
|
721 |
|
sub read_fasta_record |
722 |
|
{ |
723 |
|
my ($file_handle) = @_; |
724 |
|
my ( $old_end_of_record, $fasta_record, @lines, $head, $sequence, @parsed_fasta_record ); |
725 |
|
|
726 |
|
if (not defined($file_handle)) { $file_handle = \*STDIN; } |
727 |
|
|
728 |
|
$old_end_of_record = $/; |
729 |
|
$/ = "\n>"; |
730 |
|
|
731 |
|
if (defined($fasta_record = <$file_handle>)) |
732 |
|
{ |
733 |
|
chomp $fasta_record; |
734 |
|
@lines = split( /\n/, $fasta_record ); |
735 |
|
$head = shift @lines; |
736 |
|
$head =~ s/^>?//; |
737 |
|
$head =~ m/^(\S+)/; |
738 |
|
$seq_id = $1; |
739 |
|
|
740 |
|
if ($head =~ m/^\S+\s+(.*)$/) { $comment = $1; } else { $comment = ""; } |
741 |
|
|
742 |
|
$sequence = join( "", @lines ); |
743 |
|
|
744 |
|
@parsed_fasta_record = ( $seq_id, \$sequence, $comment ); |
745 |
|
} |
746 |
|
else |
747 |
|
{ |
748 |
|
@parsed_fasta_record = (); |
749 |
|
} |
750 |
|
|
751 |
|
$/ = $old_end_of_record; |
752 |
|
|
753 |
|
return @parsed_fasta_record; |
754 |
|
} |
755 |
|
|
756 |
|
|
757 |
=pod |
=pod |
758 |
|
|
759 |
=head1 display_id_and_seq |
=head1 display_id_and_seq |