Skip to content

Commit 290447a

Browse files
authored
Merge pull request #1365 from sanger/y24-096-add-uuid-to-aliquot
refactor: add uuid field to aliquot
2 parents 06faafb + c150abb commit 290447a

File tree

8 files changed

+77
-8
lines changed

8 files changed

+77
-8
lines changed

app/exchanges/volume_tracking/message_builder.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class MessageBuilder < Message::Message
1111
# "messageUuid"=>"0a62ee15-bbf6-46f0-ba95-01d42622d076",
1212
# "recordedAt"=>Mon, 15 Jul 2024 15:16:54.867713000 UTC +00:00,
1313
# "volume"=>1.5, "concentration"=>10.0, "insertSize"=>100, "aliquotType"=>"primary",
14-
# "aliquotId"=>"", "sourceType"=>"library", "sourceBarcode"=>"TRAC-2-35805",
14+
# "aliquotUuid"=>"", "sourceType"=>"library", "sourceBarcode"=>"TRAC-2-35805",
1515
# "sampleName"=>"Sample1", "usedByBarcode"=>"TRAC-2-35806", "usedByType"=>"pool"}}
1616

1717
def publish_data # rubocop:disable Metrics/MethodLength
@@ -20,7 +20,7 @@ def publish_data # rubocop:disable Metrics/MethodLength
2020

2121
aliquot = object
2222
data = { source_type: '', source_barcode: '', sample_name: '',
23-
used_by_type: 'nil', used_by_barcode: '', aliquot_id: aliquot.id.to_s || '' }
23+
used_by_type: 'nil', used_by_barcode: '', aliquot_uuid: aliquot.uuid || '' }
2424

2525
case aliquot.source_type
2626
when 'Pacbio::Library'

app/models/aliquot.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# An aliquot can be used to track volumes and concentrations of samples
77
class Aliquot < ApplicationRecord
88
include SampleSheet::Aliquot
9+
include Uuidable
910

1011
enum state: { created: 0, used: 1 }
1112
enum aliquot_type: { primary: 0, derived: 1 }

config/pipelines/pacbio.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,9 @@ default: &default
333333
aliquotType:
334334
type: :model
335335
value: aliquot_type
336-
aliquotId:
336+
aliquotUuid:
337337
type: :self
338-
value: publish_data&.aliquot_id
338+
value: publish_data&.aliquot_uuid
339339
sourceType:
340340
type: :self
341341
value: publish_data&.source_type
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# frozen_string_literal: true
2+
3+
namespace :aliquots do
4+
# A rake task to be run to add UUIDs to all aliquots that do not have one
5+
desc 'Update aliquots with UUID'
6+
7+
task add_missing_uuids: :environment do
8+
puts '-> Updating aliquots with UUID'
9+
10+
ActiveRecord::Base.transaction do
11+
# If an aliquot does not have a UUID set it
12+
Aliquot.where(uuid: nil).find_each do |aliquot|
13+
aliquot.update!(uuid: SecureRandom.uuid)
14+
end
15+
end
16+
end
17+
end

spec/exchanges/volume_tracking/message_builder_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
sample_name: pacbio_library.sample_name,
2222
used_by_type: 'nil',
2323
used_by_barcode: '',
24-
aliquot_id: aliquot.id.to_s || ''
24+
aliquot_uuid: aliquot.uuid
2525
})
2626
end
2727
end
@@ -37,7 +37,7 @@
3737
sample_name: pacbio_library.sample_name,
3838
used_by_type: 'pool',
3939
used_by_barcode: pacbio_pool.tube.barcode,
40-
aliquot_id: aliquot.id.to_s || ''
40+
aliquot_uuid: aliquot.uuid
4141
})
4242
end
4343
end
@@ -53,7 +53,7 @@
5353
sample_name: pacbio_library.sample_name,
5454
used_by_type: 'well',
5555
used_by_barcode: "#{pacbio_well.plate.sequencing_kit_box_barcode}:#{pacbio_well.plate.plate_number}:#{pacbio_well.position}",
56-
aliquot_id: aliquot.id.to_s || ''
56+
aliquot_uuid: aliquot.uuid
5757
})
5858
end
5959
end

