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.



17
18
19
20
21
22
23
# File 'lib/chem/db/kegg.rb', line 17

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.



16
17
18
# File 'lib/chem/db/kegg.rb', line 16

def dir
  @dir
end

Instance Method Details

#[](key) ⇒ Object



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

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



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/chem/db/kegg.rb', line 29

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



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/chem/db/kegg.rb', line 43

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



25
26
27
# File 'lib/chem/db/kegg.rb', line 25

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

#map_formulaObject



77
78
79
80
# File 'lib/chem/db/kegg.rb', line 77

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

#parse_reaction_map_formulaObject



82
83
84
85
86
87
88
89
# File 'lib/chem/db/kegg.rb', line 82

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