Module: EnsemblRest::ComparativeGenomics

Defined in:
lib/bio-ensembl-rest/comparative-genomics.rb

Class Method Summary collapse

Class Method Details

._genetree_generic(id, type, opts = {}) ⇒ Object

generic method used by genetree_id and genetree_member_id



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/bio-ensembl-rest/comparative-genomics.rb', line 49

def self._genetree_generic(id, type, opts = {}) # :nodoc:
  opts = EnsemblRest.parse_options opts
  url = type == 'id' ? "/genetree/id/#{id}" : "/genetree/member/id/#{id}"
  path = EnsemblRest.build_path url, opts

  if opts['content-type'] == 'ruby'
    plain_opts = opts.clone
    plain_opts['content-type'] = 'text/x-phyloxml+xml'
    return Bio::PhyloXML::Parser.new _genetree_generic id, type, plain_opts
  end

  return EnsemblRest.fetch_data path, opts, 'compara'
end

.alignment_block(species, region, opts = {}) ⇒ Object

Retrieves genomic alignments as separate blocks based on its location



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/bio-ensembl-rest/comparative-genomics.rb', line 6

def self.alignment_block(species, region, opts = {})
  opts = EnsemblRest.parse_options opts
  path = EnsemblRest.build_path "/alignment/block/region/#{species}/#{region}", opts

  if opts['content-type'] == 'ruby'
    plain_opts = opts.clone
    plain_opts['content-type'] = 'application/json'
    return JSON.parse ComparativeGenomics.alignment_block species, region, plain_opts
  end

  return EnsemblRest.fetch_data path, opts, 'compara'
end

.alignment_slice(species, region, opts = {}) ⇒ Object

Retrieves genomic alignments as a single slice based on its location



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/bio-ensembl-rest/comparative-genomics.rb', line 21

def self.alignment_slice(species, region, opts = {})
  opts = EnsemblRest.parse_options opts
  path = EnsemblRest.build_path "/alignment/slice/region/#{species}/#{region}", opts

  if opts['content-type'] == 'ruby'
    plain_opts = opts.clone
    plain_opts['content-type'] = 'application/json'
    return JSON.parse ComparativeGenomics.alignment_slice species, region, plain_opts
  end

  return EnsemblRest.fetch_data path, opts, 'compara'
end

.build_homology_class(json_data) ⇒ Object

:nodoc:



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/bio-ensembl-rest/comparative-genomics.rb', line 118

def self.build_homology_class(json_data) # :nodoc:
  # extract the homologies list (homology = ruby hash obj)
  homologies_data = json_data['data'][0]['homologies'] # this is a list of hashes

  # retrieve homology keys to make a list of methods
  homology_methods = []
  homologies_data.first.each { |k, _| homology_methods << k.to_sym }

  # we define an attr_accessor for each symbol in homology_methods
  # and a 'bio_methods' attribute with all the newly defined methods
  homology_methods.each { |k, _| Homology.class_eval "attr_accessor :#{k}" }
  Homology.class_eval "attr_accessor :bio_methods" 

  # we will return a list of homology objects
  homologies = []

  # let's build the list
  homologies_data.each do |hom| # cycle over the homologies we were given
    h = Homology.new            # we instantiate an Homology obj
    hom.each do |k, v|          # for each key,value in the homology hash
      h.send "#{k}=".to_sym, v  # we use the 'key=' method to set 'value'
    end
    h.send :bio_methods=, homology_methods  # set the bio_methods param
    homologies << h             # add the obj to the list to be returned             
  end

  return homologies
end

.genetree_id(id, opts = {}) ⇒ Object

Retrieves Gene Tree dumps for a given Gene Tree stable identifier



38
39
40
# File 'lib/bio-ensembl-rest/comparative-genomics.rb', line 38

def self.genetree_id(id, opts = {})
  return _genetree_generic id, 'id', opts
end

.genetree_member_id(id, opts = {}) ⇒ Object

Retrieves the Gene Tree that contains the given stable identifier



44
45
46
# File 'lib/bio-ensembl-rest/comparative-genomics.rb', line 44

def self.genetree_member_id(id, opts = {})
  return _genetree_generic id, 'member', opts
end

.genetree_member_symbol(species, symbol, opts = {}) ⇒ Object

Retrieves a Gene Tree containing the Gene identified by the given symbol



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/bio-ensembl-rest/comparative-genomics.rb', line 66

def self.genetree_member_symbol(species, symbol, opts = {})
  opts = EnsemblRest.parse_options opts
  path = EnsemblRest.build_path "/genetree/member/symbol/#{species}/#{symbol}", opts

  if opts['content-type'] == 'ruby'
    plain_opts = opts.clone
    plain_opts['content-type'] = 'text/x-phyloxml+xml'
    return Bio::PhyloXML::Parser.new genetree_member_symbol(species, symbol, plain_opts)
  end

  return EnsemblRest.fetch_data path, opts, 'compara'
end

.homology_id(id, opts = {}) ⇒ Object

Retrieves homology information by ensembl gene id



82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/bio-ensembl-rest/comparative-genomics.rb', line 82

def self.homology_id(id, opts = {})
  opts = EnsemblRest.parse_options opts
  path = EnsemblRest.build_path "/homology/id/#{id}", opts

  if opts['content-type'] == 'ruby'
    plain_opts = opts.clone
    plain_opts['content-type'] = 'application/json'
    data = JSON.parse ComparativeGenomics.homology_id id, plain_opts
    return build_homology_class data
  end

  return EnsemblRest.fetch_data path, opts, 'compara'
end

.homology_symbol(species, symbol, opts = {}) ⇒ Object

Retrieves homology information by symbol



99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/bio-ensembl-rest/comparative-genomics.rb', line 99

def self.homology_symbol(species, symbol, opts = {})
  opts = EnsemblRest.parse_options opts
  path = EnsemblRest.build_path "/homology/symbol/#{species}/#{symbol}", opts

  if opts['content-type'] == 'ruby'
    plain_opts = opts.clone
    plain_opts['content-type'] = 'application/json'
    data = JSON.parse ComparativeGenomics.homology_symbol species, symbol, plain_opts
    return build_homology_class data
  end

  return EnsemblRest.fetch_data path, opts, 'compara'      

end