Dear perlmonkers, Could you point out what's wrong with my code? I want to get for each gene, the maximum value of the associated frequency printed in the 3rd column, but it gives wrong result (e.g. MUC2), see output below

Frequency GENE 20 SEMA4G 80 CTBP2 80 CTBP2 80 CTBP2 100 SPRN 40 SVIL 80 TIMM23 80 MINPP1 80 BTAF1 20 MUC2 60 MUC2 80 MUC2 100 MUC2 60 OR10G9 60 C11orf91 80 OR4S1 40 OR4C3 40 OR4C3 20 OR4C3 40 OR4C45 60 OR4C45
$file1 = $ARGV[0]; %hashfreq = (); $freq = 0; $geneold = "NA"; open(INPUTR,"<$file1") || die "Can't open \$file1 for reading.\n"; while($line=<INPUTR>){ chomp $line; @toks = split(/\t/, $line); $gene = $toks[1]; if ($gene =~ /^$geneold$/){ if ($toks[0] >= $numold){ $freq = $toks[0]; print $toks[0]."\t".$numold."\t".$freq."\t".$gene."\n"; } else { $freq = $numold; } $hashfreq{$toks[0]} = $freq; } else { $hashfreq{$toks[1]} = $toks[0]; } $numold = $toks[0]; $geneold = $toks[1]; } close(INPUTR); open(OUTD1,">output.txt"); open(INPUTR,"<$file1") || die "Can't open \$file1 for reading.\n"; while($line=<INPUTR>){ chomp $line; @toks = split(/\t/, $line); $idgene = $toks[1]; if (exists $hashfreq{$idgene}){ print OUTD1 $line."\t".$hashfreq{$idgene}."\n"; print $line."\t".$hashfreq{$idgene}."\n"; } }
Frequency GENE MAX 20 SEMA4G 20 80 CTBP2 80 80 CTBP2 80 80 CTBP2 80 100 SPRN 100 40 SVIL 40 80 TIMM23 80 80 MINPP1 80 80 BTAF1 80 20 MUC2 20 60 MUC2 20 80 MUC2 20 100 MUC2 20 60 OR10G9 60 60 C11orf91 60 80 OR4S1 80 40 OR4C3 40 40 OR4C3 40 20 OR4C3 40 40 OR4C45 40 60 OR4C45 40

In reply to Error in Code: Need help by angerusso

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.