Skip to content

Commit

Permalink
Merge branch 'develop' into 4133-y24-120-bug-taken-link-error-when-cr…
Browse files Browse the repository at this point in the history
…eating-sequencing-batches
  • Loading branch information
yoldas committed Sep 25, 2024
2 parents ca87241 + c767ccf commit 068d0b9
Show file tree
Hide file tree
Showing 33 changed files with 387 additions and 52 deletions.
1 change: 0 additions & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,6 @@ RSpec/ExampleWording:
- 'spec/heron/factories/sample_spec.rb'
- 'spec/heron/factories/tube_rack_spec.rb'
- 'spec/lib/accession/study_spec.rb'
- 'spec/models/parsers/cardinal_pbmc_count_parser_spec.rb'
- 'spec/models/plate/quad_creator_spec.rb'
- 'spec/models/qc_result/qc_result_factory_spec.rb'
- 'spec/models/qcable_creator_spec.rb'
Expand Down
12 changes: 12 additions & 0 deletions app/controllers/api/v2/request_metadata_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

module Api
module V2
# Provides a JSON API controller for RequestMetadata
# See: http://jsonapi-resources.com/ for JSONAPI::Resource documentation
class RequestMetadataController < JSONAPI::ResourceController
# By default JSONAPI::ResourceController provides most the standard
# behaviour, and in many cases this file may be left empty.
end
end
end
2 changes: 1 addition & 1 deletion app/models/parsers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

module Parsers
ENCODINGS = %w[Windows-1252 iso-8859-1 utf-8 utf-16].freeze
PARSERS = [QuantParser, BioanalysisCsvParser, PlateReaderParser, CardinalPbmcCountParser].freeze
PARSERS = [QuantParser, BioanalysisCsvParser, PlateReaderParser, PbmcCountParser].freeze

def self.parser_for(filename, content_type, content)
return nil unless filename.downcase.end_with?('.csv') || content_type == 'text/csv'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true
module Parsers
# A parser for the cardinal pipeline qc file
class CardinalPbmcCountParser
# A parser for the cardinal and scrna pipeline qc files
class PbmcCountParser
class_attribute :assay_type, :assay_version

HEADERS = [
Expand All @@ -20,7 +20,7 @@ class CardinalPbmcCountParser
'Errors:'
].freeze

self.assay_type = 'Cardinal_PBMC_Count'
self.assay_type = 'PBMC_Count'
self.assay_version = 'v1.0'

def self.parses?(content)
Expand All @@ -38,8 +38,9 @@ def rows
end

# 0 - well name
# 2 - cell count
# 2 - live cell count
# 4 - viability
# 9 - total cell count
def qc_data
@qc_data ||=
{}.tap do |qc_data|
Expand Down Expand Up @@ -67,6 +68,7 @@ def each_well_and_parameters(&block)
def qc_metrics_hash(row)
{}.tap do |hash|
hash[:live_cell_count] = Unit.new(row[2], 'cells')
hash[:total_cell_count] = Unit.new(row[9], 'cells')
viability = row[4]
hash[:viability] = Unit.new(viability) unless viability == 'NaN'
end
Expand Down
9 changes: 9 additions & 0 deletions app/models/pbmc_pooling_customer_request.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

# A class for customer requests that need the extra metadata fields used for PBMC pooling calculations
class PbmcPoolingCustomerRequest < CustomerRequest
has_metadata as: Request do
custom_attribute(:number_of_samples_per_pool, integer: true, required: false, default: nil)
custom_attribute(:cells_per_chip_well, integer: true, required: false, default: nil)
end
end
48 changes: 48 additions & 0 deletions app/resources/api/v2/request_metadata_resource.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# frozen_string_literal: true

module Api
module V2
# @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 `/api/v2/requests_metadata/` endpoint.
#
# Provides a JSON:API representation of {Request::Metadata}.
#
# 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 Sequencescape's implementation
# of the JSON:API standard.
class RequestMetadataResource < BaseResource
# NB. request_metadata has been added to config/initializers/inflections.rb to make this class name
# work otherwise it expects RequestMetadatumResource

# Sets add_model_hint true by default, this allows updates from Limber, otherwise get a
# 500 error as it looks for resource Api::V2::MetadatumResource
model_name 'Request::Metadata'

# Associations:
has_one :request

###
# Attributes
###

# @!attribute [r] number_of_samples_per_pool
# @return [Int] the number_of_samples_per_pool.
attribute :number_of_samples_per_pool, readonly: true

# @!attribute [r] cells_per_chip_well
# @return [Int] the cells_per_chip_well.
attribute :cells_per_chip_well, readonly: true

# Filters

# Custom methods
# These shouldn't be used for business logic, and a more about
# I/O and isolating implementation details.

# Class method overrides
end
end
end
1 change: 1 addition & 0 deletions app/resources/api/v2/request_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class RequestResource < BaseResource
has_one :primer_panel
has_one :pre_capture_pool
has_many :poly_metadata, as: :metadatable, class_name: 'PolyMetadatum'
has_one :request_metadata, class_name: 'RequestMetadata', foreign_key_on: :related

