Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^2: Can you make this code shorter and/or quicker as well?

by Anonymous Monk
on Feb 25, 2014 at 00:26 UTC ( [id://1076059]=note: print w/replies, xml ) Need Help??


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

How can I put it in a sub-routine that I could use inline my script?
Something like:
sub extract_query_data($file);

Replies are listed 'Best First'.
Re^3: Can you make this code shorter and/or quicker as well?
by Anonymous Monk on Feb 25, 2014 at 00:27 UTC
    Sorry, I meant:
    extract_query_data($file);

      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.

        Aha,
        I see! Thank you very much for your time!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1076059]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-04-19 06:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found