-
Notifications
You must be signed in to change notification settings - Fork 34
Y26-125 dual index tags update in mlwh #5745
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
base: develop
Are you sure you want to change the base?
Changes from all commits
8aad520
110d784
d715c30
d3256a3
f52f6d5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,30 +26,36 @@ class DualIndexTagWell | |
| def update(_attributes = {}) | ||
| return unless valid? | ||
|
|
||
| # NB. asset here is a well, and a the well_has_single_aliquot? validation ensures there is only one aliquot | ||
| stock_aliquot = asset.aliquots.first | ||
|
|
||
| # Update all downstream aliquots as well as current aliquot | ||
| matching_aliquots = identify_all_matching_aliquots(stock_aliquot) | ||
| update_all_relevant_aliquots(matching_aliquots, tag, tag2) | ||
| # NB. the asset here is a well, and the well_has_single_aliquot? validation ensures there is only one aliquot | ||
| # NB. we are fetching via row so this is the same aliquot instance so saved_changes? works to detect | ||
| # substitutions | ||
| row.aliquots.first.assign_attributes(tag:, tag2:) | ||
| end | ||
|
|
||
| def link(other_fields) | ||
| self.sf_dual_index_tag_set = other_fields[SequencescapeExcel::SpecialisedField::DualIndexTagSet] | ||
| end | ||
|
|
||
| # From the validation in DualIndexTagSet, we know this tag set is a valid dual index tag set | ||
| # From the validation in DualIndexTagSet, we will know if this tag set is a valid dual index tag set | ||
| # with a visible tag group and visible tag2 group | ||
| def dual_index_tag_set | ||
| @dual_index_tag_set = TagSet.find(sf_dual_index_tag_set.tag_set_id) if sf_dual_index_tag_set&.tag_set_id | ||
| end | ||
|
|
||
| def tag_group_id | ||
| @tag_group_id ||= ::TagGroup.find_by(id: dual_index_tag_set.tag_group_id, visible: true).id | ||
| # defensive guard to avoid NoMethodError being thrown when dual_index_tag_set is nil, caught by validation | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Think the comment states the obvious 😃
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Didn't think it was obvious myself, a validation in a linked specialised field catching it after this code runs. |
||
| # in DualIndexTagSet | ||
| return unless dual_index_tag_set | ||
|
|
||
| @tag_group_id ||= ::TagGroup.find_by(id: dual_index_tag_set.tag_group_id, visible: true)&.id | ||
| end | ||
|
|
||
| def tag2_group_id | ||
| @tag2_group_id ||= ::TagGroup.find_by(id: dual_index_tag_set.tag2_group_id, visible: true).id | ||
| # defensive guard to avoid NoMethodError being thrown when dual_index_tag_set is nil, caught by validation | ||
| # in DualIndexTagSet | ||
| return unless dual_index_tag_set | ||
|
|
||
| @tag2_group_id ||= ::TagGroup.find_by(id: dual_index_tag_set.tag2_group_id, visible: true)&.id | ||
| end | ||
|
|
||
| private | ||
|
|
@@ -82,28 +88,6 @@ def well_has_single_aliquot? | |
| msg = "Expecting well #{asset.map.description} to have a single aliquot, but it has #{asset.aliquots.count}" | ||
| errors.add(:base, msg) | ||
| end | ||
|
|
||
| # Find all aliquots that need updating | ||
| # Aliquots must have a matching sample_id, library_id, tag_id and tag2_id to the given stock_aliquot. | ||
| def identify_all_matching_aliquots(stock_aliquot) | ||
| attributes = { | ||
| sample_id: stock_aliquot.sample_id, | ||
| library_id: stock_aliquot.library_id, | ||
| tag_id: stock_aliquot.tag_id, | ||
| tag2_id: stock_aliquot.tag2_id | ||
| } | ||
|
|
||
| Aliquot.where(attributes).ids | ||
| end | ||
|
|
||
| # Update the tags in all the matching aliquots | ||
| # NB. if active record sees that nothing has changed it will update the record | ||
| def update_all_relevant_aliquots(matching_aliquots, i7_tag, i5_tag) | ||
| Aliquot.where(id: matching_aliquots).find_each do |aq| | ||
| aq.update(tag: i7_tag, tag2: i5_tag) | ||
| aq.save! | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we don't need the
rowpassed through. If you look at the code for the other types of library manifest, they referencealiquotsdirectly (which is delegated toasseton the base class) - so should work to do the same here.Equivalent classes for other manifests:
app/sequencescape_excel/sequencescape_excel/specialised_field/i7.rb>app/sample_manifest_excel/sample_manifest_excel/tags/aliquot_updater.rbapp/sequencescape_excel/sequencescape_excel/specialised_field/tag_index.rbThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
without the row it does not set up the tag substitutions.
different aliquot instances I think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
possibly points to some other flaw in how this is working, but I can't see it.