Grig has asked for the wisdom of the Perl Monks concerning the following question:
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!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Repeats exclusion
by suhailck (Friar) on Sep 12, 2010 at 06:12 UTC | |
by Grig (Novice) on Sep 12, 2010 at 16:07 UTC | |
by JavaFan (Canon) on Sep 13, 2010 at 14:12 UTC | |
by suhailck (Friar) on Sep 14, 2010 at 05:52 UTC | |
|
Re: Repeats exclusion
by repellent (Priest) on Sep 12, 2010 at 07:21 UTC | |
by Grig (Novice) on Sep 12, 2010 at 11:22 UTC | |
by repellent (Priest) on Sep 12, 2010 at 11:43 UTC | |
|
Re: Repeats exclusion
by jwkrahn (Abbot) on Sep 12, 2010 at 08:16 UTC | |
by BrowserUk (Patriarch) on Sep 12, 2010 at 09:51 UTC | |
|
Re: Repeats exclusion
by AnomalousMonk (Archbishop) on Sep 14, 2010 at 00:11 UTC | |
|
Re: Repeats exclusion
by jfraire (Beadle) on Sep 14, 2010 at 04:47 UTC | |
|
Re: Repeats exclusion
by TomDLux (Vicar) on Sep 15, 2010 at 18:56 UTC | |
|
Re: Repeats exclusion
by TomDLux (Vicar) on Sep 15, 2010 at 19:32 UTC |