Method: Bio::Sequence::Common#splice

Defined in:
lib/bio/sequence/common.rb

#splice(position) ⇒ Object Also known as: splicing

Return a new sequence extracted from the original using a GenBank style position string. See also documentation for the Bio::Location class.

s = Bio::Sequence::NA.new('atgcatgcatgcatgc')
puts s.splice('1..3')                           #=> "atg"
puts s.splice('join(1..3,8..10)')               #=> "atgcat"
puts s.splice('complement(1..3)')               #=> "cat"
puts s.splice('complement(join(1..3,8..10))')   #=> "atgcat"

Note that ‘complement’ed Genbank position strings will have no effect on Bio::Sequence::AA objects.


Arguments:

  • (required) position: String or Bio::Location object

Returns

Bio::Sequence::NA/AA object



285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
# File 'lib/bio/sequence/common.rb', line 285

def splice(position)
  unless position.is_a?(Locations) then
    position = Locations.new(position)
  end
  s = ''
  position.each do |location|
    if location.sequence
      s << location.sequence
    else
      exon = self.subseq(location.from, location.to)
      begin
        exon.complement! if location.strand < 0
      rescue NameError
      end
      s << exon
    end
  end
  return self.class.new(s)
end