Skip to content

Commit

Permalink
Merge pull request #1524 from sanger/develop
Browse files Browse the repository at this point in the history
Merge Develop -> Master
  • Loading branch information
BenTopping authored Jan 20, 2025
2 parents 5b82053 + f27c119 commit 42cd36d
Show file tree
Hide file tree
Showing 22 changed files with 608 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .release-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.21.0
7.22.0
7 changes: 4 additions & 3 deletions app/exchanges/run_csv/pacbio_sample_sheet.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# A class spefically for SMRT-Link v13 Sample Sheets, based on the PacbioSampleSheet class
# A class specifically for SMRT-Link v13 Sample Sheets, based on the PacbioSampleSheet class
# See https://www.pacb.com/wp-content/uploads/SMRT-Link-User-Guide-v13.1.pdf (page 31) for details.

module RunCsv
Expand Down Expand Up @@ -49,9 +49,10 @@ def generate_smrt_cell_settings(well) # rubocop:disable Metrics/MethodLength
'Indexes' => well.barcode_set, # 244d96c6-f3b2-4997-5ae3-23ed33ab925f
'Sample is indexed' => well.tagged?, # Set to True to Multiplex
'Bio Sample Name' => well.tagged? ? nil : well.bio_sample_name,
'Use Adaptive Loading' => false, # this will likely be a well default in future
'Use Adaptive Loading' => well.use_adaptive_loading,
'Consensus Mode' => 'molecule', # (default to molecule do we need a custom field)
'Same Barcodes on Both Ends of Sequence' => well.same_barcodes_on_both_ends_of_sequence
'Same Barcodes on Both Ends of Sequence' => well.same_barcodes_on_both_ends_of_sequence,
'Full Resolution Base Qual' => well.full_resolution_base_qual
}
end

Expand Down
31 changes: 31 additions & 0 deletions app/exchanges/run_csv/pacbio_sample_sheet_v25.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

# A class specifically for SMRT-Link v25 Sample Sheets, based on the PacbioSampleSheet class
# See https://www.pacb.com/wp-content/uploads/SMRT-Link-User-Guide-v25.1.pdf (page 28) for details.

module RunCsv
# RunCsv::PacbioSampleSheet
class PacbioSampleSheetV25 < PacbioSampleSheet
# Generate a hash of settings for a single cell
# Overrides the method in the parent class
# Only difference is removal of 'Polymerase Kit' key
def generate_smrt_cell_settings(well) # rubocop:disable Metrics/MethodLength
{
'Well Name' => well.used_aliquots.first.source.tube.barcode, # TRAC-2-7242
'Library Type' => well.library_type, # Standard
'Movie Acquisition Time (hours)' => well.movie_acquisition_time, # 24
'Insert Size (bp)' => well.insert_size, # 500
'Assign Data To Project' => 1, # (maybe we need to assign a run a project in traction)?
'Library Concentration (pM)' => well.library_concentration, # 250
'Include Base Kinetics' => well.include_base_kinetics,
'Indexes' => well.barcode_set, # 244d96c6-f3b2-4997-5ae3-23ed33ab925f
'Sample is indexed' => well.tagged?, # Set to True to Multiplex
'Bio Sample Name' => well.tagged? ? nil : well.bio_sample_name,
'Use Adaptive Loading' => well.use_adaptive_loading,
'Consensus Mode' => 'molecule', # (default to molecule do we need a custom field)
'Same Barcodes on Both Ends of Sequence' => well.same_barcodes_on_both_ends_of_sequence,
'Full Resolution Base Qual' => well.full_resolution_base_qual
}
end
end
end
10 changes: 10 additions & 0 deletions app/models/pacbio/run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@ def used_aliquots_lib_source_in_pool(pools)
end
end

# @return [Boolean] true if all wells have adaptive loading enabled
def adaptive_loading
wells.all? { |w| w.use_adaptive_loading == 'True' }
end

# @return [Array<String>] the barcodes of the sequencing kits
def sequencing_kit_box_barcodes
plates.map { |p| "Plate #{p.plate_number}: #{p.sequencing_kit_box_barcode}" }
end

private

