Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Uninitialized Value Hash Lookup Gene Symbol

by graff (Chancellor)
on Nov 05, 2015 at 22:23 UTC ( [id://1147054]=note: print w/replies, xml ) Need Help??


in reply to Uninitialized Value Hash Lookup Gene Symbol

As mentioned in the previous reply, if you're getting a bunch of "uninitialized variable" warnings, it's probably because the second file you're reading from doesn't have the kind of content that you're expecting on some (or any?) lines.

By the way, understand that "uninitialized" is a warning, not an error. Because you have use warnings; in your script (which is good), you are learning about things that are simply not going as expected; the script continues to run, and empty strings are being printed where you might be expecting non-empty strings. Given that this is the case, try to figure out where your expectations are not being met.

Here's a modified version of the OP script, reformatted to be more compact (and "more perlish") - note how I'm adding some lines to check for unexpected conditions, and report them:

#!/usr/bin/perl use strict; use warnings; use diagnostics; my %geneSymbolConversion; my $input1 = '/scratch/Drosophila/fb_synonym_fb_2014_05.tsv'; open(INF1,"<", $input1 ) or die "$input1: $!\n"; while (<INF1>){ chomp; if ( /^FBgn\d+/ ) { my @fields = split "\t"; $geneSymbolConversion{ $fields[0] } = $fields[1]; } } warn sprintf( "loaded %d gene symbols from %s\n", scalar keys %geneSym +bolConversion, $input1 ); my $input2 = '/scratch/Drosophila/FlyRNAi_data_baseline_vs_EGF.txt'; open(INF2,"<", $input2) or die "$input2: $!\n"; open(OUTF1,">",'FLYRNAi_data_baseline_vs_EGFSymbol.txt') or die $!; while (<INF2>) { chomp; my ($geneID, $EGF_Base, $EGF_Stimulus) = split "\t"; if ( $geneID and $EGF_Base and $EGF_Stimulus ) { my $geneSymbol = $geneSymbolConversion{$geneID} || 'NA'; print OUTF1 join("\t", $geneID, $geneSymbol, $EGF_Base, $EGF_S +timulus), "\n"; } else { warn "$input2: line $.: incomplete data: $_\n"; } }
Also, I added "use strict", and re-arranged things so that declarations of variables are placed closer to where the variables are actually used.

(UPDATE: I added a bit more to report how many gene symbols were loaded from the first input, just in case that's informative.)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1147054]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-04-25 19:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found