Class: BioPlates
- Inherits:
-
Object
- Object
- BioPlates
- Defined in:
- lib/bio-plates/plates.rb
Defined Under Namespace
Classes: Plate
Class Method Summary collapse
-
.quadrants(plates, newname = "QuadrantPlate") ⇒ Object
form quadrants from four plate Objects.
- .read(file) ⇒ Object
Class Method Details
.quadrants(plates, newname = "QuadrantPlate") ⇒ Object
form quadrants from four plate Objects
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# 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) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# 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 |