Good day, dear Monks!

Unfortinatly I use Perl rather rarely. At the current moment I'm dealing with genomic coordinates. I have two large arrays with data. The fist contains some coordinates and the second contains distances. Among coordinates there are unique ones and repeats. Although distance value for every coordinate is unique. I would like to compose the final set of unique coordinates and corresponding distances. The main thing is excluding the repeating coordinates. The condition is the following: to chose those pare of coordinate - distance which has the smallest distance value.

So the example of the data the following:

coordinate distance 567 344 1345 567 2346 78 3456 67 3456 789 4678 45 5349 6 6700 124 6700 50 8964 560

I have written some very simple script

$coord = 'coordinate.txt'; open(COORD, $coord) || die("Couldn't read file $coord\n"); $dist = 'dist.txt'; open(DIST, $dist) || die("Couldn't read file $dist\n"); @d = <DIST>; @c = <COORD>; for ( $i = 0; $i <= 13; $i++ ) { if ( $c[$i] != $c[$i+1] ) { printf "%d %d\n", $c[$i], $d[$i]; } }

It selects the last line of repeat without comparing the distance values. How would you advise to change it to get only unique coordinetes-distances pairs. And to chose those pare of coordinate - distance which has the smallest distance value if there are repetative coordinates.

So for those data, given earlier I try to get the output like this:
coordinate distance 567 344 1345 567 2346 78 3456 67 4678 45 5349 6 6700 50 8964 560

Thank you in advance!


In reply to Repeats exclusion by Grig

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.