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

Y24-099 scRNA - tube rack banking sequencescape api #4416

Merged

Conversation

andrewsparkes
Copy link
Member

Closes #sanger/limber#1696

Changes proposed in this pull request

Adds specific tube rack creation v2 api endpoint

@andrewsparkes andrewsparkes changed the base branch from y24-088-tuberacks-epic to develop October 15, 2024 15:04
@andrewsparkes andrewsparkes changed the base branch from develop to y24-088-tuberacks-epic October 15, 2024 15:04
Copy link

codecov bot commented Oct 16, 2024

Codecov Report

Attention: Patch coverage is 99.09910% with 2 lines in your changes missing coverage. Please review.

Project coverage is 86.55%. Comparing base (f107b9f) to head (5bfcdb1).
Report is 3 commits behind head on y24-088-tuberacks-epic.

Files with missing lines Patch % Lines
app/resources/api/v2/tube_rack_resource.rb 83.33% 2 Missing ⚠️
Additional details and impacted files
@@                   Coverage Diff                    @@
##           y24-088-tuberacks-epic    #4416    +/-   ##
========================================================
  Coverage                   86.55%   86.55%            
========================================================
  Files                        1394     1397     +3     
  Lines                       29867    30003   +136     
========================================================
+ Hits                        25851    25969   +118     
- Misses                       4016     4034    +18     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

@andrewsparkes andrewsparkes linked an issue Nov 1, 2024 that may be closed by this pull request
4 tasks
Copy link
Contributor

@KatyTaylor KatyTaylor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments so far. I haven't finished reading it yet, so I might answer my own questions as I go. Hope to finish on Monday! Thanks.

db/schema.rb Show resolved Hide resolved
app/models/specific_tube_rack_creation.rb Show resolved Hide resolved
app/models/specific_tube_rack_creation.rb Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you and Stuart discuss your opinions on whether this is a good pattern for the API to follow?

If so could put a sentence or two under line 5 to explain the pattern.

app/models/specific_tube_rack_creation.rb Show resolved Hide resolved
app/models/specific_tube_rack_creation.rb Outdated Show resolved Hide resolved
self.table_name = 'specific_tube_rack_creation_purposes'
belongs_to :specific_tube_rack_creation
belongs_to :tube_rack_purpose, class_name: 'Purpose'
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where's the link between rack and purpose?
Should it be instead that SpecificTubeRackCreation::ChildTubeRack has a relationship belongs_to :purpose, or just a string with the purpose name or something?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Link between rack and purpose is in the TubeRack model / resource?
This endpoint can make multiple tube racks of different purposes remember.
I copied the pattern from SpecificTubeCreation.
Can discuss.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at this again, I think you are right, there is a problem here.
It should be just the one table, not two.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tried to change it for one table with belongs_to on purpose added but it breaks all the unit tests. I haven't been able to fix it.

app/models/specific_tube_rack_creation.rb Show resolved Hide resolved
Copy link
Contributor

@KatyTaylor KatyTaylor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a lot of work gone into this story!

Lots of comments, sorry. Let's talk them through at some point because I don't want to create a bunch of extra work for you on this one.

else
redirect_existing_barcode(existing_barcode_record, new_tube_rack, tube_rack_barcode)
end
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This (handle_tube_rack_barcode) feels like a core method that should probably be elsewhere - on the tube rack model, or purpose perhaps 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I agree, too much code in this labware creator. can discuss.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KatyTaylor Create refactor story to create central tube rack creation code to be shared between this and sample manifest upload code.

raise StandardError, error_message
end
Barcode.create!(labware: new_tube_rack, barcode: tube_rack_barcode, format: barcode_format)
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that this kind of thing was probably replicated in the sample manifest upload code, and then found this comment -

# TODO: the below foreign barcode checks are duplicated in sanger_tube_id specialised field file - refactor

So looks like there might be 3 places that could do with a refactor!

return if pm.save

raise StandardError, "New metadata for tube rack (key: #{metadata_key}, value: #{tube_rack_barcode}) did not save"
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also feels like a core method for tube rack creation, perhaps should be on the tube rack model.

app/models/specific_tube_rack_creation.rb Show resolved Hide resolved
return if existing_tube_barcode_record.nil?

error_message = "The tube barcode '#{tube_barcode}' is already in use, cannot continue."
raise StandardError, error_message
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this replicating behaviour that would happen already if you tried to insert a tube with a pre-existing barcode?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth having a discussion about error handling for API endpoints in general, as I'm not very clear on what the best way to do all this is. This endpoint has to make multiple tube racks, each with multiple tubes. If anything goes wrong at any point I want the whole lot rolled back and a suitable human friendly error message passed back through the api response to be displayed to the user.
Does raising an explicit StandardError like this trigger the full rollback? And does that error message make it back to Limber and get displayed? Would I get the same result attempting an insert and that failing with a uniqueness error (given barcode is a different table than labwares / receptacles)? Does it still rollback everything and return a clear message to Limber?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we put it on our list to ask Stuart about?

app/resources/api/v2/tube_rack_resource.rb Show resolved Hide resolved
has_many :state_changes, readonly: true
has_one :custom_metadatum_collection, foreign_key_on: :related
has_many :ancestors, readonly: true, polymorphic: true
# NB. no child or descendent associations as tube racks can't have children (tubes have children).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's true that tube racks can't have children?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we discussed this and decided it was the tubes that have children:

  1. parent plate has child tube rack
  2. tube rack has racked tubes (not children)
  3. tubes have child plate

what would the child of a tube rack be?

Copy link
Contributor

@KatyTaylor KatyTaylor Nov 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in the specific scRNA Core case that's true, but not necessarily in the general case.

In the scRNA Core case, the LRC Bank Seq/Spare tube rack doesn't have a direct child because the tubes are taken out, given to a different team for storage in a different labware, and then come back in different groupings.

If it was just a simple plate --> tube rack --> plate within a pipeline, then I could see all the parent-child relationships being from the tube rack - and I think that's what our data model / design is expecting.

@andrewsparkes andrewsparkes merged commit 0fbb091 into y24-088-tuberacks-epic Nov 27, 2024
23 checks passed
@andrewsparkes andrewsparkes deleted the y24-099-tube-rack-banking-sequencescape-api branch November 27, 2024 10:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Y24-099 Tube Rack Banking Sequencescape API
2 participants