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 Squishify

extended

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


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

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


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

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

.map_384wellsObject


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

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

.map_96wellsObject


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

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

.pad_description(map) ⇒ Object


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

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


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

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


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

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

.valid_plate_position_and_plate_size?(well_position, plate_size) ⇒ Boolean

Returns:

  • (Boolean)

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

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)

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

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)

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

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)

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

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


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

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, …


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

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 .…


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

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


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

def column
  row_order % width
end

#heightObject


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

def height
  asset_shape.plate_height(asset_size)
end

#horizontal_plate_positionObject


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

def horizontal_plate_position
  row_order + 1
end

#rowObject

Row of particular map location. Zero indexed integer


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

def row
  column_order % height
end

#snp_idObject

Raises:

  • (StandardError)

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

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

  horizontal_plate_position
end

#vertical_plate_positionObject


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

def vertical_plate_position
  column_order + 1
end

#widthObject


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

def width
  asset_shape.plate_width(asset_size)
end