Class: V1::MultiPoolResource

Inherits:
JSONAPI::Resource
  • Object
show all
Defined in:
app/resources/v1/multi_pool_resource.rb

Overview

Note:

Access this resource via the /v1/multi_pools endpoint.

MultiPoolResource provides a JSON:API representation of the MultiPool model. It allows API clients to query, filter, and retrieve multi-pool-related information.

Provides a JSON:API representation of MultiPool and exposes valid request for use by the UI.

Filters: * pipeline * pool_method * pool_barcode

Primary relationships: * multi_pool_positions MultiPoolPositionResource

Examples:

curl -X GET http://localhost:3100/v1/multi_pools
curl -X GET http://localhost:3100/v1/multi_pools/1
curl -X GET "http://localhost:3100/v1/multi_pools/1?include=multi_pool_positions"
curl -X GET "http://localhost:3100/v1/multi_pools?filter[pipeline]=pacbio"
curl -X POST "http://localhost:3100/v1/multi_pools" \
   -H "accept: application/vnd.api+json" \
   -H "Content-Type: application/vnd.api+json" \
   -d '{
     "data": {
       "type": "multi_pools",
       "attributes": {
          "pool_method": "Plate",
          "pipeline": "pacbio",
          "multi_pool_positions_attributes": [
            {
              "position": "A1",
              "pacbio_pool_attributes": {
                "template_prep_kit_box_barcode": "LK1234567",
                "volume": 1.11,
                "concentration": 2.22,
                "insert_size": 100,
                "used_aliquots_attributes": [
                  {
                    "volume": 1.11,
                    "template_prep_kit_box_barcode": "LK1234567",
                    "concentration": 2.22,
                    "insert_size": 100,
                    "source_id": 1,
                    "source_type": "Pacbio::Request",
                    "tag_id": 1
                  }
                ],
                "primary_aliquot_attributes": {
                  "volume": 200,
                  "concentration": 22,
                  "template_prep_kit_box_barcode": 100,
                  "insert_size": 11
                }
              }
            }
          ]
        }
      }
     }'
curl -X PATCH "http://localhost:3100/v1/multi_pools/2" \
    -H "accept: application/vnd.api+json" \
    -H "Content-Type: application/vnd.api+json" \
    -d '{
         "data": {
             "type": "multi_pools",
             "id": "2",
             "attributes": {
                 "pool_method": "Plate",
                 "pipeline": "pacbio",
                 "multi_pool_positions_attributes": [
                     {
                         "id": 2,
                         "position": "A1",
                         "pacbio_pool_attributes": {
                             "id": 15,
                             "template_prep_kit_box_barcode": "LK1234567",
                             "volume": 1.11,
                             "concentration": 2.22,
                             "insert_size": 100,
                             "used_aliquots_attributes": [
                                 {
                                     "id": 363,
                                     "volume": 1.11,
                                     "template_prep_kit_box_barcode": "LK1234567",
                                     "concentration": 2.22,
                                     "insert_size": 100,
                                     "source_id": 1,
                                     "source_type": "Pacbio::Request",
                                     "tag_id": 1
                                 }
                             ],
                             "primary_aliquot_attributes": {
                                 "id": 364,
                                 "volume": 200,
                                 "concentration": 22,
                                 "template_prep_kit_box_barcode": 100,
                                 "insert_size": 11
                             }
                         }
                     }
                 ]
             }
         }
       }'

Constant Summary collapse

MULTI_POOL_POSITIONS_ATTRIBUTES =
%w[id position
pacbio_pool_attributes].freeze
PACBIO_POOL_ATTRIBUTES =
%w[id volume concentration template_prep_kit_box_barcode
insert_size created_at updated_at
library_attributes used_aliquots_attributes
primary_aliquot_attributes
used_volume available_volume].freeze
ALIQUOT_ATTRIBUTES =
%w[id volume concentration template_prep_kit_box_barcode insert_size
tag_id source_id source_type].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#created_atString (readonly)

Returns the creation date of the multi_pool in US format via override below.

Returns:

  • (String)

    the creation date of the multi_pool in US format via override below