# Attributes
attribute :uuid, readonly: true
Expand Down
3 changes: 3 additions & 0 deletions app/resources/api/v2/sample_metadata_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ module V2
# or look at the [JSONAPI::Resources](http://jsonapi-resources.com/) package for Sequencescape's implementation
# of the JSON:API standard.
class SampleMetadataResource < BaseResource
# NB. sample_metadata has been added to config/initializers/inflections.rb to make this class name
# work otherwise it expects SampleMetadatumResource

# Set add_model_hint true to allow updates from Limber, otherwise get a
# 500 error as it looks for resource Api::V2::MetadatumResource
model_name 'Sample::Metadata', add_model_hint: true
Expand Down
31 changes: 31 additions & 0 deletions app/uat_actions/uat_actions/tube_submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,26 @@ class UatActions::TubeSubmission < UatActions
include_blank: 'Using default library type...'
}

form_field :number_of_samples_per_pool,
:number_field,
label: 'Number of samples per pool',
help:
'Optional field to set the number_of_samples_per_pool field on the ' \
'submission request. Leave blank if not required.',
options: {
minimum: 0
}

form_field :cells_per_chip_well,
:number_field,
label: 'Cells per Chip Well',
help:
'Optional field to set the cells_per_chip_well field on the ' \
'submission request. Leave blank if not required.',
options: {
minimum: 0
}

validates :submission_template, presence: { message: 'could not be found' }

# Returns a default copy of the UatAction which will be used to fill in the form
Expand Down Expand Up @@ -74,12 +94,21 @@ def perform
# Fills the report with the information from the submission
#
# @return [Void]
# rubocop:disable Metrics/AbcSize
def fill_report(order)
report['tube_barcodes'] = assets.map(&:human_barcode)
report['submission_id'] = order.submission.id
report['library_type'] = order.request_options[:library_type] if order.request_options[:library_type].present?
report['number_of_samples_per_pool'] = order.request_options[:number_of_samples_per_pool] if order.request_options[
:number_of_samples_per_pool
].present?
report['cells_per_chip_well'] = order.request_options[:cells_per_chip_well] if order.request_options[
:cells_per_chip_well
].present?
end

# rubocop:enable Metrics/AbcSize

# Returns the submisssion template to use for the submission
#
# @return [SubmissionTemplate] The submission template to use
Expand Down Expand Up @@ -131,6 +160,8 @@ def default_request_options
def custom_request_options
options = {}
options[:library_type] = library_type_name if library_type_name.present?
options[:number_of_samples_per_pool] = number_of_samples_per_pool.presence
options[:cells_per_chip_well] = cells_per_chip_well.presence
options
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ limber_scrna_core_cdna_prep_gem_x_5p:
name: scRNA Core cDNA Prep GEM-X 5p
asset_type: SampleTube
order: 1
request_class_name: CustomerRequest
request_class_name: PbmcPoolingCustomerRequest
for_multiplexing: false
billable: true
product_line_name: Short Read
Expand Down
4 changes: 3 additions & 1 deletion config/initializers/inflections.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
# inflect.uncountable %w( fish sheep )
# end

ActiveSupport::Inflector.inflections(:en) { |inflect| inflect.uncountable %w[health sample_metadata labware] }
ActiveSupport::Inflector.inflections(:en) do |inflect|
inflect.uncountable %w[health sample_metadata request_metadata labware]
end

# These inflection rules are supported but not enabled by default:
# ActiveSupport::Inflector.inflections(:en) do |inflect|
Expand Down
6 changes: 6 additions & 0 deletions config/locales/metadata/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ en:
requested_flowcell_type:
label: Flowcell type

number_of_samples_per_pool:
label: Number of samples per pool

cells_per_chip_well:
label: Cells per chip well

library_creation_request:
<<: *REQUEST
sequencing_request:
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
jsonapi_resources :qcables
jsonapi_resources :racked_tubes
jsonapi_resources :receptacles
jsonapi_resources :request_metadata
jsonapi_resources :request_types
jsonapi_resources :requests
jsonapi_resources :samples
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true
class AddscRnaFieldsToRequestMetadata < ActiveRecord::Migration[6.1]
def change
add_column :request_metadata, :number_of_samples_per_pool, :integer, null: true
add_column :request_metadata, :cells_per_chip_well, :integer, null: true
end
end
4 changes: 3 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2024_09_12_000109) do
ActiveRecord::Schema.define(version: 2024_09_17_133813) do

