Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add huMFre code field to the samples #4559

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
3184c31
fix: generate plate volumes
StephenHulme Nov 28, 2024
12deaa2
style: lindt
StephenHulme Nov 28, 2024
df603b4
tests: split out individual expectations
StephenHulme Nov 28, 2024
b3084f7
tests: refactor and fix expectations
StephenHulme Nov 28, 2024
ca14fa1
tests: add additional tests for validation
StephenHulme Dec 2, 2024
48a0ba1
style: lint
StephenHulme Dec 3, 2024
5d6cc14
Merge branch 'develop' into y24-382-generate-plate-volumes
StephenHulme Dec 3, 2024
9c82b86
fix: allow maximum to equal minimum
StephenHulme Dec 3, 2024
91b78f3
fix: allow maximum to equal minimum (concentrations)
StephenHulme Dec 3, 2024
a2acfb9
style: lint
StephenHulme Dec 3, 2024
5b0a3ed
tests: add more
StephenHulme Dec 4, 2024
d45119c
tests: repair broken tests
StephenHulme Dec 4, 2024
2e73bc6
fix: specify what b and v stand for
StephenHulme Dec 5, 2024
1e4dd24
add huMFre code field to the samples
sabrine33 Dec 12, 2024
4874191
run prettier
sabrine33 Dec 12, 2024
569962a
fix cucumber test
sabrine33 Dec 12, 2024
5a080e0
fix: show units
StephenHulme Dec 12, 2024
6f66d94
fix: reword receptacle volume -> picking volume
StephenHulme Dec 12, 2024
9da0e25
fix: replace assay_version Binning with more suitable UAT_version
StephenHulme Dec 13, 2024
2a42c35
Merge pull request #4547 from sanger/y24-382-annotate-worksheets
StephenHulme Dec 16, 2024
90b2405
Merge pull request #4529 from sanger/y24-382-generate-plate-volumes
StephenHulme Dec 17, 2024
44df650
add huMFre code field to the samples
sabrine33 Dec 12, 2024
debfce3
run prettier
sabrine33 Dec 12, 2024
7ef8fb8
fix cucumber test
sabrine33 Dec 12, 2024
168c92e
add length constrain to the huMFre code
sabrine33 Dec 18, 2024
1ec551c
Merge remote-tracking branch 'origin/Y24-480-store-huMFre-code' into …
sabrine33 Dec 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/controllers/samples_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ def default_permitted_metadata_fields
subject
treatment
donor_id
huMFre_code
]
}
end
Expand Down
1 change: 1 addition & 0 deletions app/models/api/sample_io.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def json_root
map_attribute_to_json_attribute(:treatment)
map_attribute_to_json_attribute(:date_of_consent_withdrawn)
map_attribute_to_json_attribute(:user_id_of_consent_withdrawn, 'marked_as_consent_withdrawn_by')
map_attribute_to_json_attribute(:huMFre_code)
end

extra_json_attributes do |_object, json_attributes|
Expand Down
13 changes: 13 additions & 0 deletions app/models/sample.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ class Current < ActiveSupport::CurrentAttributes
custom_attribute(:date_of_consent_withdrawn)
custom_attribute(:user_id_of_consent_withdrawn)

custom_attribute(:huMFre_code)

# These fields are warehoused, so need to match the encoding restrictions there
# This excludes supplementary characters, which include emoji and rare kanji
# @note phenotype isn't currently broadcast but has a field waiting in the warehouse
Expand Down Expand Up @@ -226,6 +228,17 @@ class Current < ActiveSupport::CurrentAttributes
# Sample::Metadata tracks sample information, either for use in the lab, or passing to
# the EBI
class Metadata
# HuMFre numbers contain tissue information, which is only relevant for human samples.
validates :huMFre_code,
length: {
maximum: 16
},
format: {
with: %r{\A(?:\d{2}/\d{2,}|\d{2}/\d{4}-\d{3})\z},
message: 'must match a valid format, e.g. 12/34 or 12/2023-001'
},
allow_blank: true

