Skip to content

Commit

Permalink
Merge pull request #4573 from sanger/Y24-480-store-huMFre-code
Browse files Browse the repository at this point in the history
store huMFre code by sample
  • Loading branch information
sabrine33 authored Dec 20, 2024
2 parents 90b2405 + 1ec551c commit 1e3a310
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 3 deletions.
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
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

0 comments on commit 1e3a310

Please sign in to comment.