http://qs321.pair.com?node_id=1076062


in reply to Re^3: Can you make this code shorter and/or quicker as well?
in thread Can you make this code shorter and/or quicker as well?

Here's one option:

use strict; use warnings; for my $fastaRec ( extract_query_data('fastaFile.fa') ) { print $fastaRec, "\n"; } sub extract_query_data { my ($file) = @_; my @arr; local $/ = '>'; open my $fh, '<', $file or die $!; while (<$fh>) { chomp; my ( $id, $seq ) = /(.+?\n)(.+)/s or next; $seq =~ s/\s+//g; push @arr, ">$id$seq"; } close $fh; return @arr; }

You'll note that the subroutine returns an array of fasta records.

Replies are listed 'Best First'.
Re^5: Can you make this code shorter and/or quicker as well?
by Anonymous Monk on Feb 25, 2014 at 00:37 UTC
    Aha,
    I see! Thank you very much for your time!