Method: Bio::Sequence::Common#window_search
- Defined in:
- lib/bio/sequence/common.rb
#window_search(window_size, step_size = 1) ⇒ Object
This method steps through a sequences in steps of ‘step_size’ by subsequences of ‘window_size’. Typically used with a block. Any remaining sequence at the terminal end will be returned.
Prints average GC% on each 100bp
s.window_search(100) do |subseq|
puts subseq.gc
end
Prints every translated peptide (length 5aa) in the same frame
s.window_search(15, 3) do |subseq|
puts subseq.translate
end
Split genome sequence by 10000bp with 1000bp overlap in fasta format
i = 1
remainder = s.window_search(10000, 9000) do |subseq|
puts subseq.to_fasta("segment #{i}", 60)
i += 1
end
puts remainder.to_fasta("segment #{i}", 60)
Arguments:
-
(required) window_size: Fixnum
-
(optional) step_size: Fixnum (default 1)
- Returns
-
new Bio::Sequence::NA/AA object
179 180 181 182 183 184 185 186 |
# File 'lib/bio/sequence/common.rb', line 179 def window_search(window_size, step_size = 1) last_step = 0 0.step(self.length - window_size, step_size) do |i| yield self[i, window_size] last_step = i end return self[last_step + window_size .. -1] end |