in reply to Re^2: Bioinformatics: Slow Parsing of a Fasta File
in thread Bioinformatics: Slow Parsing of a Fasta File

I admit, I didn't think that that was legal. But anyway, the fix is quite trivial and has no affect upon performance:

#! perl -slw use strict; use Data::Dump qw[ pp ]; my %sequences; local $/ = '>'; (undef) = scalar <DATA>; ## Discard first delimiter local $/ = "\n>"; while( my $record = <DATA> ) { my @lines = split "\n", $record; pop @lines if $lines[-1] eq '>'; my $id = shift @lines; $sequences{ $id } = join'', @lines; } pp \%sequences; __DATA__ >uc002yje.1 > chr21:13973492-13974491 cccctgccccaccgcaccctggattactgcacgccaagaccctcacctga acgcgccctacactctggcatgggggaacccggccccgcagagccctgga CTCTGACATTGGAGGACTCCTCGGCTACGTCCTGGACTCCTGCACAAGAG >uc002yje.2 > chr21:13974492-13975432 cccctgccccaccgcaccctggattactgcacgccaagaccctcacctga acgcgccctacactctggcatgggggaaaaaacccggccccgcagagccctgga CTCTGACATTGGAGGACTCCTCGGCTACGTCCTGGACTCCTGCACAAGAG >uc002yje.3 > chr21:13975431-13976330 cccctgccccaccgcaccctggattactgcacgccaagaccctcacctga acgcgccctacactctggcatgggggaacccggccccgcagagggccctgga CTCTGACATTGGAGGACTCCTCGGCTACGTCCTGGACTCCTGCACAAGAG

Produces:

C:\test>fasta { "uc002yje.1 > chr21:13973492-13974491" => "cccctgccccaccgcaccctggatt +actgcacgccaagaccctcacctgaacgcgccctacactctggcatgggggaacccggccccgcagagc +cctggaCTCTGACATTGGAGGACTCCTCGGCTACGTCCTGGACTCCTGCACAAGAG", "uc002yje.2 > chr21:13974492-13975432" => "cccctgccccaccgcaccctggatt +actgcacgccaagaccctcacctgaacgcgccctacactctggcatgggggaaaaaacccggccccgca +gagccctggaCTCTGACATTGGAGGACTCCTCGGCTACGTCCTGGACTCCTGCACAAGAG", "uc002yje.3 > chr21:13975431-13976330" => "cccctgccccaccgcaccctggatt +actgcacgccaagaccctcacctgaacgcgccctacactctggcatgggggaacccggccccgcagagg +gccctggaCTCTGACATTGGAGGACTCCTCGGCTACGTCCTGGACTCCTGCACAAGAG", }

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.