Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

This is really frustrating me. The script I'm writing is indexing coordinates in a hash and then using those index numbers to pull out values from an array.

The weird thing is that if the value begins with 2 or 22 it will not print. Any other number works. I'll show you two variations and output of the script.

First variation. This is what I want the script to do. Print chromosome, position, value.

#!/usr/bin/perl use strict; use warnings; use File::Find; use Scalar::Util qw(looks_like_number); open IN, "/home/big/scratch/affy_map.txt" or die "Cannot open referenc +e\n"; my %ref; my $head = <IN>; my $index = 0; while(<IN>){ chomp $_; my @row = split /\t/, $_; my $value = join "\t", $row[1],$row[2]; if($row[1] == 2 && $row[2] <= 50000 && $row[2] <= 51113178) { +$ref{$index}=$value; print $index."\t".$value."\n";} if($row[1] == 22 && $row[2] <= 16300001 && $row[2] <= 20500000 +) { $ref{$index}=$value; print $index."\t".$value."\n"; } $index++; } close(IN); my @files; my $masterDirect = "/nfs/archive02/big/Norm/norm_gcc/"; find(\&file_names, $masterDirect); sub file_names { if( -f && $File::Find::name=~/\.nzd$/) { push @files, $File::Find::name; } } my $count=0; foreach(@files){ $count++; if($count % 100 == 0 ){ print "\n","-" x 10, " $count ", "-" x 10, +"\n";} undef my @probes; open IN, $_; #file name handling my @inDir = split "\/", $_; my $id = pop(@inDir); $id =~ s/\.gcc.nzd$//; #header test $head =<IN>; if(looks_like_number($head)) { push @probes, $head; } #open output open OUT, ">/home/big/scratch/phase1_affy/".$id."_select_probeset. +txt"; #load probe array @probes = <IN>; close(IN); foreach my $key (sort keys %ref){ #intended function print OUT $ref{$key}."\t".$probes[$key]; #testing my @temp = split "\t", $ref{$key}; foreach(@temp){if($temp[0] == 2){print $key."\t".$ref{$key}."\ +t".$probes[$key];}} } close(OUT); }

Here's the output for the test. The printing from the reference file is flawless. The first number is the $key or index number. The second is frome $probes$key why is the $ref{$key} missing?

146529 0.777314368326637 146529 0.777314368326637 146530 0.116241153901913 146530 0.116241153901913 146531 0.940593233609167 146531 0.940593233609167 146532 -0.150051720847835 146532 -0.150051720847835 146533 0.037500790454267 146533 0.03750079045426

Variation 2.

... foreach my $key (sort keys %ref){ print OUT $ref{$key}."\t".$probes[$key]; my @temp = split "\t", $ref{$key}; foreach(@temp){if($temp[0] == 2){print $key."\t".$ref{$key}."\ +n";}} }

And its output. See now it's printing correctly. $key and $ref{$key}

146542 2 31852 146542 2 31852 146543 2 37693 146543 2 37693 146544 2 40415 146544 2 40415 146545 2 40814 146545 2 40814 146546 2 41256 146546 2 41256 146547 2 43652 146547 2 43652

I'm not as experienced as a lot of you monks out there but I've never experienced this error. I thought it might be a DOS->UNIX file problem but I performed perl -pi -e 's/\R/\n/g' input_files.txt for all the input the script sees. It prints the same value twice because there are two elements in the @temp array. I'm really at a loss right now.


In reply to Hash will not print if a value begins with 2 under certain conditions by pimperator

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2024-04-19 09:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found