From c588cd796d04e9fa3c0ca70a28030a5c0e236bb1 Mon Sep 17 00:00:00 2001 From: martinahansen Date: Sun, 2 Aug 2009 19:01:53 +0000 Subject: [PATCH] fix embl parser git-svn-id: http://biopieces.googlecode.com/svn/trunk@623 74ccb610-7750-0410-82ae-013aeee3265d --- code_perl/Maasha/EMBL.pm | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/code_perl/Maasha/EMBL.pm b/code_perl/Maasha/EMBL.pm index 5134b03..1478749 100644 --- a/code_perl/Maasha/EMBL.pm +++ b/code_perl/Maasha/EMBL.pm @@ -83,7 +83,7 @@ sub parse_embl_entry # returns data structure - my ( @lines, $i, %hash, $ft, $seq, $key, $val ); + my ( @lines, $i, %hash, $ft, $seq, $key, $val, $ref ); @lines = split "\n", $entry; @@ -101,7 +101,7 @@ sub parse_embl_entry $val = $2; if ( $key =~ /RN|RX|RP|RG|RA|RT|RL/ ) { - add_ref( \%hash, \@lines, $i, $args->{ "keys" } ) if $key eq "RN"; + add_ref( \%hash, \@lines, $i, $args->{ "keys" } ) if $key eq "RN"; } elsif ( exists $hash{ $key } and $key eq "FT" ) { $hash{ $key } .= "\n" . $val; } elsif ( exists $hash{ $1 } ) { @@ -171,16 +171,24 @@ sub add_ref # Returns nothing. - my ( %ref ); + my ( %ref, $key, $val ); if ( $args ) { - while ( $lines->[ $i ] =~ /^(\w{2})\s+(.*)/ and $1 ne 'XX' and exists $args->{ $1 } ) + while ( $lines->[ $i ] =~ /^(\w{2})\s+(.*)/ ) { - if ( exists $ref{ $1 } ) { - $ref{ $1 } .= " " . $2; - } else { - $ref{ $1 } = $2; + $key = $1; + $val = $2; + + last if $key eq "XX"; + + if ( exists $args->{ $key } ) + { + if ( exists $ref{ $key } ) { + $ref{ $key } .= " " . $val; + } else { + $ref{ $key } = $val; + } } $i++; -- 2.39.5