Hi all,

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);

In reply to Comparing FILE1 value to FILE2 range and printing matches by edwardtickle

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.