# This constraint doesn't match that described in the manifest, and is more permissive
# It was added on conversion of out database to utf8 to address concerns that this would
# lead to an increase in characters that their pipeline cannot process. Only a handful
Expand Down
8 changes: 4 additions & 4 deletions app/uat_actions/uat_actions/generate_plate_concentrations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def self.default
validates :concentration_units, presence: { message: 'needs a choice' }
validates :minimum_concentration, numericality: { only_integer: false }
validates :maximum_concentration, numericality: { greater_than: 0, only_integer: false }
validate :maximum_greater_than_minimum
validate :maximum_greater_than_or_equal_to_minimum

def perform
qc_assay_results = construct_qc_assay
Expand All @@ -58,10 +58,10 @@ def perform

private

def maximum_greater_than_minimum
return true if max_conc > min_conc
def maximum_greater_than_or_equal_to_minimum
return true if max_conc >= min_conc

errors.add(:maximum_concentration, 'needs to be greater than minimum concentration')
errors.add(:maximum_concentration, 'needs to be greater than or equal to minimum concentration')
false
end

Expand Down
101 changes: 101 additions & 0 deletions app/uat_actions/uat_actions/generate_plate_volumes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# frozen_string_literal: true

# Will generate volumes for a given plate
class UatActions::GeneratePlateVolumes < UatActions
self.title = 'Generate volumes for a plate'
self.description = 'Generate a set of randomised volumes for a plate.'
self.category = :quality_control

form_field :plate_barcode,
:text_field,
label: 'Plate barcode',
help:
'Enter the barcode of the plate for which you want to add volumes. ' \
'NB. only well containing aliquots will have volumes set.'
form_field :minimum_volume,
:number_field,
label: 'Minimum volume (µl)',
help: 'The minimum volume the wells should have.',
options: {
minimum: 0
}
form_field :maximum_volume,
:number_field,
label: 'Maximum volume (µl)',
help: 'The maximum volume the wells should have.',
options: {
minimum: 0
}

#
# Returns a default copy of the UatAction which will be used to fill in the form, with values
# for the units, and min and max volumes.
#
# @return [UatActions::GeneratePlateVolumes] A default object for rendering a form
def self.default
new(minimum_volume: 0, maximum_volume: 100)
end

validates :plate_barcode, presence: { message: 'could not be found' }
validates :minimum_volume, numericality: { only_integer: false }
validates :maximum_volume, numericality: { greater_than: 0, only_integer: false }
validate :maximum_greater_than_or_equal_to_minimum

def perform
qc_assay_results = construct_qc_assay
report['number_well_volumes_written'] = qc_assay_results[:num_wells_written]
qc_assay_results[:qc_assay_success]
end

private

def maximum_greater_than_or_equal_to_minimum
return true if max_vol >= min_vol

errors.add(:maximum_volume, 'needs to be greater than or equal to minimum volume')
false
end

def labware
@labware ||= Plate.find_by_barcode(plate_barcode.strip)
end

def key
@key ||= 'volume'
end

def min_vol
@min_vol ||= minimum_volume.to_f
end

def max_vol
@max_vol ||= maximum_volume.to_f
end

def create_random_volume
value = (rand * (max_vol - min_vol)) + min_vol
format('%.3f', value)
end

def construct_qc_assay
qc_assay = QcAssay.new
num_wells_written = 0

labware.wells.each do |well|
next if well.aliquots.empty?

QcResult.create!(
asset: well,
key: key,
value: create_random_volume,
units: 'µl',
assay_type: 'UAT_Testing',
assay_version: 'UAT_version',
qc_assay: qc_assay
)
num_wells_written += 1
end
qc_assay_success = qc_assay.save
{ qc_assay_success:, num_wells_written: }
end
end
3 changes: 2 additions & 1 deletion app/views/batches/_cherrypick_single_worksheet.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
</div>

<div id="footer">
Created: <%= batch.updated_at.strftime("%I:%M %p on %A %d %B, %Y") %> for <%= batch.user.login %> -
v = picking volume µl; b = buffer volume µl<br>
Created: <%= batch.updated_at.strftime("%I:%M %p on %A %d %B, %Y") %> for <%= batch.user.login %><br>
Printed: <%= Time.now.strftime("%I:%M %p on %A %d %B, %Y") %> for <%= current_user.login %>
</div>
2 changes: 2 additions & 0 deletions app/views/shared/metadata/edit/_sample.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@
<%= metadata_fields.text_field(:disease) %>
<%= metadata_fields.text_field(:treatment)%>

