Class: Ensembl::Core::Gene
- Inherits:
-
DBConnection
- Object
- ActiveRecord::Base
- DBRegistry::Base
- DBConnection
- Ensembl::Core::Gene
- Includes:
- Sliceable
- Defined in:
- lib/bio-ensembl/core/activerecord.rb
Overview
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.
Class Method Summary collapse
-
.find_all_by_name(name) ⇒ Object
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
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
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
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)
The Gene#display_label method returns the default name of the gene.
-
#go_terms ⇒ Object
The Gene#go_terms method returns all GO terms associated with a gene.
-
#hgnc ⇒ Object
The Gene#hgnc returns the HGNC symbol for the gene.
-
#stable_id ⇒ Object
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
connect, ensemblgenomes_connect
Methods inherited from DBRegistry::Base
generic_connect, get_info, get_name_from_db
Class Method Details
.find_all_by_name(name) ⇒ Object
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.
1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 |
# 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) ⇒ Object
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.
1081 1082 1083 1084 1085 1086 1087 1088 |
# 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) ⇒ Object
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.
1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 |
# 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 |
Instance Method Details
#all_xrefs ⇒ Object
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.
1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 |
# 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 ⇒ Object Also known as: display_name, label, name
The Gene#display_label method returns the default name of the gene.
1057 1058 1059 |
# File 'lib/bio-ensembl/core/activerecord.rb', line 1057 def display_label return Xref.find(self.display_xref_id).display_label end |
#go_terms ⇒ Object
The Gene#go_terms method returns all GO terms associated with a gene.
1123 1124 1125 1126 |
# 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 ⇒ Object
The Gene#hgnc returns the HGNC symbol for the gene.
1129 1130 1131 1132 1133 1134 |
# 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 |
#stable_id ⇒ Object
The Gene#stable_id method returns the stable_id of the gene (i.e. the ENSG id).
1051 1052 1053 1054 |
# File 'lib/bio-ensembl/core/activerecord.rb', line 1051 def stable_id return self.gene_stable_id.stable_id end |