diff --git a/app/models/pacbio/run.rb b/app/models/pacbio/run.rb index 0c8cae2d9..57ac06c11 100644 --- a/app/models/pacbio/run.rb +++ b/app/models/pacbio/run.rb @@ -134,6 +134,16 @@ def used_aliquots_lib_source_in_pool(pools) end end + # @return [Boolean] true if all wells have adaptive loading enabled + def adaptive_loading + wells.all? { |w| w.use_adaptive_loading == 'True' } + end + + # @return [Array] the barcodes of the sequencing kits + def sequencing_kit_box_barcodes + plates.map { |p| "Plate #{p.plate_number}: #{p.sequencing_kit_box_barcode}" } + end + private # We now have SMRT Link versioning diff --git a/app/resources/v1/pacbio/run_resource.rb b/app/resources/v1/pacbio/run_resource.rb index 195e8c786..a9f0bfa07 100644 --- a/app/resources/v1/pacbio/run_resource.rb +++ b/app/resources/v1/pacbio/run_resource.rb @@ -32,9 +32,14 @@ class RunResource < JSONAPI::Resource # @return [Integer] the ID of the PacBio SMRT Link version # @!attribute [rw] plates_attributes # @return [Array] the attributes of the plates + # @!attribute [r] adaptive_loading + # @return [Boolean] whether adaptive loading is used + # @!attribute [r] sequencing_kit_box_barcodes + # @return [Array] the barcodes of the sequencing kits attributes :name, :dna_control_complex_box_barcode, :system_name, :created_at, :state, :comments, - :pacbio_smrt_link_version_id, :plates_attributes + :pacbio_smrt_link_version_id, :plates_attributes, + :adaptive_loading, :sequencing_kit_box_barcodes has_many :plates, foreign_key_on: :related, foreign_key: 'pacbio_run_id', class_name: 'Runs::Plate' @@ -86,6 +91,14 @@ def publish_messages 'volume_tracking') end + def self.creatable_fields(context) + super - %i[adaptive_loading sequencing_kit_box_barcodes] + end + + def self.updatable_fields(context) + super - %i[adaptive_loading sequencing_kit_box_barcodes] + end + private def plates_attributes=(plates_parameters) # rubocop:disable Metrics/MethodLength diff --git a/config/pacbio_smrt_link_versions.yml b/config/pacbio_smrt_link_versions.yml index f6716fd00..c80e8d38f 100644 --- a/config/pacbio_smrt_link_versions.yml +++ b/config/pacbio_smrt_link_versions.yml @@ -261,7 +261,6 @@ default: &default - v12_revio - v13_revio - v13_1_revio - - v25_1_revio library_type: key: library_type label: "Library Type" diff --git a/spec/models/pacbio/run_spec.rb b/spec/models/pacbio/run_spec.rb index 072d7df89..baf8c5e2b 100644 --- a/spec/models/pacbio/run_spec.rb +++ b/spec/models/pacbio/run_spec.rb @@ -233,6 +233,40 @@ end end + context 'adaptive_loading' do + it 'is false if the wells do not have use_adaptive_loading' do + # Sequel run wells do not have use_adaptive_loading + run = create(:pacbio_sequel_run) + expect(run.adaptive_loading).to be false + end + + it 'is false if the wells have use_adaptive_loading set to false' do + # Revio run wells have use_adaptive_loading set to false + run = create(:pacbio_revio_run) + expect(run.adaptive_loading).to be false + end + + it 'is true if the wells have use_adaptive_loading set to true' do + # Revio run wells have use_adaptive_loading set to true + run = create(:pacbio_revio_run) + run.wells.each do |w| + w.use_adaptive_loading = 'True' + w.save + end + expect(run.adaptive_loading).to be true + end + end + + context 'sequencing_kit_box_barcodes' do + it 'returns the barcodes of the sequencing kits' do + run = create(:pacbio_revio_run) + expect(run.sequencing_kit_box_barcodes).to eq([ + "Plate 1: #{run.plates.first.sequencing_kit_box_barcode}", + "Plate 2: #{run.plates.second.sequencing_kit_box_barcode}" + ]) + end + end + describe '#create with nested attributes' do let!(:pools) { create_list(:pacbio_pool, 2) } diff --git a/spec/requests/v1/pacbio/runs_spec.rb b/spec/requests/v1/pacbio/runs_spec.rb index b7b7362b1..a7df2b869 100644 --- a/spec/requests/v1/pacbio/runs_spec.rb +++ b/spec/requests/v1/pacbio/runs_spec.rb @@ -125,7 +125,9 @@ 'state' => run.state, 'comments' => run.comments, 'pacbio_smrt_link_version_id' => run.pacbio_smrt_link_version_id, - 'created_at' => run.created_at.to_fs(:us) + 'created_at' => run.created_at.to_fs(:us), + 'adaptive_loading' => run.adaptive_loading, + 'sequencing_kit_box_barcodes' => run.sequencing_kit_box_barcodes ) end end @@ -157,7 +159,9 @@ 'state' => run1.state, 'comments' => run1.comments, 'pacbio_smrt_link_version_id' => run1.pacbio_smrt_link_version_id, - 'created_at' => run1.created_at.to_fs(:us) + 'created_at' => run1.created_at.to_fs(:us), + 'adaptive_loading' => run1.adaptive_loading, + 'sequencing_kit_box_barcodes' => run1.sequencing_kit_box_barcodes ) end end @@ -187,7 +191,9 @@ 'state' => run1.state, 'comments' => run1.comments, 'pacbio_smrt_link_version_id' => run1.pacbio_smrt_link_version_id, - 'created_at' => run1.created_at.to_fs(:us) + 'created_at' => run1.created_at.to_fs(:us), + 'adaptive_loading' => run1.adaptive_loading, + 'sequencing_kit_box_barcodes' => run1.sequencing_kit_box_barcodes ) end end @@ -497,6 +503,39 @@ end end + context 'when there are read-only attributes' do + let(:body) do + { + data: { + type: 'runs', + attributes: { + adaptive_loading: 'True', + sequencing_kit_box_barcodes: ['Plate 1: DM0001100861800123121'] + } + } + }.to_json + end + + it 'has a bad_request status' do + post v1_pacbio_runs_path, params: body, headers: json_api_headers + expect(response).to have_http_status(:bad_request) + end + + it 'does not create a run' do + expect do + post v1_pacbio_runs_path, params: body, + headers: json_api_headers + end.not_to change(Pacbio::Run, :count) + end + + it 'has the correct error messages' do + post v1_pacbio_runs_path, params: body, headers: json_api_headers + json = ActiveSupport::JSON.decode(response.body) + errors = json['errors'] + expect(errors[0]['detail']).to eq 'adaptive_loading is not allowed.' + end + end + context 'when there no wells' do let(:body) do {