class BioPlates
Public Class Methods
quadrants(plates,newname="QuadrantPlate")
click to toggle source
form quadrants from four plate Objects
# File lib/bio-plates/plates.rb, line 19 def self.quadrants(plates,newname="QuadrantPlate") if plates.is_a? Hash plates = plates.sort.to_h.values end unless plates.length == 4 warn "Number of plates supplied should be four; truncating/reusing" if plates.length > 4 plates = plates[0..3] elsif plates.length < 4 i = 0 until plates.length == 4 do duplicate = plates[i].dup duplicate.wells = duplicate.wells.map(&:dup) plates << duplicate # Keep incrementing as long as there are still supplied plates, else reset i < plates.length ? i += 1 : i = 0 end end end newplate = BioPlates::Plate.new(newname) plates.each.with_index do |plateobj, plateno| plateno = plateno + 1 modplate = plateobj.dup modplate.wells.map!{|x| x.quadrantize!(plateno)} modplate.add_leading_zeroes! modplate.wells.map(&:index!) newplate.wells = newplate.wells + modplate.wells end newplate.wells = newplate.wells.sort_by{|w| w.well} newplate end
read(file)
click to toggle source
# File lib/bio-plates/plates.rb, line 3 def self.read(file) plates = Hash.new{|h,k| h[k] = BioPlates::Plate.new(k)} csv = CSV.read(File.open(file), headers: true, header_converters: :symbol) unless csv.headers.include? :well || ((csv.headers.include? :row) && (csv.headers.include? :column)) raise "Column headers must include either Well, or Row and Column" end csv.each do |row| plates[row[:plate]].wells << BioPlates::Plate::Well.new(row) end plates.map{|k,v| v.add_leading_zeroes!} # Return a hash of Plate Objects for all the plates in the CSV #plates.each.map!{|k,v| v.name = k} plates end