Dear All,

More of a conceptual problem than a Perl problem per se.

I am parsing the output of a program (non-perl and not editable) that compares two DNA sequences. The results are given as sets of 2-D co-ordinates.

e.g.

[ ['NM_144963','2713','4091'], ['NM_144963','1949','2712'] ];
where field 1 is the name
field2 is the start coordinate
and field3 is the end coordinate

A simple sort allows me to sort the above and calculate the coverage

my @sorted = sort {($a->[1] <=>$b->[1]) || ($a->[2] <=> $b->[2])}@ +array; my $coverage = 0; for (@sorted){ $coverage += $_->[2] - $_->[1] +1; } printf "cover = %.1f%% \n", $coverage/$length *100;
All well and good for the above case. But parts of my data are overlapping e.g.
[ ['NM_176827','618','710'], ['NM_176827','621','710'], ['NM_176827','622','692'], ['NM_176827','629','710'] ]
Here my code breaks down and I cannot for the life of me think of a data structure that will allow adequately deal with both cases (i.e a collection of distinct hits, a collection of overlapping hits) or worse a combination of the two.

When they overlap I need to pick the longest hit. (i.e. the first array above).

Am I just having a brain metldown today - Can someone point me in the direction of an obvious solution. Thanks a lot

A.A.


In reply to Comparing 2-D co-ordinates by aging acolyte

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.