Class: Chem::KEGG::KeggDirectory

Inherits:
Object
  • Object
show all
Defined in:
lib/chem/db/kegg.rb

Defined Under Namespace

Classes: KeggGene, KeggOrganism, KeggPfam

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir) ⇒ KeggDirectory

Returns a new instance of KeggDirectory.



51
52
53
54
55
56
57
# File 'lib/chem/db/kegg.rb', line 51

def initialize dir
  @dir = dir
  @compounds = {}
  @ligand_dir = File.join(@dir, "ligand")
  @mol_dir = File.join(@ligand_dir, "mol")
  @parsed_file = []
end

Instance Attribute Details

#dirObject (readonly)

Returns the value of attribute dir.



50
51
52
# File 'lib/chem/db/kegg.rb', line 50

def dir
  @dir
end

Instance Method Details

#[](key) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/chem/db/kegg.rb', line 92

def [](key)
  case key
  when /(R\d+)/
    get_reaction $1
  when /(C\d+)/
    get_compound $1
  when /pf:(.+)/
    KeggPfam.new($1, self)
  when /^([^:]{3,4}):(\d+)/
    # gene
    raise "Parser for Organism not implemented!"
  when /^([^:]{3,4})/
    # organism
    KeggOrganism.new($1, self)
  else
    raise "unknown KEGG key type : #{key}"
  end
end

#gene_to_pfam(organism) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/chem/db/kegg.rb', line 63

def gene_to_pfam organism
  filename = File.join(@dir, "genomes", organism, organism + "_pfam.list")
  return @pfam2gene if @parsed_file.include?(filename)
  @parsed_file.push filename
  @gene2pfam ||= {}
  @pfam2gene ||= {}
  open(filename).each do |line|
    gene, pfam = line.split("\t")
    @gene2pfam[gene] = pfam.chop
    (@pfam2gene[pfam.chop] ||= []).push(KeggGene.new(gene, organism, self))
  end
  @pfam2gene
end

#get_ec_number(gene) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/chem/db/kegg.rb', line 77

def get_ec_number gene
  @gene2enzyme ||= {}
  @enzyme2gene ||= {}
  filename = File.join(@dir, "genomes", gene.organism, gene.organism + "_enzyme.list")
  return @gene2enzyme[gene.gene] if @parsed_file.include?(filename)
  @parsed_file.push filename

  open(filename).each do |line|
    gn, ec = line.chop.split("\t")
    @gene2enzyme[gn] = ec
    @enzyme2gene[ec] = gn
  end
  @gene2enzyme[gene.gene]
end

#get_organism(organism, file) ⇒ Object



59
60
61
# File 'lib/chem/db/kegg.rb', line 59

def get_organism organism, file
  File.join(@dir, "genomes", organism, file)
end

#map_formulaObject



111
112
113
114
# File 'lib/chem/db/kegg.rb', line 111

def map_formula
  @reaction_map_formula = parse_reaction_map_formula unless @reaction_map_formula
  @reaction_map_formula
end

#parse_reaction_map_formulaObject



116
117
118
119
120
121
122
123
# File 'lib/chem/db/kegg.rb', line 116

def parse_reaction_map_formula
  rxns = {}
  parser = Chem.parse_file(File.join(@dir, "ligand", "reaction_mapformula.lst"))
  parser.each do |rxn|
    rxns[rxn.entry] = rxn
  end
  rxns
end