Class: Bio::GFFbrowser::Helpers::LinkedRecs

Inherits:
Hash
  • Object
show all
Includes:
Logger
Defined in:
lib/bio/db/gff/gffvalidate.rb

Overview

Helper class for storing linked records based on a shared ID

Instance Method Summary collapse

Methods included from Logger

#debug, #error, #info, #log_sys_info, #warn

Instance Method Details

#add(id, rec) ⇒ Object



37
38
39
40
41
42
# File 'lib/bio/db/gff/gffvalidate.rb', line 37

def add id, rec
  info "Adding #{rec.feature_type} (validate)",id
  raise "ID should not be empty" if id == nil or id == ""
  self[id] = [] if self[id] == nil
  self[id] << rec
end

#validate_nonoverlappingObject

walk all (CDS) lists for every container/component and validate they do not overlap



77
78
79
80
81
82
83
84
85
86
87
# File 'lib/bio/db/gff/gffvalidate.rb', line 77

def validate_nonoverlapping
  each do | id, rec |
    sections = Sections::sort(rec)
    sections.each_with_index do | check, i |
      neighbour = sections[i+1]
      if neighbour and check.intersection(neighbour)
        warn "Overlapping sections for ",id
      end
    end
  end
end

#validate_seqnameObject

Validate all lists belong to the same container/component



45
46
47
48
49
50
51
52
# File 'lib/bio/db/gff/gffvalidate.rb', line 45

def validate_seqname
  each do | id, rec |
    seqname = rec.first.seqname
    rec.each do | section |
      raise "Non-matching seqname #{section.seqname} in #{seqname}" if section.seqname != seqname
    end
  end
end

#validate_shared_parentObject

Validate all lists share the same parent (if available). First checks for Parent attribute, next for mRNA attribute



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/bio/db/gff/gffvalidate.rb', line 56

def validate_shared_parent
  each do | id, rec |
    parent = rec.first.get_attribute('Parent')
    if parent
      rec.each do | section |
        _parent = section.get_attribute('Parent')
        raise "Non-matching parent #{_parent} and #{parent} in #{id}" if _parent != parent
      end
    end
    parent = rec.first.get_attribute('mRNA')
    if parent
      rec.each do | section |
        _parent = section.get_attribute('mRNA')
        raise "Non-matching parent #{_parent} and #{parent} in #{id}" if _parent != parent
      end
    end
  end
end