edwardtickle has asked for the wisdom of the Perl Monks concerning the following question:
I'm very new to Perl and am working on a Bioinformatics project at University. I have FILE1 containing a list of positions, in the format:
99269 550 100 126477 1700
And FILE2 in the format:
517 1878 forward 700 2500 forward 2156 3289 forward 99000 100000 forward 22000 23000 backward
I want to compare every position in FILE1 to every range in values on FILE2, and if a position falls into one of the ranges then i want to print the position, range and direction.
So my expected output would be:
99269 99000 100000 forward 550 517 1878 forward 1700 517 1878 forward
Currently it will run with no errors, however it doesn't output any information so i am unsure where i am going wrong! When i split the final 'if' rule it runs but will only work if the position is on exacly the same line as the range.
Any help would be much appreciated.
I have posted the same question on Stackoverflow as i'm after a fairly urgent answer.
My code is as follows:
#!/usr/bin/perl use strict; use warnings; my $outputfile = "/Users/edwardtickle/Documents/CC22CDS.txt"; open FILE1, "/Users/edwardtickle/Documents/CC22positions.txt" or die "cannot open > CC22: $!"; open FILE2, "/Users/edwardtickle/Documents/CDSpositions.txt" or die "cannot open > CDS: $!"; open (OUTPUTFILE, ">$outputfile") or die "Could not open output file: +$! \n"; while (<FILE1>) { if (/^(\d+)/) { my $CC22 = $1; while (<FILE2>) { if (/^(\d+)\s+(\d+)\s+(\S+)/) { my $CDS1 = $1; my $CDS2 = $2; my $CDS3 = $3; if ($CC22 > $CDS1 && $CC22 < $CDS2) { print OUTPUTFILE "$CC22 $CDS1 $CDS2 $CDS3\n"; } } } } } close(FILE1); close(FILE2);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Comparing FILE1 value to FILE2 range and printing matches
by RichardK (Parson) on Oct 17, 2014 at 12:13 UTC | |
by edwardtickle (Initiate) on Oct 17, 2014 at 14:44 UTC | |
|
Re: Comparing FILE1 value to FILE2 range and printing matches
by choroba (Cardinal) on Oct 17, 2014 at 10:21 UTC | |
by edwardtickle (Initiate) on Oct 17, 2014 at 10:31 UTC | |
|
Re: Comparing FILE1 value to FILE2 range and printing matches
by biohisham (Priest) on Oct 18, 2014 at 04:09 UTC | |
|
Re: Comparing FILE1 value to FILE2 range and printing matches
by CountZero (Bishop) on Oct 18, 2014 at 20:02 UTC | |
|
Re: Comparing FILE1 value to FILE2 range and printing matches
by Laurent_R (Canon) on Oct 18, 2014 at 11:12 UTC |