class BioPlates::Plate
Attributes
columns[RW]
name[RW]
rows[RW]
wells[RW]
Public Class Methods
new(name="")
click to toggle source
# File lib/bio-plates/plates.rb, line 59 def initialize(name="") @name = name @wells = [] end
Public Instance Methods
add_leading_zeroes!()
click to toggle source
Add leading zeroes to column strings
# 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")
click to toggle source
# 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
each()
click to toggle source
# File lib/bio-plates/plates.rb, line 64 def each @wells.each end