]> git.donarmstrong.com Git - biopieces.git/commitdiff
fix embl parser
authormartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Sun, 2 Aug 2009 19:01:53 +0000 (19:01 +0000)
committermartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Sun, 2 Aug 2009 19:01:53 +0000 (19:01 +0000)
git-svn-id: http://biopieces.googlecode.com/svn/trunk@623 74ccb610-7750-0410-82ae-013aeee3265d

code_perl/Maasha/EMBL.pm

index 5134b033d958dfa62e3862e410cda77b0b6e3ccb..14787496b8ec2caf93cbb11e1bc910c7b1cfff3f 100644 (file)
@@ -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++;