122
# File 'app/resources/v1/multi_pool_resource.rb', line 122

attributes :number_of_pools, :created_at, readonly: true

#multi_pool_position_attributes=(value) ⇒ Array<Hash> (writeonly)

Returns attributes for creating/updating nested multi_pool_positions.

Returns:

  • (Array<Hash>)

    attributes for creating/updating nested multi_pool_positions



126
# File 'app/resources/v1/multi_pool_resource.rb', line 126

attribute :multi_pool_positions_attributes

#number_of_poolsInteger (readonly)

Returns a computed number of pools in the multi_pool.

Returns:

  • (Integer)

    a computed number of pools in the multi_pool



122
# File 'app/resources/v1/multi_pool_resource.rb', line 122

attributes :number_of_pools, :created_at, readonly: true

#pipelineString

Returns the pipeline associated with the multi_pool .e.g. “Pacbio” or “Ont”.

Returns:

  • (String)

    the pipeline associated with the multi_pool .e.g. “Pacbio” or “Ont”



116
# File 'app/resources/v1/multi_pool_resource.rb', line 116

attributes :pool_method, :pipeline

#pool_methodInteger

Returns the method used for pooling.

Returns:

  • (Integer)

    the method used for pooling



116
# File 'app/resources/v1/multi_pool_resource.rb', line 116

attributes :pool_method, :pipeline

Class Method Details

.default_sortObject



147
148
149
# File 'app/resources/v1/multi_pool_resource.rb', line 147

def self.default_sort
  [{ field: 'created_at', direction: :desc }]
end

Instance Method Details

#fetchable_fieldsObject



188
189
190
# File 'app/resources/v1/multi_pool_resource.rb', line 188

def fetchable_fields
  super - %i[multi_pool_positions_attributes]
end

#multi_pool_positions_attributes=(multi_pool_positions_parameters) ⇒ Object

We need to override the setter to permit nested attributes for multi_pool_positions and their nested pacbio_pools and their nested used_aliquots and primary_aliquot



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'app/resources/v1/multi_pool_resource.rb', line 168

def multi_pool_positions_attributes=(multi_pool_positions_parameters) # rubocop:disable Metrics/MethodLength
  @model.multi_pool_positions_attributes = multi_pool_positions_parameters.map do |mpp|
    mpp.permit(
      *MULTI_POOL_POSITIONS_ATTRIBUTES,
      :_destroy,
      pacbio_pool_attributes: [
        :_destroy,
        *PACBIO_POOL_ATTRIBUTES,
        { used_aliquots_attributes: [
            :_destroy,
            *ALIQUOT_ATTRIBUTES
          ],
          primary_aliquot_attributes: [
            *ALIQUOT_ATTRIBUTES
          ] }
      ]
    ).to_h.with_indifferent_access
  end
end

#publish_messages_on_creationObject



192
193
194
195
196
197
198
199
200
# File 'app/resources/v1/multi_pool_resource.rb', line 192

def publish_messages_on_creation
  # Collect pacbio pools only
  @model.multi_pool_positions.each do |mpp|
    next if mpp.pacbio_pool.blank?

    # Publish volume tracking message for each pacbio pool's primary aliquot
    Emq::Publisher.publish(mpp.pacbio_pool.primary_aliquot, Pipelines.pacbio, 'volume_tracking')
  end
end

#publish_messages_on_updateObject



202
203
204
205
206
207
208
209
210
211
212
213
# File 'app/resources/v1/multi_pool_resource.rb', line 202

def publish_messages_on_update
  @model.multi_pool_positions.each do |mpp|
    next if mpp.pacbio_pool.blank?

    # Publish volume tracking message for each pacbio pool's primary aliquot
    Emq::Publisher.publish(mpp.pacbio_pool.primary_aliquot, Pipelines.pacbio, 'volume_tracking')
    # Publish messages for sequencing runs associated with the pool
    # This may not be the most efficient way as a multi pool may be updated without every pool
    # being changed, but it ensures all runs are up to date
    Messages.publish(mpp.pacbio_pool.sequencing_runs, Pipelines.pacbio.message)
  end
end