create_table "aliquot_indices", id: :integer, charset: "utf8mb4", collation: "utf8mb4_unicode_ci", options: "ENGINE=InnoDB ROW_FORMAT=DYNAMIC", force: :cascade do |t|
t.integer "aliquot_id", null: false
Expand Down Expand Up @@ -1175,6 +1175,8 @@
t.string "data_type"
t.integer "primer_panel_id"
t.string "requested_flowcell_type"
t.integer "number_of_samples_per_pool"
t.integer "cells_per_chip_well"
t.index ["request_id"], name: "index_request_metadata_on_request_id"
end

Expand Down
42 changes: 42 additions & 0 deletions lib/tasks/populate_number_of_samples_per_pool.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# frozen_string_literal: true

# Run the rake task with the following command:
# bundle exec rake number_of_samples_per_pool:populate[20,1]
# The rake task will populate the number of samples per pool column in the request_metadata table
# for a given submission ID.
namespace :number_of_samples_per_pool do
desc 'Populate number of samples per pool column in request_metadata table for a given submission ID'

task :populate, %i[samples_per_pool submission_id] => :environment do |_, args|
args.with_defaults(samples_per_pool: nil, submission_id: nil)

raise StandardError, 'Number of samples per pool is missing' if args[:samples_per_pool].nil?
raise StandardError, 'Submission ID is missing' if args[:submission_id].nil?

puts "Populating number of samples per pool column with #{args[:samples_per_pool]}
in request_metadata table for submission: #{args[:submission_id]}..."

ActiveRecord::Base.transaction do
saved_count = 0
Request::Metadata
.joins(:request)
.where(requests: { submission_id: args[:submission_id] })
.find_each(batch_size: 50) do |request_metadata|
puts "Processing request_metadata #{request_metadata.id}..."
saved_count = process_request_metadata(request_metadata, saved_count, args[:samples_per_pool])
end
end
end

def process_request_metadata(request_metadata, saved_count, samples_per_pool)
request_metadata.number_of_samples_per_pool = samples_per_pool
begin
request_metadata.save!
saved_count += 1
rescue ActiveRecord::ActiveRecordError, StandardError => e
puts "Error processing request_metadata #{request_metadata.id}: #{e.message}"
raise e
end
saved_count
end
end
2 changes: 1 addition & 1 deletion spec/bulk_submission_excel/download_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
let(:columns) { configuration.columns.all.dup }
let(:ranges) { configuration.ranges.dup }
let(:assets) { create(:plate_with_untagged_wells).wells }
let(:submission_template) { create :libray_and_sequencing_template }
let(:submission_template) { create :library_and_sequencing_template }

after { File.delete(test_file) if File.exist?(test_file) }

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions spec/factories/request_type_factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
request_class { CustomerRequest }
end

factory :pbmc_pooling_customer_request_type do
request_class { PbmcPoolingCustomerRequest }
end

factory :cherrypick_request_type do
request_class { CherrypickRequest }
asset_type { 'Well' }
Expand Down
10 changes: 7 additions & 3 deletions spec/factories/submission_factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,21 @@
transient { request_types { [create(:library_request_type)] } }
end

factory :libray_and_sequencing_template do
factory :library_and_sequencing_template do
transient { request_types { [create(:library_request_type), create(:sequencing_request_type)] } }
end

factory :heron_libray_and_sequencing_template do
factory :heron_library_and_sequencing_template do
transient { request_types { [create(:heron_request_type), create(:sequencing_request_type)] } }
end

factory :isc_libray_and_sequencing_template do
factory :isc_library_and_sequencing_template do
transient { request_types { [create(:isc_library_request_type), create(:sequencing_request_type)] } }
end

factory :pbmc_pooling_submission_template do
transient { request_types { [create(:pbmc_pooling_customer_request_type)] } }
end
end

factory :order do
Expand Down
6 changes: 3 additions & 3 deletions spec/features/generate_a_bulk_submission_template_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# We only use two wells of out partial plate in our submission. However we are generating 13
# to ensure we are only using the specified well. The other two will be ignored.
let!(:partial_plate) { create(:plate_with_untagged_wells, well_count: 13) }
let!(:submission_template) { create :libray_and_sequencing_template }
let!(:submission_template) { create :library_and_sequencing_template }

let(:iso_date) { Time.current.utc.strftime('%Y%m%d') }
let(:filename) { "#{plate.human_barcode}_to_#{partial_plate.human_barcode}_#{iso_date}_#{user.login}.xlsx" }
Expand Down Expand Up @@ -37,7 +37,7 @@
end

context 'with a primer panel submission' do
let!(:submission_template) { create :heron_libray_and_sequencing_template }
let!(:submission_template) { create :heron_library_and_sequencing_template }
let!(:primer_panel) { create :primer_panel }

it 'populates the primer panel column' do
Expand All @@ -58,7 +58,7 @@
end

context 'with a bait_library submission' do
let!(:submission_template) { create :isc_libray_and_sequencing_template }
let!(:submission_template) { create :isc_library_and_sequencing_template }
let!(:bait_library) { create :bait_library }

it 'populates the primer panel column' do
Expand Down
Loading

0 comments on commit 068d0b9

Please sign in to comment.