-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from sanger/next_release
Release 1.7.0
- Loading branch information
Showing
6 changed files
with
280 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
class StockResource < ActiveRecord::Base | ||
include ResourceTools | ||
include CompositeResourceTools | ||
|
||
has_associated(:study) | ||
has_associated(:sample) | ||
|
||
has_composition_keys(:id_stock_resource_lims,:id_sample_tmp) | ||
|
||
json do | ||
|
||
translate( | ||
:stock_resource_id => :id_stock_resource_lims, | ||
:uuid => :stock_resource_uuid | ||
) | ||
|
||
has_nested_model(:samples) do | ||
end | ||
|
||
ignore(:samples) | ||
|
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
class AddStockResourcesTable < ActiveRecord::Migration | ||
|
||
def change | ||
# Using singluar table names to maintain convention with rest of warehouse | ||
create_table :stock_resource, primary_key: :id_stock_resource_tmp do |t| | ||
|
||
t.datetime :last_updated, null: false, comment: 'Timestamp of last update' | ||
t.datetime :recorded_at, null: false, comment: 'Timestamp of warehouse update' | ||
t.datetime :created, null: false, comment: 'Timestamp of initial registration of stock in LIMS' | ||
t.datetime :deleted_at, null: true, comment: 'Timestamp of initial registration of deletion in parent LIMS. NULL if not deleted.' | ||
|
||
t.column :id_sample_tmp, 'integer unsigned', null: false, comment: 'Sample id, see "sample.id_sample_tmp"' | ||
t.column :id_study_tmp, 'integer unsigned', null: false, comment: 'Sample id, see "study.id_study_tmp"' | ||
t.string :id_lims, limit:10, null:false, comment: 'LIM system identifier' | ||
|
||
t.string :id_stock_resource_lims, limit: 20, null: false, comment: 'Lims specific identifier for the stock' | ||
t.string :stock_resource_uuid, limit: 36, comment: 'Uuid identifier for the stock' | ||
|
||
t.string :labware_type, null: false, comment: 'The type of labware containing the stock. eg. Well, Tube' | ||
|
||
t.string :labware_machine_barcode, null: false, comment: 'The barcode of the containing labware as read by a barcode scanner' | ||
t.string :labware_human_barcode, null: false, comment: 'The barcode of the containing labware in human readable format' | ||
t.string :labware_coordinate, null: true, comment: 'For wells, the coordinate on the containing plate. Null for tubes.' | ||
|
||
t.float :current_volume, null: true, comment: 'The current volume of material in microlitres based on measurements and know usage' | ||
t.float :initial_volume, null: true, comment: 'The result of the initial volume measurement in microlitres conducted on the material' | ||
t.float :concentration, null: true, comment: 'The concentration of material recorded in the lab in nanograms per microlitre' | ||
|
||
t.string :gel_pass, null: true, comment: 'The recorded result for the qel QC assay.' | ||
t.string :pico_pass, null: true, comment: 'The recorded result for the pico green assay. A pass indicates a successful assay, not sufficient material.' | ||
t.integer :snp_count, null: true, comment: 'The number of markers detected in genotyping assays' | ||
t.string :measured_gender, null: true, comment: 'The gender call base on the genotyping assay' | ||
end | ||
end | ||
end |
15 changes: 15 additions & 0 deletions
15
db/migrate/20170412135215_add_foreigin_key_contraints_to_stock_table.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class AddForeiginKeyContraintsToStockTable < ActiveRecord::Migration | ||
|
||
require './lib/foreign_key_constraint' | ||
include ForeignKeyConstraint | ||
|
||
def up | ||
add_constraint :stock_resource, :sample, as: :id_sample_tmp, foreign_key: :id_sample_tmp | ||
add_constraint :stock_resource, :study, as: :id_study_tmp, foreign_key: :id_study_tmp | ||
end | ||
|
||
def down | ||
drop_constraint :stock_resource, :sample, as: :id_sample_tmp, foreign_key: :id_sample_tmp | ||
drop_constraint :stock_resource, :study, as: :id_study_tmp, foreign_key: :id_study_tmp | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
require 'spec_helper' | ||
|
||
describe StockResource do | ||
|
||
let!(:mock_sample) { create(:sample) } | ||
let!(:mock_study) { create(:study) } | ||
|
||
before(:each) do | ||
mock_sample; mock_study | ||
end | ||
|
||
shared_examples_for 'a stock resource' do | ||
|
||
it_behaves_like 'maps JSON fields', { | ||
} | ||
|
||
it_behaves_like 'ignores JSON fields', [ | ||
] | ||
|
||
it_behaves_like 'belongs to',[ | ||
:sample, | ||
:study | ||
], [:samples] | ||
|
||
it_behaves_like 'a nested resource' | ||
end | ||
|
||
context 'for a well' do | ||
# We have a row for the lane, the sample and the control | ||
let(:expected_entries) { 1 } | ||
|
||
it_behaves_like 'a stock resource' | ||
|
||
let(:json) do | ||
{ | ||
"created_at" => "2012-03-11 10:22:42", | ||
"updated_at" => "2012-03-11 10:22:42", | ||
|
||
"samples" => [ | ||
"sample_uuid" => "000000-0000-0000-0000-0000000000", | ||
"study_uuid" => "000000-0000-0000-0000-0000000001" | ||
], | ||
|
||
"stock_resource_id" => "12345", | ||
"stock_resource_uuid" => "000000-0000-0000-0000-0000000002", | ||
|
||
# We don't validate the barcode format, other | ||
# LIMS might use different standards | ||
"labware_machine_barcode" => "1220456987123", | ||
"labware_human_barcode" => "DN456987D", | ||
"labware_coordinate" => "A1", | ||
"labware_type" => "well", | ||
|
||
"current_volume" => 1.23, | ||
"initial_volume" => 4.56, | ||
"concentration" => 23.56, | ||
|
||
"gel_pass" => "Pass", | ||
"pico_pass" => "Pass", | ||
"snp_count" => 2, | ||
"measured_gender" => "Unknown" | ||
|
||
} | ||
end | ||
|
||
context 'when update with identical tag indexes' do | ||
|
||
let(:example_lims) { 'example' } | ||
|
||
let(:updated_json) do | ||
updated_json = json.dup | ||
updated_json['current_volume'] = 1.00 | ||
updated_json['updated_at'] = "2012-03-11 10:22:42" | ||
updated_json | ||
end | ||
|
||
it 'reuses the existing records' do | ||
described_class.create_or_update_from_json(json, example_lims) | ||
original_ids = described_class.pluck(:id_stock_resource_tmp,:id_sample_tmp) | ||
described_class.create_or_update_from_json(updated_json, example_lims) | ||
new_ids = described_class.pluck(:id_stock_resource_tmp,:id_sample_tmp) | ||
expect(new_ids).to eq(original_ids) | ||
end | ||
end | ||
|
||
end | ||
|
||
context 'for a well with SS formatted data' do | ||
# We have a row for the lane, the sample and the control | ||
let(:expected_entries) { 1 } | ||
|
||
it_behaves_like 'a stock resource' | ||
|
||
let(:json) do | ||
{ | ||
"created_at" => "2012-03-11T10:22:42+00:00", | ||
"updated_at" => "2012-03-11T10:22:42+00:00", | ||
|
||
"samples" => [ | ||
"sample_uuid" => "000000-0000-0000-0000-0000000000", | ||
"study_uuid" => "000000-0000-0000-0000-0000000001" | ||
], | ||
|
||
"stock_resource_id" => 12345, | ||
"stock_resource_uuid" => "000000-0000-0000-0000-0000000002", | ||
|
||
# We don't validate the barcode format, other | ||
# LIMS might use different standards | ||
"labware_machine_barcode" => "1220456987123", | ||
"labware_human_barcode" => "DN456987D", | ||
"labware_coordinate" => "A1", | ||
"labware_type" => "well", | ||
|
||
"current_volume" => 1.23, | ||
"initial_volume" => 4.56, | ||
"concentration" => 23.56, | ||
|
||
"gel_pass" => "Pass", | ||
"pico_pass" => "Pass", | ||
"snp_count" => 2, | ||
"measured_gender" => "Unknown" | ||
|
||
} | ||
end | ||
|
||
end | ||
|
||
|
||
context 'for a tube' do | ||
|
||
let(:expected_entries) { 1 } | ||
|
||
let(:json) do | ||
{ | ||
"created_at" => "2012-03-11 10:22:42", | ||
"updated_at" => "2012-03-11 10:22:42", | ||
|
||
"samples" => [ | ||
"sample_uuid" => "000000-0000-0000-0000-0000000000", | ||
"study_uuid" => "000000-0000-0000-0000-0000000001" | ||
], | ||
|
||
"stock_resource_id" => "12345", | ||
"stock_resource_uuid" => "000000-0000-0000-0000-0000000002", | ||
|
||
# We don't validate the barcode format, other | ||
# LIMS might use different standards | ||
"machine_barcode" => "3040456987123", | ||
"human_barcode" => "NT456987D", | ||
"labware_type" => "tube" | ||
|
||
# QC data will not always be present, especially for tubes | ||
# So lets make sure its absence doesn't cause issues | ||
|
||
} | ||
end | ||
|
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters