Hi, i am stuck with a mapping problem. my input file and script are below. I'm trying to map, if elements is found in two keys, then map the two keys. The script mapping some part of the elements but not fully. I can't seem to see what the problem is. The numbers in front of each (e.g. 2 C00080MM) element are not mapped and i'm removing them. Is it the empty space causing the problem?. Thanks for your help!

INPUT data: R00009MM#R00009#2 C00027MM <=> C00007MM + 2 C00001MM R00014MM#R00014#C00022MM + C00068MM + C00080MM <=> C05125MM + C00011MM R00081MM#R00081#C00007MM + 4 C00126MM + 8 C00080MM <=> 4 C00125MM + 2 +C00001MM + 4 C00080Cyto R00086MM#R00086#C00008MM + C00009MM + 7 C00080Cyto <=> C00002MM + C000 +01MM + 7 C00080MM R00094MM#R00094#2 C00051MM + C00003MM <=> C00127MM + C00004MM + C00080 +MM
OUTPUT expected. R00081MM -> R00094MM R00014MM -> R00086MM R00081MM -> R00086MM R00086MM -> R00081MM R00094MM -> R00014MM R00009MM -> R00081MM
#!/usr/bin/perl use warnings; use strict; open (IN, "input.txt") || die $!; #open (OUT,">output.txt") || die $!; my %groups; my @rxnGraph; while (<IN>) { chomp $_; my @rxn = split /#/, $_; next if length $rxn[1] == 0; my ($left_side, $right_side) = split /\s*<=>\s*/, $rxn[2]; my @left_els = split /\s*\+\s*/, $left_side; my @right_els = split /\s*\+\s*/, $right_side; my $x=0; for ($x=0; $x<=$#left_els; $x++){ $left_els[$x]=~s/^[0-9]//; if($left_els[$x]=~/C.*/){ #print ">>",$left_els[$x],"\n" } } # print ">L>@left_els\n"; my $y=0; for ($y=0; $y<=$#right_els; $y++){ $right_els[$y]=~s/^[0-9]//; if($right_els[$y]=~/C.*/){ # print ">>>$right_els[$y]\n"; } } # print ">R>@right_els\n"; $groups{$_}{left} = $rxn[0] for @left_els; $groups{$_}{right} = $rxn[0] for @right_els; } #while( my ($keys, $values) = each(%groups)){ #print ">>K>>>$keys\n"; #} for my $grp (keys %groups) { if (2 == grep exists $groups{$grp}{$_}, qw/left right/) { print "$groups{$grp}{right} ->", " $groups{$grp}{left}\n"; # push @rxnGraph, "$groups{$grp}{right},", # " $groups{$grp}{left}\n"; } } #print OUT @rxnGraph;

In reply to Mapping issues by filipo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.