class Ensembl::Core::Gene

The Gene class provides an interface to the gene table. This table contains mappings of genes to a SeqRegion.

This class uses ActiveRecord to access data in the Ensembl database. See the general documentation of the Ensembl module for more information on what this means and what methods are available.

This class includes the mixin Sliceable, which means that it is mapped to a SeqRegion object and a Slice can be created for objects of this class. See Sliceable and Slice for more information.

@example

puts Gene.find_by_biotype('protein_coding').length

Public Class Methods

find_all_by_name(name) click to toggle source

The Gene#find_all_by_name class method searches the Xrefs for that name and returns an array of the corresponding Gene objects. If the name is not found, it returns an empty array.

# File lib/bio-ensembl/core/activerecord.rb, line 1067
def self.find_all_by_name(name)
  answer = Array.new
  xrefs = Ensembl::Core::Xref.find_all_by_display_label(name)
  xrefs.each do |xref|
    answer.push(Ensembl::Core::Gene.find_by_display_xref_id(xref.xref_id))
  end
  
  answer.reject!{|a| a.nil?}
  return answer
end
find_by_name(name) click to toggle source

The Gene#find_by_name class method searches the Xrefs for that name and returns one Gene objects (even if there should be more). If the name is not found, it returns nil.

# File lib/bio-ensembl/core/activerecord.rb, line 1081
def self.find_by_name(name)
  all_names = self.find_all_by_name(name)
  if all_names.length == 0
    return nil
  else
    return all_names[0]
  end
end
find_by_stable_id(stable_id) click to toggle source

The Gene#find_by_stable_id class method fetches a Gene object based on its stable ID (i.e. the “ENSG” accession number). If the name is not found, it returns nil.

# File lib/bio-ensembl/core/activerecord.rb, line 1093
def self.find_by_stable_id(stable_id)
  result = nil
  if stable_id.kind_of? Array
    gene_stable_ids = GeneStableId.where({:stable_id => stable_id})
    result = (gene_stable_ids.size == 0) ? nil : gene_stable_ids.map {|id| id.gene}
  else
    gene_stable_id = GeneStableId.find_by_stable_id(stable_id)
    result = (gene_stable_id.nil?) ? nil : gene_stable_id.gene
  end
  return result
end

Public Instance Methods

all_xrefs() click to toggle source

The Gene#all_xrefs method is a convenience method in that it combines three methods into one. It collects all xrefs for the gene itself, plus all xrefs for all transcripts for the gene, and all xrefs for all translations for those transcripts.

# File lib/bio-ensembl/core/activerecord.rb, line 1109
def all_xrefs
  answer = Array.new
  answer.push(self.xrefs)
  self.transcripts.each do |transcript|
    answer.push(transcript.xrefs)
    if ! transcript.translation.nil?
      answer.push(transcript.translation.xrefs)
    end
  end
  answer.flatten!
  return answer
end
display_label() click to toggle source

The Gene#display_label method returns the default name of the gene.

# File lib/bio-ensembl/core/activerecord.rb, line 1057
def display_label
  return Xref.find(self.display_xref_id).display_label
end
Also aliased as: display_name, label, name
display_name()
Alias for: display_label
go_terms() click to toggle source

The Gene#go_terms method returns all GO terms associated with a gene.

# File lib/bio-ensembl/core/activerecord.rb, line 1123
def go_terms
  go_db_id = ExternalDb.find_by_db_name('GO').id
  return self.all_xrefs.select{|x| x.external_db_id == go_db_id}.collect{|x| x.dbprimary_acc}.uniq
end
hgnc() click to toggle source

The Gene#hgnc returns the HGNC symbol for the gene.

# File lib/bio-ensembl/core/activerecord.rb, line 1129
def hgnc
  hgnc_db_id = ExternalDb.find_by_db_name('HGNC_curated_gene').id
  xref = self.all_xrefs.select{|x| x.external_db_id == hgnc_db_id}[0]
  return nil if xref.nil?
  return xref.display_label
end
label()
Alias for: display_label
name()
Alias for: display_label
stable_id() click to toggle source

The Gene#stable_id method returns the stable_id of the gene (i.e. the ENSG id).

# File lib/bio-ensembl/core/activerecord.rb, line 1051
def stable_id
  return self.gene_stable_id.stable_id
  
end