spec/fixtures/volume_tracking_avro_response.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"subject": "create-aliquot-in-mlwh",
33
"version": 1,
44
"id": 14,
5-
"schema": "{\"type\":\"record\",\"name\":\"CreateAliquotInMLWH\",\"namespace\":\"uk.ac.sanger.psd\",\"doc\":\"Create an Aliquot in MLWH coming from Traction.\",\"fields\":[{\"name\":\"messageUuid\",\"type\":{\"type\":\"string\",\"logicalType\":\"uuid\"},\"doc\":\"Unique message ID.\"},{\"name\":\"messageCreateDateUtc\",\"type\":{\"type\":\"long\",\"logicalType\":\"timestamp-millis\"},\"doc\":\"Date (UTC) that the message was created.\"},{\"name\":\"limsId\",\"type\":\"string\",\"doc\":\"The LIMS system that the aliquot was created in\"},{\"name\":\"aliquotId\",\"type\":{\"type\":\"string\",\"logicalType\":\"uuid\"},\"doc\":\"The UUID of the aliquot in the LIMS system\"},{\"name\":\"aliquotType\",\"type\":{\"type\":\"enum\",\"name\":\"allowedAliquotType\",\"symbols\":[\"primary\",\"derived\"]},\"doc\":\"The type of the aliquot\"},{\"name\":\"sourceType\",\"type\":{\"type\":\"enum\",\"name\":\"allowedSourceType\",\"symbols\":[\"well\",\"sample\",\"library\",\"pool\"]},\"doc\":\"The type of the source of the aliquot\"},{\"name\":\"sourceBarcode\",\"type\":\"string\",\"doc\":\"The barcode of the source of the aliquot\"},{\"name\":\"sampleName\",\"type\":\"string\",\"doc\":\"The name of the sample that the aliquot was created from\"},{\"name\":\"usedByType\",\"type\":{\"type\":\"enum\",\"name\":\"allowedUsedByType\",\"symbols\":[\"library\",\"pool\",\"run\",\"none\"],\"default\":\"none\"},\"doc\":\"The type of the entity that the aliquot is used by\"},{\"name\":\"usedByBarcode\",\"type\":\"string\",\"doc\":\"The barcode of the entity that the aliquot is used by\"},{\"name\":\"volume\",\"type\":\"float\",\"doc\":\"The volume of the aliquot (uL)\"},{\"name\":\"concentration\",\"type\":[\"null\",\"float\"],\"doc\":\"The concentration of the aliquot (ng/ul)\",\"default\":null},{\"name\":\"insertSize\",\"type\":[\"null\",\"int\"],\"doc\":\"The insert size for the aliquot\",\"default\":null},{\"name\":\"recordedAt\",\"type\":{\"type\":\"long\",\"logicalType\":\"timestamp-millis\"},\"doc\":\"The date and time that the aliquot was recorded\"}]}"
5+
"schema": "{\"type\":\"record\",\"name\":\"CreateAliquotInMLWH\",\"namespace\":\"uk.ac.sanger.psd\",\"doc\":\"Create an Aliquot in MLWH coming from Traction.\",\"fields\":[{\"name\":\"messageUuid\",\"type\":{\"type\":\"string\",\"logicalType\":\"uuid\"},\"doc\":\"Unique message ID.\"},{\"name\":\"messageCreateDateUtc\",\"type\":{\"type\":\"long\",\"logicalType\":\"timestamp-millis\"},\"doc\":\"Date (UTC) that the message was created.\"},{\"name\":\"limsId\",\"type\":\"string\",\"doc\":\"The LIMS system that the aliquot was created in\"},{\"name\":\"aliquotUuid\",\"type\":{\"type\":\"string\",\"logicalType\":\"uuid\"},\"doc\":\"The UUID of the aliquot in the LIMS system\"},{\"name\":\"aliquotType\",\"type\":{\"type\":\"enum\",\"name\":\"allowedAliquotType\",\"symbols\":[\"primary\",\"derived\"]},\"doc\":\"The type of the aliquot\"},{\"name\":\"sourceType\",\"type\":{\"type\":\"enum\",\"name\":\"allowedSourceType\",\"symbols\":[\"well\",\"sample\",\"library\",\"pool\"]},\"doc\":\"The type of the source of the aliquot\"},{\"name\":\"sourceBarcode\",\"type\":\"string\",\"doc\":\"The barcode of the source of the aliquot\"},{\"name\":\"sampleName\",\"type\":\"string\",\"doc\":\"The name of the sample that the aliquot was created from\"},{\"name\":\"usedByType\",\"type\":{\"type\":\"enum\",\"name\":\"allowedUsedByType\",\"symbols\":[\"library\",\"pool\",\"run\",\"none\"],\"default\":\"none\"},\"doc\":\"The type of the entity that the aliquot is used by\"},{\"name\":\"usedByBarcode\",\"type\":\"string\",\"doc\":\"The barcode of the entity that the aliquot is used by\"},{\"name\":\"volume\",\"type\":\"float\",\"doc\":\"The volume of the aliquot (uL)\"},{\"name\":\"concentration\",\"type\":[\"null\",\"float\"],\"doc\":\"The concentration of the aliquot (ng/ul)\",\"default\":null},{\"name\":\"insertSize\",\"type\":[\"null\",\"int\"],\"doc\":\"The insert size for the aliquot\",\"default\":null},{\"name\":\"recordedAt\",\"type\":{\"type\":\"long\",\"logicalType\":\"timestamp-millis\"},\"doc\":\"The date and time that the aliquot was recorded\"}]}"
66
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# frozen_string_literal: true
2+
3+
require 'rails_helper'
4+
require 'rake'
5+
6+
# only load Rake tasks if they haven't been loaded already
7+
Rails.application.load_tasks if Rake::Task.tasks.empty?
8+
9+
RSpec.describe 'RakeTasks' do
10+
# Create a default SMRTLink version to be used by factories
11+
before do
12+
Pacbio::SmrtLinkVersion.find_by(name: 'v13_sequel_iie') || create(:pacbio_smrt_link_version, name: 'v13_sequel_iie', default: true)
13+
end
14+
15+
describe 'aliquots:add_missing_uuids' do
16+
define_negated_matcher :not_change, :change
17+
18+
it 'assigns a random UUID to all aliquots that currently lack one.' do
19+
aliquots_with_empty_uuid = create_list(:aliquot, 5, used_by: create(:pacbio_pool), uuid: nil)
20+
aliquots_with_uuid = create_list(:aliquot, 5, used_by: create(:pacbio_pool))
21+
22+
# Get uuids to check they are not affected
23+
uuids = aliquots_with_uuid.map(&:uuid)
24+
25+
# We shouldnt change the amount of aliquots
26+
expect { Rake::Task['aliquots:add_missing_uuids'].invoke }.to not_change(Aliquot, :count).and output(
27+
<<~HEREDOC
28+
-> Updating aliquots with UUID
29+
HEREDOC
30+
).to_stdout
31+
32+
# Aliquots without uuids should have a uuid set
33+
aliquots_with_empty_uuid.each do |aliquot|
34+
aliquot.reload
35+
expect(aliquot.uuid).not_to be_nil
36+
end
37+
38+
# Other aliquots should not be affected
39+
aliquots_with_uuid.each do |aliquot|
40+
aliquot.reload
41+
expect(uuids).to include aliquot.uuid
42+
end
43+
end
44+
end
45+
end

spec/models/aliquot_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
require 'rails_helper'
44

55
RSpec.describe Aliquot do
6+
context 'uuidable aliquot' do
7+
let(:uuidable_model) { :aliquot }
8+
9+
it_behaves_like 'uuidable'
10+
end
11+
612
it 'is invalid without volume' do
713
expect(build(:aliquot, volume: nil)).not_to be_valid
814
end

0 commit comments

Comments
 (0)