Class: Ensembl::Core::Gene
- Inherits:
-
DBConnection
- Object
- ActiveRecord::Base
- DBConnection
- Ensembl::Core::Gene
- Includes:
- Sliceable
- Defined in:
- lib/ensembl/core/activerecord.rb
Overview
DESCRIPTION
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.
USAGE
puts Gene.find_by_biotype('protein_coding').length
Class Method Summary collapse
-
.find_all_by_name(name) ⇒ Object
DESCRIPTION The Gene#find_all_by_name class method searches the Xrefs for that name and returns an array of the corresponding Gene objects.
-
.find_by_name(name) ⇒ Object
DESCRIPTION The Gene#find_by_name class method searches the Xrefs for that name and returns one Gene objects (even if there should be more).
-
.find_by_stable_id(stable_id) ⇒ Object
DESCRIPTION The Gene#find_by_stable_id class method fetches a Gene object based on its stable ID (i.e. the “ENSG” accession number).
Instance Method Summary collapse
-
#all_xrefs ⇒ Object
DESCRIPTION The Gene#all_xrefs method is a convenience method in that it combines three methods into one.
-
#display_label ⇒ Object
(also: #display_name, #label, #name)
DESCRIPTION The Gene#display_label method returns the default name of the gene.
-
#go_terms ⇒ Object
DESCRIPTION The Gene#go_terms method returns all GO terms associated with a gene.
-
#hgnc ⇒ Object
DESCRIPTION The Gene#hgnc returns the HGNC symbol for the gene.
-
#stable_id ⇒ Object
DESCRIPTION The Gene#stable_id method returns the stable_id of the gene (i.e. the ENSG id).
Methods included from Sliceable
#length, #project, #seq, #slice, #start, #stop, #strand, #transform
Methods inherited from DBConnection
Class Method Details
.find_all_by_name(name) ⇒ Object
DESCRIPTION
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.
1074 1075 1076 1077 1078 1079 1080 1081 1082 |
# File 'lib/ensembl/core/activerecord.rb', line 1074 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 return answer end |
.find_by_name(name) ⇒ Object
DESCRIPTION
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.
1088 1089 1090 1091 1092 1093 1094 1095 |
# File 'lib/ensembl/core/activerecord.rb', line 1088 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) ⇒ Object
DESCRIPTION
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.
1101 1102 1103 1104 1105 1106 1107 1108 |
# File 'lib/ensembl/core/activerecord.rb', line 1101 def self.find_by_stable_id(stable_id) gene_stable_id = GeneStableId.find_by_stable_id(stable_id) if gene_stable_id.nil? return nil else return gene_stable_id.gene end end |
Instance Method Details
#all_xrefs ⇒ Object
DESCRIPTION
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.
1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 |
# File 'lib/ensembl/core/activerecord.rb', line 1115 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 ⇒ Object Also known as: display_name, label, name
DESCRIPTION
The Gene#display_label method returns the default name of the gene.
1063 1064 1065 |
# File 'lib/ensembl/core/activerecord.rb', line 1063 def display_label return Xref.find(self.display_xref_id).display_label end |
#go_terms ⇒ Object
DESCRIPTION
The Gene#go_terms method returns all GO terms associated with a gene.
1130 1131 1132 1133 |
# File 'lib/ensembl/core/activerecord.rb', line 1130 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 ⇒ Object
DESCRIPTION
The Gene#hgnc returns the HGNC symbol for the gene.
1137 1138 1139 1140 1141 1142 |
# File 'lib/ensembl/core/activerecord.rb', line 1137 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 |
#stable_id ⇒ Object
DESCRIPTION
The Gene#stable_id method returns the stable_id of the gene (i.e. the ENSG id).
1056 1057 1058 1059 |
# File 'lib/ensembl/core/activerecord.rb', line 1056 def stable_id return self.gene_stable_id.stable_id end |