Module: Plate::FluidigmBehaviour

Included in:
Plate
Defined in:
app/models/plate/fluidigm_behaviour.rb

Defined Under Namespace

Classes: FluidigmError

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

rubocop:todo Metrics/MethodLength



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/models/plate/fluidigm_behaviour.rb', line 6

def self.included(base) # rubocop:todo Metrics/MethodLength
  base.class_eval do
    scope :requiring_fluidigm_data,
          -> do
            fluidigm_request_ids = RequestType.where(key: 'pick_to_fluidigm').ids

            joins(
              [
                :well_requests_as_target,
                "LEFT OUTER JOIN events
          ON eventful_id = #{Plate.table_name}.id
          AND eventful_type = \"#{Plate.base_class.name}\"
          AND family = \"update_fluidigm_plate\"
          AND content = \"FLUIDIGM_DATA\""
              ]
            )
              .includes(:barcodes)
              .where(events: { id: nil }, requests: { request_type_id: fluidigm_request_ids })
              .distinct
          end
  end
end

Instance Method Details

#apply_fluidigm_data(fluidigm_file) ⇒ Object

rubocop:todo Metrics/MethodLength

Raises:



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'app/models/plate/fluidigm_behaviour.rb', line 43

def apply_fluidigm_data(fluidigm_file) # rubocop:todo Metrics/AbcSize
  qc_assay = QcAssay.new
  raise FluidigmError, 'File does not match plate' unless fluidigm_file.for_plate?(fluidigm_barcode)

  wells
    .located_at(fluidigm_file.well_locations)
    .include_stock_wells
    .each do |well|
      well.stock_wells.each do |sw|
        gender_markers = fluidigm_file.well_at(well.map_description).gender_markers.join('')
        loci_passed = fluidigm_file.well_at(well.map_description).count
        QcResult.create!(
          [
            {
              asset: sw,
              key: 'gender_markers',
              assay_type: 'FLUIDIGM',
              assay_version: 'v0.1',
              value: gender_markers,
              units: 'bases',
              qc_assay: qc_assay
            },
            {
              asset: sw,
              key: 'loci_passed',
              assay_type: 'FLUIDIGM',
              assay_version: 'v0.1',
              value: loci_passed,
              units: 'bases',
              qc_assay: qc_assay
            }
          ]
        )
      end
    end
  events.updated_fluidigm_plate!('FLUIDIGM_DATA')
end

#retrieve_fluidigm_dataObject



29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/models/plate/fluidigm_behaviour.rb', line 29

def retrieve_fluidigm_data
  ActiveRecord::Base.transaction do
    fluidigm_data = FluidigmFile::Finder.find(fluidigm_barcode)

    # rubocop:todo Rails/TransactionExitStatement
    return false if fluidigm_data.empty? # Return false if we have no data

    # rubocop:enable Rails/TransactionExitStatement

    apply_fluidigm_data(FluidigmFile.new(fluidigm_data.content))
  end
end