Skip to content

Extend 'under-represented wells' feature to other pipelines#5769

Open
sabrine33 wants to merge 5 commits into
developfrom
Y26-090
Open

Extend 'under-represented wells' feature to other pipelines#5769
sabrine33 wants to merge 5 commits into
developfrom
Y26-090

Conversation

@sabrine33
Copy link
Copy Markdown
Contributor

@sabrine33 sabrine33 commented May 12, 2026

  • update the logic behind construct under_rep comments to include all submission types.
  • also update the logic behind comparing aliquots
  • Tested the fix on training on the batches with wrong data (explained here) and it returned the expected/right values.

Closes #

Changes proposed in this pull request

Instructions for Reviewers

[All PRs] - Confirm PR template filled
[Feature Branches] - Review code
[Production Merges to main]
    - Check story numbers included
    - Check for debug code
    - Check version

sabrine33 added 2 commits May 12, 2026 09:28
…ubmission types.

also update the logic behind comparing aliquots
@sabrine33 sabrine33 linked an issue May 12, 2026 that may be closed by this pull request
2 tasks
@sabrine33 sabrine33 changed the title update the logic behind construct under_rep comments to include all s… Extend 'under-represented wells' feature to other pipelines May 12, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.29%. Comparing base (18aae87) to head (0c9f815).
⚠️ Report is 33 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #5769      +/-   ##
===========================================
- Coverage    87.36%   87.29%   -0.07%     
===========================================
  Files         1477     1477              
  Lines        33526    33535       +9     
  Branches      3550     3552       +2     
===========================================
- Hits         29290    29275      -15     
- Misses        4215     4239      +24     
  Partials        21       21              
Flag Coverage Δ
javascript 50.00% <ø> (ø)
ruby 87.31% <100.00%> (-0.08%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Member

@andrewsparkes andrewsparkes left a comment

Choose a reason for hiding this comment

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

Looks good. Clear comments, thorough tests, thanks.

Copy link
Copy Markdown
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.

A few things to consider.

Would be good to test it on at least one plate from each of the mentioned pipelines.

def under_represented_well_comments
request_with_under_represented_wells.flat_map do |request|
build_comments_for_request(request)
requests.flat_map do |batch_request|
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
requests.flat_map do |batch_request|
requests.flat_map do |sequencing_request|

Think it's confusing to call this variable batch_request since that there is actually a different model / table called batch_request, and this is a request.
(Also applicable to naming in a couple of other methods).

Copy link
Copy Markdown
Contributor Author

@sabrine33 sabrine33 May 13, 2026

Choose a reason for hiding this comment

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

@KatyTaylor - they are actually batch_requests (which can be/usually are sequencing requests). As we are reading from the model Batch:

has_many :requests, -> { distinct }, through: :batch_requests, inverse_of: :batch

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Batch.last.requests.first.class
=> HiSeqSequencingRequest (a type of Request)

Batch.last.batch_requests.first.class
=> BatchRequest (not a type of Request - a join table)

Comment thread app/models/under_rep_well_comments_to_broadcast.rb Outdated
def under_rep_requests_for_lane(lane)
lane.ancestors.grep(Plate)
.flat_map(&:wells)
.flat_map(&:requests)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Above line will return duplicate Requests, as multiple Plates in a pipeline point to the same Request. Might also get some nils, as some Plates (e.g. first ones in a Pipeline, or ones that don't require Requests) will not point to a Request. Could do a .uniq.compact

# @param batch_request [Request] the sequencing request whose position is used in the comment
# @return [Array<UnderRepWellComment>] comments built for the given lane
def build_comments_for_lane(lane, batch_request)
under_rep_requests_for_lane(lane).flat_map do |library_request|
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could mention in the comment that we are assuming it's a library_request as that is the known use case. The way it's retrieved does not enforce it.

request.target_asset.aliquots.filter_map do |aliquot|
lane = request.asset.descendants.last
next unless aliquot_matches_lane?(lane, aliquot)
# @param library_request [Request] the library request whose target_asset well holds the aliquots
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is a limitation in the original design. Since we are storing the polymetadata on request, not well, it only works for plates that have a request 'finishing' in them. If you try to mark a well on an 'intermediate' plate as under-represented, this will assume that it came from a different plate. Think we need to state this explicitly somewhere and maybe code in some guards against it.


UnderRepWellComment.new(
position: lane.source_request.position,
position: batch_request.position,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this is the Request, not the Batch Request, so you should pass through the Batch Request instead to get the position.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There are actually batch requests type, that is why we can the read the position

There are actually batch requests type, that is why we can the read the position

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

position can be accessed directly from the sequencing request as it's joined to batch request,
batch.requests.first.position or batch.request.first.batch_request.position

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

OK I hadn't noticed that Request delegates position to BatchRequest in app/models/batch/request_behaviour.rb, so that's how it works 👍

Just some variable naming to make a bit clearer then.

Comment thread app/models/under_rep_well_comments_to_broadcast.rb Outdated
def aliquot_matches_lane?(lane, aliquot)
lane.aliquots.any? { |a| a.aliquot_index_value == aliquot.tag.map_id }
# @return [Aliquot, nil] the matching lane aliquot, or nil if no match is found
def find_matching_lane_aliquot(lane, aliquot)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could use the equivalent? method on Aliquot. There's also a matches? method, but it allows the upstream aliquot to be untagged, which is less strict.

Co-authored-by: KatyTaylor <kt17@sanger.ac.uk>
@sabrine33
Copy link
Copy Markdown
Contributor Author

A few things to consider.

Would be good to test it on at least one plate from each of the mentioned pipelines.

I tested on the RNA pipeline but also with different scenarios

Co-authored-by: KatyTaylor <kt17@sanger.ac.uk>
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.

Y26-090 - Extend 'under-represented wells' feature to other pipelines

4 participants