knirirr has asked for the wisdom of the Perl Monks concerning the following question:
Several (hundreds, even) sequences may be read, and it's apparently necessary to define a new object relating @nreg to the name of each sequence, as I find that the values for all sequences are pushed into the same array. Can anyone suggest a suitable way to set up a "new" method to relate a different @nreg to a particular sequence name, please? I've tried various permutations, which either use the same array every time or refuse to bless it (e.g. "Attempt to bless into a reference at..." messages appear). Thanks for any suggestions!sub addregion { my ($start,$end) = @_; if ($start > $end) { ($start,$end) = ($end,$start); } my $done = 0; my $k; my $tempcoding = 0; for ($k=0;$k<@nreg;$k++) { # calculate sum of bases $tempcoding += $nreg[$k][1] - $nreg[$k][0] + 1; # new region starts after old region ends next if ($nreg[$k][1] < $start); # new region ends before old region starts if ($end < $nreg[$k][0]) { splice(@nreg,$k,0,[$start,$end]); $done = 1; last; } # regions overlap $nreg[$k][0] = $start < $nreg[$k][0] ? $start : $nreg[$k][0]; $nreg[$k][1] = $end > $nreg[$k][1] ? $end : $nreg[$k][1]; $done = 1; # Combine two regions if the new section has brough about an o +verlap while ($k < $#nreg and $nreg[$k][1] > $nreg[$k+1][0]) { $nreg[$k][1] = $nreg[$k+1][1]; splice(@nreg,$k+1,1); } last; } unless ($done) { push @nreg,[$start,$end]; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Array of arrays used within object
by esh (Pilgrim) on Aug 06, 2003 at 16:56 UTC | |
|
Re: Array of arrays used within object
by MidLifeXis (Monsignor) on Aug 06, 2003 at 17:08 UTC | |
by knirirr (Scribe) on Aug 07, 2003 at 08:43 UTC | |
by esh (Pilgrim) on Aug 08, 2003 at 01:26 UTC | |
by knirirr (Scribe) on Aug 08, 2003 at 09:29 UTC | |
by knirirr (Scribe) on Aug 07, 2003 at 15:44 UTC | |
by esh (Pilgrim) on Aug 08, 2003 at 01:36 UTC |