dust_seq = # file in url above
nums = 0
d.dust_seq.scan(/[N]+/) do |blah|
nums += 1
puts "Index #{d.dust_seq.index(blah.to_s)}"
done
puts "Num of Ns: #{nums}"
In the example, the index for the third of the N groups
is reported as the same as the first, as it's small enough
to fit within it. Is there any way around this?
Thanks.
dust_seq = # file in url above
nums = 0
d.dust_seq.scan(/[N]+/) do |blah|
nums += 1
puts "Index #{d.dust_seq.index(blah.to_s)}"
done
puts "Num of Ns: #{nums}"
In the example, the index for the third of the N groups
is reported as the same as the first, as it's small enough
to fit within it. Is there any way around this?
Thanks.
dust_seq = # file in url above
nums = 0
d.dust_seq.scan(/[N]+/) do |blah|
nums += 1
puts "Index #{d.dust_seq.index(blah.to_s)}"
done
puts "Num of Ns: #{nums}"
In the example, the index for the third of the N groups
is reported as the same as the first, as it's small enough
to fit within it. Is there any way around this?
(not tested):
nums = 0
idx = 0
while idx = dust_seq.index /N+/, idx
nums += 1
puts "Index #{idx}"
idx = Regexp.last_match.end(0)+1
end
puts "Num of Ns: #{nums}"
Thanks - the interpreter didn't like this line, though.
However, I got it working and it seems better than the $`
method, which caused some nasty memory hogging problems
(I now regret not compiling in an kernel OOM killer...).
"Milo Thurston" <nospam@linacreschoolofdefence.org> schrieb im Newsbeitrag
news:ck3el8$7dm$1@news.ox.ac.uk...
···
Carlos <angus@quovadis.com.ar> wrote:
> while idx = dust_seq.index /N+/, idx
Thanks - the interpreter didn't like this line, though.
However, I got it working and it seems better than the $`
method, which caused some nasty memory hogging problems
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
??? Care to explain?
That would explain it. Some of the strings I'm looking at are several MB
in size. I've been writing out the data to disk and flushing stdout, but
$` seemed to leave each complete sequence in memory, causing it to run
out rather rapidly.
···
ts <decoux@moulon.inra.fr> wrote:
> ??? Care to explain?
You create a String object for each call, you don't have this problem with
$~.begin(0)
"Milo Thurston" <nospam@linacreschoolofdefence.org> schrieb im Newsbeitrag
news:ck3grg$8bv$1@news.ox.ac.uk...
> > ??? Care to explain?
> You create a String object for each call, you don't have this problem
with
> $~.begin(0)
That would explain it. Some of the strings I'm looking at are several MB
in size. I've been writing out the data to disk and flushing stdout, but
$` seemed to leave each complete sequence in memory, causing it to run
out rather rapidly.
Yes, that's the reason. I haven't though about this, but as you can see
each reference to $` creates a new string instance: