Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
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":



  • 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.
  • 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 chanting in the Monastery: (5)
    As of 2025-06-13 12:49 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found

      Notices?
      erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.