Greetings monks, I am *extremely* new to perl, and attempting to use it for a bioinformatics problem. I'm trying to process some bioinformatics data-- I have a large chunk of text which includes information about a group of genes. All of the gene names are in the wrong nomenclature. I want to keep my text file intact, but replace each instance of the incorrect nomenclature with the corresponding correct name. I've put together a hash with the incorrect(current) name for each gene as keys, and the correct(new) name as the values. I figured that I could make my text file into an array, and use some sort of regular expression to find matches to keys in the hash, and replace them with the respective value. I'm not sure how to do this part, and it's a little beyond the scope of the perl manuals I've been using. This is what I have so far:

use warnings; use strict; my $infile1 = "InParanoid_Modified.txt"; my $infile2 = "IPArray.txt"; my $outfile = "IPEnsembl.txt"; open (IN1, $infile1) or die $!; open (IN2, $infile2) or die $!; open (OUT, ">$outfile") or die $!; my %Ensembl while ($infile2 = <IN1>){ chomp ($infile); my @values = split " ", $infile; my $ENSG = shift @values; foreach my $ENSP(@values){ $Ensembl{$ENSG} = $ENSP; } } while ($infile1 = <IN1>){ chomp ($infile1); my $IPReplace = translate($infile1); print OUT $IPReplace; } sub translate { my close (IN1); close (IN2);

any help would be greatly appreciated!


In reply to using a hash as a sort of dictionary by McCaslin

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.