# We now have SMRT Link versioning
Expand Down
8 changes: 8 additions & 0 deletions app/resources/v1/pacbio/library_batch_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class LibraryBatchResource < JSONAPI::Resource
# @!attribute [w] libraries_attributes
# @return [Array] the attributes of the libraries
attributes :created_at, :libraries_attributes
after_create :publish_volume_tracking_messages

has_many :libraries, always_include_optional_linkage_data: true

Expand All @@ -69,6 +70,13 @@ def libraries_attributes=(libraries_attributes_parameters)
def fetchable_fields
super - [:libraries_attributes]
end

def publish_volume_tracking_messages
@model.libraries.each do |library|
Emq::Publisher.publish([library.primary_aliquot, *library.used_aliquots],
Pipelines.pacbio, 'volume_tracking')
end
end
end
end
end
60 changes: 46 additions & 14 deletions app/resources/v1/pacbio/run_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,39 @@

module V1
module Pacbio
# @todo This documentation does not yet include a detailed description of what this resource represents.
# @todo This documentation does not yet include detailed descriptions for relationships, attributes and filters.
# @todo This documentation does not yet include any example usage of the API via cURL or similar.
#
# @note Access this resource via the `/v1/pacbio/runs/` endpoint.
#
# Provides a JSON:API representation of {Pacbio::Run}.
#
# For more information about JSON:API see the [JSON:API Specifications](https://jsonapi.org/format/)
# or look at the [JSONAPI::Resources](http://jsonapi-resources.com/) package
# for the service implementation of the JSON:API standard.
# This resource represents a Pacbio Run and can return all runs, a single run or multiple
# runs along with their relationships.
# It can also create and update runs and their nested relationships
# via the plates_attributes parameter. These actions also publish run messages to the warehouse.
#
# ## Filters:
#
# * name
# * state
#
# ## Primary relationships:
#
# * plates {V1::Pacbio::PlateResource}
# * smrt_link_version {V1::Pacbio::SmrtLinkVersionResource}
#
# ## Relationship trees:
#
# * plates.wells.used_aliquots
# * smrt_link_version.smrt_link_option_versions
#
# @example
# curl -X GET http://localhost:3000/v1/pacbio/runs/1
# curl -X GET http://localhost:3000/v1/pacbio/runs/
# curl -X GET http://localhost:3000/v1/pacbio/runs/1?include=plates.wells.used_aliquots,smrt_link_version
#
# http://localhost:3000/v1/pacbio/runs?filter[name]=TRACTION-RUN-1
# http://localhost:3000/v1/pacbio/runs?filter[state]=pending
#
class RunResource < JSONAPI::Resource
model_name 'Pacbio::Run'

Expand All @@ -32,9 +54,14 @@ class RunResource < JSONAPI::Resource
# @return [Integer] the ID of the PacBio SMRT Link version
# @!attribute [rw] plates_attributes
# @return [Array<Hash>] the attributes of the plates
# @!attribute [r] adaptive_loading
# @return [Boolean] whether adaptive loading is used
# @!attribute [r] sequencing_kit_box_barcodes
# @return [Array<String>] the barcodes of the sequencing kits
attributes :name, :dna_control_complex_box_barcode,
:system_name, :created_at, :state, :comments,
:pacbio_smrt_link_version_id, :plates_attributes
:pacbio_smrt_link_version_id, :plates_attributes,
:adaptive_loading, :sequencing_kit_box_barcodes

has_many :plates, foreign_key_on: :related, foreign_key: 'pacbio_run_id',
class_name: 'Runs::Plate'
Expand All @@ -45,13 +72,10 @@ class RunResource < JSONAPI::Resource

paginator :paged

#
# # A pain. It means we would need to turn this into a method to beat the cop.
# rubocop:disable Layout/LineLength
PERMITTED_WELL_PARAMETERS = %i[id
row column
comment].concat(Rails.configuration.pacbio_smrt_link_versions.options.keys).freeze
# rubocop:enable Layout/LineLength
# Well parameters that are permitted for the plates_attributes
PERMITTED_WELL_PARAMETERS = %i[
id row column comment
].concat(Rails.configuration.pacbio_smrt_link_versions.options.keys).freeze

