Hello Wonderful Perl Monks! I have a tab delimited text file made up of many lines of numerical entries, for example:
...etc. The fifth element of each line corresponds to the locus along a chromosome.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
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
and there are no spaces at the end of my input file, I checked. Any wisdom is much appreciated!Use of uninitialized value within @SNPs in concatenation (.) or strin +g at temp_file_test.pl line 36, <CG> line 1112424.
In reply to Use of Uninitialized in Concatenation or String Error? by ccelt09
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |