Class: Map

Inherits:
ApplicationRecord show all
Defined in:
app/models/map.rb

Overview

Map identifies a wells position on a Plate. It is not related to the ruby #map method.

Defined Under Namespace

Modules: Coordinate, Sequential

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

convert_labware_to_receptacle_for, find_by_id_or_name, find_by_id_or_name!

Methods included from Warren::BroadcastMessages

#broadcast, included, #queue_associated_for_broadcast, #queue_for_broadcast, #warren

Class Method Details

.horizontal_to_vertical(well_position, plate_size, _plate_shape = nil) ⇒ Object


221
222
223
# File 'app/models/map.rb', line 221

def self.horizontal_to_vertical(well_position, plate_size, _plate_shape = nil)
  Map::Coordinate.horizontal_to_vertical(well_position, plate_size)
end

.location_from_row_and_column(row, column) ⇒ Object


217
218
219
# File 'app/models/map.rb', line 217

def self.location_from_row_and_column(row, column)
  "#{('A'.getbyte(0) + row).chr}#{column}"
end

.map_384wellsObject


233
234
235
# File 'app/models/map.rb', line 233

def self.map_384wells
  Map.where(asset_size: 384)
end

.map_96wellsObject


229
230
231
# File 'app/models/map.rb', line 229

def self.map_96wells
  Map.where(asset_size: 96)
end

.pad_description(map) ⇒ Object


247
248
249
250
251
252
# File 'app/models/map.rb', line 247

def self.pad_description(map)
  split_description = split_well_description(map.description)
  return "#{map.description[0].chr}0#{split_description[:col]}" if split_description[:col] < 10

  map.description
end

.split_well_description(well_description) ⇒ Object


237
238
239
# File 'app/models/map.rb', line 237

def self.split_well_description(well_description)
  { row: well_description.getbyte(0) - 65, col: well_description[1, well_description.size].to_i }
end

.strip_description(description) ⇒ Object

Stip any leading zeros from the well name eg. A01 => A1


243
244
245
# File 'app/models/map.rb', line 243

def self.strip_description(description)
  description.sub(/0(\d)$/, '\1')
end

.valid_plate_position_and_plate_size?(well_position, plate_size) ⇒ Boolean

Returns:

  • (Boolean)

164
165
166
167
168
169
170
# File 'app/models/map.rb', line 164

def self.valid_plate_position_and_plate_size?(well_position, plate_size)
  return false unless valid_well_position?(well_position)
  return false unless valid_plate_size?(plate_size)
  return false if well_position > plate_size

  true
end

.valid_plate_size?(plate_size) ⇒ Boolean

Returns:

  • (Boolean)

160
161
162
# File 'app/models/map.rb', line 160

def self.valid_plate_size?(plate_size)
  plate_size.is_a?(Integer) && plate_size > 0
end

.valid_well_description_and_plate_size?(well_description, plate_size) ⇒ Boolean

Returns:

  • (Boolean)

172
173
174
175
176
177
# File 'app/models/map.rb', line 172

def self.valid_well_description_and_plate_size?(well_description, plate_size)
  return false if well_description.blank?
  return false unless valid_plate_size?(plate_size)

  true
end

.valid_well_position?(well_position) ⇒ Boolean

Returns:

  • (Boolean)

179
180
181
# File 'app/models/map.rb', line 179

def self.valid_well_position?(well_position)
  well_position.is_a?(Integer) && well_position > 0
end

.vertical_to_horizontal(well_position, plate_size, _plate_shape = nil) ⇒ Object


225
226
227
# File 'app/models/map.rb', line 225

def self.vertical_to_horizontal(well_position, plate_size, _plate_shape = nil)
  Map::Coordinate.vertical_to_horizontal(well_position, plate_size)
end

.walk_plate_in_column_major_order(size, asset_shape = nil) ⇒ Object Also known as: walk_plate_vertically

Walking in column major order goes by the columns: A1, B1, C1, … A2, B2, …


261
262
263
264
265
266
# File 'app/models/map.rb', line 261

def walk_plate_in_column_major_order(size, asset_shape = nil)
  asset_shape ||= AssetShape.default_id
  where(asset_size: size, asset_shape_id: asset_shape).order(:column_order).each do |position|
    yield(position, position.column_order)
  end
end

.walk_plate_in_row_major_order(size, asset_shape = nil) ⇒ Object

Walking in row major order goes by the rows: A1, A2, A3, … B1, B2, B3 .…


270
271
272
273
274
275
# File 'app/models/map.rb', line 270

def walk_plate_in_row_major_order(size, asset_shape = nil)
  asset_shape ||= AssetShape.default_id
  where(asset_size: size, asset_shape_id: asset_shape).order(:row_order).each do |position|
    yield(position, position.row_order)
  end
end

Instance Method Details

#columnObject

Column of particular map location. Zero indexed integer


197
198
199
# File 'app/models/map.rb', line 197

def column
  row_order % width
end

#heightObject


187
188
189
# File 'app/models/map.rb', line 187

def height
  asset_shape.plate_height(asset_size)
end

#horizontal_plate_positionObject


207
208
209
# File 'app/models/map.rb', line 207

def horizontal_plate_position
  row_order + 1
end

#rowObject

Row of particular map location. Zero indexed integer


203
204
205
# File 'app/models/map.rb', line 203

def row
  column_order % height
end

#snp_idObject

Raises:

  • (StandardError)

211
212
213
214
215
# File 'app/models/map.rb', line 211

def snp_id
  raise StandardError, 'Only standard maps can be converted to SNP' unless map.standard?

  horizontal_plate_position
end

#vertical_plate_positionObject


183
184
185
# File 'app/models/map.rb', line 183

def vertical_plate_position
  column_order + 1
end

#widthObject


191
192
193
# File 'app/models/map.rb', line 191

def width
  asset_shape.plate_width(asset_size)
end