Hello Wonderful Perl Monks! I have a tab delimited text file made up of many lines of numerical entries, for example:

0 50 2 48 654732 0 1 1 1 0 2 3 2 1 3 0 50 4 46 723430 0 2 1 2 1 1 1 1 3 1
...etc. The fifth element of each line corresponds to the locus along a chromosome.

What I would like to do is:

-identify each line by its locus

-sort the lines in the same format to smaller files, grouping them by location along the chromosome.

So, all lines with loci between 1 and 1,000,000 go to one file, lines with a loci between 1,000,001 and 2,000,000 go to the next file ...etc.

and so here is my code

#!usr/bin/perl -w use strict; use warnings; my $count = 0; my $placeholder = 0; open (INTERVAL, "/Users/logancurtis-whitchurch/Dropbox/thesis_folder/g +alaxy_chrX_data/chrX_1Mbwindow_nonoverlapping.interval") or die "can' +t open file\n"; while (my $interval = <INTERVAL>){ chomp($interval); my @find_interval = split(/\t/, $interval); my $start = $find_interval[1]; my $end = $find_interval[2]; my $switch = 1; while ($switch == 1) { open (CG, "/Users/logancurtis-whitchurch/Dropbox/thesis_folder +/CompleteGenomics/28_males_inAll/CGS.inall.28.chr.23.txt") or die "ca +n't open CG file\n"; my @SNPs = <CG>; my @get_SNP = split(/\t/, $SNPs[$placeholder]); my $position = $get_SNP[3]; while ($switch == 1) { if (($position < $end) && ($position >= $start)) { my $output_file = "/Users/logancurtis-whitchurch/Desktop/t +emp_$count.txt"; open(OUT, ">$output_file"); print OUT "$SNPs[$placeholder]\n"; close (OUT); $placeholder++; } else { $switch = 0; } } $count++ } }

I print out the correct first temp_2.txt file but no lines are printed to it

I then receive a continuous

Use of uninitialized value within @SNPs in concatenation (.) or strin +g at temp_file_test.pl line 36, <CG> line 1112424.
and there are no spaces at the end of my input file, I checked. Any wisdom is much appreciated!


In reply to Use of Uninitialized in Concatenation or String Error? by ccelt09

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.