Module: Rbfam::Utils

Defined in:
lib/rbfam/modules/utils.rb

Class Method Summary collapse

Class Method Details

.aa_sequence_from_entrez(id, position, window) ⇒ Object



18
19
20
# File 'lib/rbfam/modules/utils.rb', line 18

def aa_sequence_from_entrez(id, position, window)
  Bio::Sequence::AA.new(sequence_from_entrez(id, position, window).seq)
end

.na_sequence_from_entrez(id, position, window, buffer_size = 0) ⇒ Object



14
15
16
# File 'lib/rbfam/modules/utils.rb', line 14

def na_sequence_from_entrez(id, position, window, buffer_size = 0)
  Bio::Sequence::NA.new(sequence_from_entrez(id, position, Range.new(window.min - buffer_size, window.max + buffer_size)).seq)
end

.rna_sequence_from_entrez(id, position, window, buffer_size = 0) ⇒ Object



10
11
12
# File 'lib/rbfam/modules/utils.rb', line 10

def rna_sequence_from_entrez(id, position, window, buffer_size = 0)
  na_sequence_from_entrez(id, position, window, buffer_size).rna
end

.sequence_from_entrez(id, position, window) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rbfam/modules/utils.rb', line 22

def sequence_from_entrez(id, position, window)
  puts "Retrieving sequence from Entrez: using nuccore DB (id: #{id}, seq_start: #{position + window.min}, seq_stop: #{position + window.max})"
  puts "> True starting position: #{position} with window #{window.min} to #{window.max}"

  fasta = Entrez.EFetch("nuccore", {
    id:        id, 
    seq_start: position + window.min, 
    seq_stop:  position + window.max, 
    retmode:   :fasta, 
    rettype:   :text
  }).response.body

  Bio::FastaFormat.new(fasta)
end

.simple_rna_sequence(id, from, to) ⇒ Object



4
5
6
7
8
# File 'lib/rbfam/modules/utils.rb', line 4

def simple_rna_sequence(id, from, to)
  sequence = rna_sequence_from_entrez(id, [from, to].min, 0..((to - from).abs))
    
  to < from ? sequence.complement : sequence
end