after_save :publish_messages

Expand Down Expand Up @@ -86,6 +110,14 @@ def publish_messages
'volume_tracking')
end

def self.creatable_fields(context)
super - %i[adaptive_loading sequencing_kit_box_barcodes]
end

def self.updatable_fields(context)
super - %i[adaptive_loading sequencing_kit_box_barcodes]
end

private

def plates_attributes=(plates_parameters) # rubocop:disable Metrics/MethodLength
Expand Down
4 changes: 4 additions & 0 deletions app/resources/v1/pacbio/runs/well_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ class WellResource < JSONAPI::Resource
# @return [String] the polymerase kit
# @!attribute [rw] library_type
# @return [String] the library type
# @!attribute [rw] use_adaptive_loading
# @return [Boolean] whether to use adaptive loading
# @!attribute [rw] full_resolution_base_qual
# @return [Boolean] whether to apply full resolution base qual
attributes :row, :column, :comment, :pacbio_plate_id, :position,
*Rails.configuration.pacbio_smrt_link_versions.options.keys

Expand Down
26 changes: 18 additions & 8 deletions app/resources/v1/pacbio/smrt_link_version_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,28 @@

module V1
module Pacbio
# @todo This documentation does not yet include a detailed description of what this resource represents.
# @todo This documentation does not yet include detailed descriptions for relationships, attributes and filters.
# @todo This documentation does not yet include any example usage of the API via cURL or similar.
# The JSON:API representation of a {Pacbio::SmrtLinkVersion}.
# For more information about JSON:API see the [JSON:API Specifications](https://jsonapi.org/format/)
# or look at the [JSONAPI::Resources](http://jsonapi-resources.com/) package
# for the service implementation of the JSON:API standard.
#
# @note Access this resource via the `/v1/pacbio/smrt_link_versions/` endpoint.
#
# Provides a JSON:API representation of {Pacbio::SmrtLinkVersion}. Returns the SMRT Link
# Versions.
# This resource represents a Pacbio SmrtLinkVersion and can return all smrt_link_versions
# or a single smrt_link_version
#
# This resource has no filters.
#
# ## Primary relationships:
#
# * smrt_link_option_versions {V1::Pacbio::SmrtLinkOptionVersionResource}
#
# @example
# curl -X GET http://localhost:3000/v1/pacbio/smrt_link_versions/1
# curl -X GET http://localhost:3000/v1/pacbio/smrt_link_versions
#
# https://localhost:3000/v1/pacbio/v1/smrt_link_versions/1?include=smrt_link_option_versions
#
# For more information about JSON:API see the [JSON:API Specifications](https://jsonapi.org/format/)
# or look at the [JSONAPI::Resources](http://jsonapi-resources.com/) package
# for the service implementation of the JSON:API standard.
class SmrtLinkVersionResource < JSONAPI::Resource
model_name 'Pacbio::SmrtLinkVersion'

Expand Down
31 changes: 25 additions & 6 deletions app/resources/v1/pacbio/well_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,36 @@

module V1
module Pacbio
# @todo This documentation does not yet include a detailed description of what this resource represents.
# @todo This documentation does not yet include detailed descriptions for relationships, attributes and filters.
# @todo This documentation does not yet include any example usage of the API via cURL or similar.
# Provides a JSON:API representation of {Pacbio::Well}.
#
# @note Access this resource via the `/v1/pacbio/wells/` endpoint.
#
# Provides a JSON:API representation of {Well}. Returns the wells for a Pacbio plate.
# This resource is primarily accessed through {V1::Pacbio::RunResource}
# and {V1::Pacbio::PlateResource}.
# Wells are primarily created via a Run and Plate.
#
# For more information about JSON:API see the [JSON:API Specifications](https://jsonapi.org/format/)
# or look at the [JSONAPI::Resources](http://jsonapi-resources.com/) package
# for the service implementation of the JSON:API standard.
#
# This resource represents a Pacbio Well and can return all wells or a single well
#
# This resource has no filters.
#
# ## Primary relationships:
#
# * materials {V1::Pacbio::MaterialResource}
# * requests {V1::Pacbio::RequestResource}
# * plate {V1::Pacbio::PlateResource}
#
# @note Access this resource via the `/v1/pacbio/wells/` endpoint.
#
# @example
# curl -X GET http://localhost:3000/v1/pacbio/wells/1
# curl -X GET http://localhost:3000/v1/pacbio/wells
# curl -X GET http://localhost:3000/v1/pacbio/runs/1/wells
# curl -X GET http://localhost:3000/v1/pacbio/runs/1/wells/1
#
# https://localhost:3000/v1/pacbio/v1/wells/1?include=plate,materials
#
class WellResource < JSONAPI::Resource
model_name '::Well'

