Skip to content

Commit

Permalink
feat(pacbio-run-resource): adds adaptive_loading and sequencing_kit_b…
Browse files Browse the repository at this point in the history
…ox_barcodes attributes
  • Loading branch information
BenTopping committed Jan 10, 2025
1 parent 987009d commit 1854433
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 5 deletions.
10 changes: 10 additions & 0 deletions app/models/pacbio/run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>] 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
Expand Down
15 changes: 14 additions & 1 deletion app/resources/v1/pacbio/run_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,14 @@ class RunResource < JSONAPI::Resource
# @return [Integer] the ID of the PacBio SMRT Link version
# @!attribute [rw] plates_attributes
# @return [Array<Hash>] the attributes of the plates
# @!attribute [r] adaptive_loading
# @return [Boolean] whether adaptive loading is used
# @!attribute [r] sequencing_kit_box_barcodes
# @return [Array<String>] 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'
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion config/pacbio_smrt_link_versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ default: &default
- v12_revio
- v13_revio
- v13_1_revio
- v25_1_revio
library_type:
key: library_type
label: "Library Type"
Expand Down
34 changes: 34 additions & 0 deletions spec/models/pacbio/run_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }

Expand Down
45 changes: 42 additions & 3 deletions spec/requests/v1/pacbio/runs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
{
Expand Down

0 comments on commit 1854433

Please sign in to comment.