Class: GFFDB

Inherits:
Object
  • Object
show all
Defined in:
lib/protk/gffdb.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(gff_file_path) ⇒ GFFDB

Returns a new instance of GFFDB.



9
10
11
12
13
# File 'lib/protk/gffdb.rb', line 9

def initialize(gff_file_path)
  @database = gff_file_path
  @id_to_records_map={}
  @id_to_cds_map={}
end

Instance Attribute Details

#id_to_records_mapObject

Returns the value of attribute id_to_records_map.



7
8
9
# File 'lib/protk/gffdb.rb', line 7

def id_to_records_map
  @id_to_records_map
end

Class Method Details

.create(gff_file_path) ⇒ Object



15
16
17
18
19
# File 'lib/protk/gffdb.rb', line 15

def self.create(gff_file_path)
  db = GFFDB.new(gff_file_path)
  db.make_index(gff_file_path)
  db
end

Instance Method Details

#get_by_id(entry_id) ⇒ Object



21
22
23
# File 'lib/protk/gffdb.rb', line 21

def get_by_id(entry_id)
  @id_to_records_map[entry_id]
end

#get_cds_by_parent_id(entry_id) ⇒ Object



25
26
27
# File 'lib/protk/gffdb.rb', line 25

def get_cds_by_parent_id(entry_id)
  @id_to_cds_map[entry_id]
end

#make_index(input_gff) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/protk/gffdb.rb', line 30

def make_index(input_gff)
  env=Constants.instance

  io = File.open(input_gff, "r")
  env.log "Parsing Input GFF",:info
  gffdb = Bio::GFF::GFF3.new(io)  #parses the entire db

  num_records = gffdb.records.length
  env.log "Indexing #{num_records}", :info

  # Now create the mapping from ids to records
  gffdb.records.each do |record| 

    @id_to_records_map[record.id] = [] if @id_to_records_map[record.id].nil?
    @id_to_records_map[record.id] << record

    begin
      # puts record.feature_type.match(/CDS/)
      if record.feature_type.to_s =~ /CDS/i
        # puts record.feature_type
        parent_id=record.attributes_to_hash['Parent']
        # puts parent_id
        if parent_id
          @id_to_cds_map[parent_id] = [] if @id_to_cds_map[parent_id].nil?
          @id_to_cds_map[parent_id] << record
        end
      end

    rescue
      puts "Problem initializing cds map for #{record}"
    end
  end

end