Module: Entrez
- Defined in:
- lib/rbbt/sources/entrez.rb
Defined Under Namespace
Classes: Gene
Class Method Summary collapse
- .entrez2name(taxs, options = {}) ⇒ Object
- .entrez2native(taxs, options = {}) ⇒ Object
- .entrez2pubmed(taxs) ⇒ Object
- .gene_filename(id) ⇒ Object
-
.gene_text_similarity(gene, text) ⇒ Object
Counts the words in common between a chunk of text and the text found in Entrez Gene for that particular gene.
- .get_gene(geneid) ⇒ Object
Class Method Details
.entrez2name(taxs, options = {}) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rbbt/sources/entrez.rb', line 24 def self.entrez2name(taxs, = {}) = Misc.add_defaults , :key_field => 1, :fields => [2], :persist => true, :merge => true taxs = [taxs] unless Array === taxs .merge! :grep => taxs.collect{|t| "^" + t.to_s} tsv = Rbbt.share.databases.entrez.gene_info.tsv :flat, tsv.key_field = "Entrez Gene ID" tsv.fields = ["Associated Gene Name"] tsv end |
.entrez2native(taxs, options = {}) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/rbbt/sources/entrez.rb', line 12 def self.entrez2native(taxs, = {}) = Misc.add_defaults , :key_field => 1, :fields => [5], :persist => true, :merge => true taxs = [taxs] unless Array === taxs .merge! :grep => taxs.collect{|t| "^" + t.to_s} tsv = Rbbt.share.databases.entrez.gene_info.tsv :flat, tsv.key_field = "Entrez Gene ID" tsv.fields = ["Native ID"] tsv end |
.entrez2pubmed(taxs) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/rbbt/sources/entrez.rb', line 37 def self.entrez2pubmed(taxs) = {:key_field => 1, :fields => [2], :persist => true, :merge => true} taxs = [taxs] unless taxs.is_a?(Array) .merge! :grep => taxs.collect{|t| "^" + t.to_s} Rbbt.share.databases.entrez.gene2pubmed.tsv :flat, end |
.gene_filename(id) ⇒ Object
108 109 110 |
# File 'lib/rbbt/sources/entrez.rb', line 108 def self.gene_filename(id) 'gene-' + id.to_s + '.xml' end |
.gene_text_similarity(gene, text) ⇒ Object
Counts the words in common between a chunk of text and the text found in Entrez Gene for that particular gene. The gene
may be a gene identifier or a Gene class instance.
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/rbbt/sources/entrez.rb', line 158 def self.gene_text_similarity(gene, text) case when Entrez::Gene === gene gene_text = gene.text when String === gene || Fixnum === gene begin gene_text = get_gene(gene).text rescue CMD::CMDError return 0 end else return 0 end gene_words = gene_text.words.to_set text_words = text.words.to_set return 0 if gene_words.empty? || text_words.empty? common = gene_words.intersection(text_words) common.length / (gene_words.length + text_words.length).to_f end |
.get_gene(geneid) ⇒ Object
112 113 114 115 116 117 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 146 147 148 149 150 151 152 153 |
# File 'lib/rbbt/sources/entrez.rb', line 112 def self.get_gene(geneid) return nil if geneid.nil? if Array === geneid missing = [] list = {} geneid.each{|p| next if p.nil? if FileCache.found(gene_filename p) list[p] = Gene.new(Open.read(FileCache.path(gene_filename p))) else missing << p end } return list unless missing.any? genes = get_online(missing) genes.each{|p, xml| filename = gene_filename p FileCache.add(filename,xml) unless FileCache.found(filename) list[p] = Gene.new(xml) } return list else filename = gene_filename geneid if FileCache.found(filename) return Gene.new(Open.read(FileCache.path(filename))) else xml = get_online(geneid) FileCache.add(filename, xml) unless FileCache.found(filename) return Gene.new(xml) end end end |