Class: BioPlates::Plate::Well

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

Constant Summary collapse

@@regexp =
/(?<row>[A-Za-z]+)(?<column>\d+)/
@@nrow =

Better not to hard code theseā€¦

8
@@ncol =
12

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Well

Returns a new instance of Well.



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/bio-plates/plates.rb', line 123

def initialize(hash)

  if hash[:row] && hash[:column]
    @row = hash[:row]
    @column = hash[:column].to_s
  else
    # Split the well annotation if row & col not given separately
    m = hash[:well].match(@@regexp)
    @well = hash[:well]
    @row = m[:row]
    @column = m[:column]
  end
  # NB annotation includes the original well annotation
  @annotation = hash.delete_if{|k,f| [:row, :column, :well].include? k}.to_h
end

Instance Attribute Details

#annotationObject

Returns the value of attribute annotation.



118
119
120
# File 'lib/bio-plates/plates.rb', line 118

def annotation
  @annotation
end

#columnObject

Returns the value of attribute column.



118
119
120
# File 'lib/bio-plates/plates.rb', line 118

def column
  @column
end

#rowObject

Returns the value of attribute row.



118
119
120
# File 'lib/bio-plates/plates.rb', line 118

def row
  @row
end

#wellObject

Returns the value of attribute well.



118
119
120
# File 'lib/bio-plates/plates.rb', line 118

def well
  @well
end

Instance Method Details

#index!Object



139
140
141
# File 'lib/bio-plates/plates.rb', line 139

def index!
  @well = @row.upcase.to_s + @column
end

#quadrantize(plate) ⇒ Object



155
156
157
158
# File 'lib/bio-plates/plates.rb', line 155

def quadrantize(plate)
  dup = self.dup
  dup.quadrantize!(plate)
end

#quadrantize!(plate) ⇒ Object



143
144
145
146
147
148
149
150
151
152
153
# File 'lib/bio-plates/plates.rb', line 143

def quadrantize!(plate)
  self.index! unless @well
  @annotation[:original_well] = @well
  @annotation[:original_plate] = @annotation[:plate]
  @annotation.delete(:plate) # Remove so no conflict with new plate
  (plate == 2 || plate == 4) ? inc = 1 : inc = 0
  (plate == 3 || plate == 4) ? rowinc = 1 : rowinc = 0
  @column = (@column.to_i + [*0..@@ncol][@column.to_i-1]+inc).to_s
  @row = (@row.ord + [*0..@@nrow][@row.upcase.ord-65]+rowinc).chr # 65 = ASCII "A"
  self
end