Class: AssetShape

Inherits:
ApplicationRecord show all
Includes:
SharedBehaviour::Named
Defined in:
app/models/asset_shape.rb

Overview

Describes the shape of the plate and its numbering system. The majority of our plates have a 3:2 width height ratio: eg. 128 or 2416 And wells are numbered by ‘coordinate’ eg. A1, H12 However FluidigmPlates have different dimensions: - 6 * 16 (96) - 12 * 16 (192) In addition, wells are labeled sequentially in column order, padded with zeros: eg. S01-S96 and S001-S192

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SharedBehaviour::Named

included

Methods inherited from ApplicationRecord

alias_association, convert_labware_to_receptacle_for, find_by_id_or_name, find_by_id_or_name!

Methods included from Squishify

extended

Class Method Details

.defaultObject



21
22
23
24
25
26
27
# File 'app/models/asset_shape.rb', line 21

def self.default
  AssetShape.create_with(
    horizontal_ratio: 3,
    vertical_ratio: 2,
    description_strategy: 'Map::Coordinate'
  ).find_or_create_by(name: 'Standard')
end

.default_idObject



17
18
19
# File 'app/models/asset_shape.rb', line 17

def self.default_id
  @default_id ||= default.id
end

Instance Method Details

#alternate_position(well_position, size, *dimensions) ⇒ Object



76
77
78
79
80
81
82
83
84
85
# File 'app/models/asset_shape.rb', line 76

def alternate_position(well_position, size, *dimensions)
  return nil unless Map.valid_well_position?(well_position)

  divisor, multiplier = dimensions.map { |n| send(:"plate_#{n}", size) }
  column, row = (well_position - 1).divmod(divisor)
  return nil unless (0...multiplier).cover?(column)
  return nil unless (0...divisor).cover?(row)

  alternate = (row * multiplier) + column + 1
end

#generate_map(size) ⇒ Object

Raises:

  • (StandardError)


57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'app/models/asset_shape.rb', line 57

def generate_map(size)
  raise StandardError, 'Map already exists' if Map.find_by(asset_size: size, asset_shape_id: id).present?

  ActiveRecord::Base.transaction do
    map_data =
      Array.new(size) do |i|
        {
          asset_size: size,
          asset_shape_id: id,
          location_id: i + 1,
          row_order: i,
          column_order: (horizontal_to_vertical(i + 1, size) || 1) - 1,
          description: location_from_index(i, size)
        }
      end
    Map.import(map_data)
  end
end

#horizontal_to_vertical(well_position, plate_size) ⇒ Object



41
42
43
# File 'app/models/asset_shape.rb', line 41

def horizontal_to_vertical(well_position, plate_size)
  alternate_position(well_position, plate_size, :width, :height)
end

#interlaced_vertical_to_horizontal(well_position, plate_size) ⇒ Object



49
50
51
# File 'app/models/asset_shape.rb', line 49

def interlaced_vertical_to_horizontal(well_position, plate_size)
  alternate_position(interlace(well_position, plate_size), plate_size, :height, :width)
end

#location_from_row_and_column(row, column, size = 96) ⇒ Object



87
88
89
# File 'app/models/asset_shape.rb', line 87

def location_from_row_and_column(row, column, size = 96)
  description_strategy.constantize.location_from_row_and_column(row, column, plate_width(size), size)
end

#plate_height(size) ⇒ Object



33
34
35
# File 'app/models/asset_shape.rb', line 33

def plate_height(size)
  multiplier(size) * vertical_ratio
end

#plate_width(size) ⇒ Object



37
38
39
# File 'app/models/asset_shape.rb', line 37

def plate_width(size)
  multiplier(size) * horizontal_ratio
end

#standard?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'app/models/asset_shape.rb', line 29

def standard?
  horizontal_ratio == 3 && vertical_ratio == 2
end

#vertical_to_horizontal(well_position, plate_size) ⇒ Object



45
46
47
# File 'app/models/asset_shape.rb', line 45

def vertical_to_horizontal(well_position, plate_size)
  alternate_position(well_position, plate_size, :height, :width)
end

#vertical_to_interlaced_vertical(well_position, plate_size) ⇒ Object



53
54
55
# File 'app/models/asset_shape.rb', line 53

def vertical_to_interlaced_vertical(well_position, plate_size)
  interlace(well_position, plate_size)
end