<%= metadata_fields.text_field(:huMFre_code)%>

<% metadata_fields.finalize_related_fields %>
<% end %>
<% end %>
Expand Down
2 changes: 2 additions & 0 deletions app/views/shared/metadata/show/_sample.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,7 @@
<%= metadata_fields.plain_value(:disease) %>
<%= metadata_fields.plain_value(:treatment)%>

<%= metadata_fields.plain_value(:huMFre_code)%>

<% end %>
<% end %>
2 changes: 2 additions & 0 deletions config/locales/metadata/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,8 @@ en:
edit_info: "EGA"
genome_size:
label: Genome Size
huMFre_code:
label: HuMFre Code

study:
metadata:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true
class AddHuMFreCodeToSampleMetadata < ActiveRecord::Migration[7.0]
def change
add_column :sample_metadata, :huMFre_code, :string, limit: 16
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2024_11_06_103710) do
ActiveRecord::Schema[7.0].define(version: 2024_12_11_143636) do
create_table "aliquot_indices", id: :integer, charset: "utf8mb4", collation: "utf8mb4_unicode_ci", options: "ENGINE=InnoDB ROW_FORMAT=DYNAMIC", force: :cascade do |t|
t.integer "aliquot_id", null: false
t.integer "lane_id", null: false
Expand Down Expand Up @@ -1395,6 +1395,7 @@
t.integer "user_id_of_consent_withdrawn"
t.boolean "consent_withdrawn", default: false, null: false
t.string "collected_by", comment: "Name of persons or institute who collected the specimen"
t.string "huMFre_code", limit: 16
t.index ["sample_ebi_accession_number"], name: "index_sample_metadata_on_sample_ebi_accession_number"
t.index ["sample_id"], name: "index_sample_metadata_on_sample_id"
t.index ["supplier_name"], name: "index_sample_metadata_on_supplier_name"
Expand Down
1 change: 1 addition & 0 deletions features/samples/xml_interface.feature
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ Feature: The XML interface to the samples
<property><name>Time Point</name><value></value></property>
<property><name>Donor Id</name><value></value></property>
<property><name>Collected By</name><value/></property>
<property><name>HuMFre Code</name><value/></property>
</properties>
</sample>
"""
6 changes: 4 additions & 2 deletions spec/models/api/sample_io_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@
sample_strain_att: 'stuff about strain',
consent_withdrawn: false,
donor_id: 2,
developmental_stage: 'thing'
developmental_stage: 'thing',
huMFre_code: '23/21'
}
)
end
Expand Down Expand Up @@ -133,7 +134,8 @@
'developmental_stage' => 'thing',
'donor_id' => '2',
'reference_genome' => 'ReferenceGenome1',
'component_sample_uuids' => [{ uuid: comp_sample1.uuid }, { uuid: comp_sample2.uuid }]
'component_sample_uuids' => [{ uuid: comp_sample1.uuid }, { uuid: comp_sample2.uuid }],
'huMFre_code' => '23/21'
}
end

Expand Down
24 changes: 24 additions & 0 deletions spec/models/sample_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,30 @@
end
end

context 'huMFre code' do
let(:sample) { create(:sample) }

it 'defaults to null when not specified' do
expect(sample.sample_metadata.huMFre_code).to be_nil
end

it 'fails to update/save when huMFre code value is invalid' do
expect(sample.sample_metadata.huMFre_code).to be_nil
sample.sample_metadata.huMFre_code = 'humFre1'
expect(sample.sample_metadata.save).to be false
end

it 'contains huMFre code value when it is correctly specified' do
sample.sample_metadata.update!(huMFre_code: '12/12')
expect(sample.sample_metadata.huMFre_code).to eq '12/12'
end

it 'can have the huMFre code blanked' do
sample.sample_metadata.update!(huMFre_code: nil)
expect(sample.sample_metadata.huMFre_code).to be_nil
end
end

context '(DPL-148) on updating sample metadata' do
let(:sample) { create(:sample) }

Expand Down
Loading
Loading