Class: BioPlates::Plate

Inherits:
Object
  • Object
show all
Defined in:
lib/bio-plates/plates.rb

Defined Under Namespace

Classes: Well

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = "") ⇒ Plate

Returns a new instance of Plate.



59
60
61
62
# File 'lib/bio-plates/plates.rb', line 59

def initialize(name="")
  @name = name
  @wells = []
end

Instance Attribute Details

#columnsObject

Returns the value of attribute columns.



57
58
59
# File 'lib/bio-plates/plates.rb', line 57

def columns
  @columns
end

#nameObject

Returns the value of attribute name.



57
58
59
# File 'lib/bio-plates/plates.rb', line 57

def name
  @name
end

#rowsObject

Returns the value of attribute rows.



57
58
59
# File 'lib/bio-plates/plates.rb', line 57

def rows
  @rows
end

#wellsObject

Returns the value of attribute wells.



57
58
59
# File 'lib/bio-plates/plates.rb', line 57

def wells
  @wells
end

Instance Method Details

#add_leading_zeroes!Object

Add leading zeroes to column strings



81
82
83
84
85
# File 'lib/bio-plates/plates.rb', line 81

def add_leading_zeroes!
  max = self.wells.dup.sort_by!{|x| x.column.to_s.length}.pop.column.to_s.length
  self.wells.map!{|x| y = ""; (max - x.column.to_s.length).times{y << "0"} ; x.column = y + x.column.to_s; x }
  self
end

#dump(file = "output.csv", head = true, format = "csv") ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/bio-plates/plates.rb', line 87

def dump(file="output.csv",head=true,format="csv")
  #Column titles required:
  columns = Hash.new{|h,k| h[k] = 1}
  self.wells.each do |well|
    well.annotation.each{|k,v| columns[k] += 1}
  end
  columns.delete(:plate) # Remove original plate annotation
  CSV.open(file,"wb") do |csv|
    if head
      csv << ["Plate","Row","Column"] + columns.keys
      head = false
    end
    self.wells.each do |well|
      line = [self.name,well.row,well.column]
      columns.keys.each do |col_title|
        if well.annotation.keys.include?(col_title)
          line << well.annotation[col_title]
        else
   # Any wells without value for an annotation get a zero
          line << 0
        end
      end
    csv << line
    end
  end

end

#eachObject



64
65
66
# File 'lib/bio-plates/plates.rb', line 64

def each
  @wells.each
end