Expand Down
22 changes: 17 additions & 5 deletions app/validators/smrt_link_options_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@ def validate(record)
# options is a hash e.g. { greater_than_equal_to: 1 }
# see the validator docs in ActiveModel for the standard ones
smrt_link_option.validations.each do |key, options|
# We need to get the constant for the validator
# @example
# key = required
# validator => ActiveModel::Validations::RequiredValidator
validator = "ActiveModel::Validations::#{key.capitalize}Validator".constantize
validator = validator_by_prefix(key)

# We then need to create a new instance of the validator
# and pass the options along with the attribute name which is the key
Expand All @@ -53,4 +49,20 @@ def validate(record)
end
end
end

private

# Get the validator class by prefix
# @param prefix [String] the prefix of the validator
# @return [Class] the class of the validator
def validator_by_prefix(prefix)
validator_class_name = "#{prefix.camelize}Validator"
# Check if there is a custom validator first
if Object.const_defined?(validator_class_name)
validator_class_name.constantize
else
# If no custom validator then use an active model one
"ActiveModel::Validations::#{validator_class_name}".constantize
end
end
end
11 changes: 11 additions & 0 deletions app/validators/use_adaptive_loading_validator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

# Validator for ensuring use_adaptive_loading is consistent across all wells
class UseAdaptiveLoadingValidator < ActiveModel::Validator
# @param [ActiveRecord::Base] record
def validate(record)
return if record.use_adaptive_loading == record.run.wells.first.use_adaptive_loading

record.errors.add(:base, "well #{record.position} has a differing 'Use Adaptive Loading' value")
end
end
37 changes: 37 additions & 0 deletions config/pacbio_smrt_link_versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ default: &default
name: v13_1_revio
active: true
default: false
v25_1_revio:
name: v25_1_revio
active: true
default: false
options:
ccs_analysis_output:
key: ccs_analysis_output
Expand Down Expand Up @@ -218,6 +222,7 @@ default: &default
- v12_revio
- v13_revio
- v13_1_revio
- v25_1_revio
include_base_kinetics:
key: include_base_kinetics
label: "Include Base Kinetics"
Expand All @@ -232,6 +237,7 @@ default: &default
- v12_revio
- v13_revio
- v13_1_revio
- v25_1_revio
library_concentration:
key: library_concentration
label: "Library Concentration (pM)"
Expand All @@ -243,6 +249,7 @@ default: &default
- v12_revio
- v13_revio
- v13_1_revio
- v25_1_revio
polymerase_kit:
key: polymerase_kit
label: "Polymerase Kit"
Expand All @@ -268,6 +275,36 @@ default: &default
- v12_revio
- v13_revio
- v13_1_revio
- v25_1_revio
use_adaptive_loading:
key: use_adaptive_loading
label: "Use Adaptive Loading"
default_value: "False"
validations:
presence: {}
inclusion:
in: *true_false
use_adaptive_loading: {}
data_type: list
select_options: *select_true_false
versions:
- v13_revio
- v13_1_revio
- v25_1_revio
full_resolution_base_qual:
key: full_resolution_base_qual
label: "Full Resolution Base Qual"
default_value: "False"
validations:
presence: {}
inclusion:
in: *true_false
data_type: list
select_options: *select_true_false
versions:
- v13_revio
- v13_1_revio
- v25_1_revio

development: *default
test: *default
Expand Down
Loading

0 comments on commit 42cd36d

Please sign in to comment.