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.