Class: UatActions::TubeSubmission

Inherits:
UatActions show all
Defined in:
app/uat_actions/uat_actions/tube_submission.rb

Overview

This UAT Action will generates a basic submission for tubes. Initially, it has been designed for generating scRNA Core Donor Pooling and cDNA Prep submissions on LRC Bank Seq/Spare tubes. rubocop:disable Metrics/ClassLength

Constant Summary collapse

ERROR_SUBMISSION_TEMPLATE_DOES_NOT_EXIST =
"Submission template '%s' does not exist."
ERROR_TUBES_DO_NOT_EXIST =
'Tubes with barcodes do not exist: %s'
ERROR_LIBRARY_TYPE_DOES_NOT_EXIST =
"Library type '%s' does not exist."
SCRNA_CORE_CDNA_PREP_GEM_X_5P =
'Limber-Htp - scRNA Core cDNA Prep GEM-X 5p'

Constants inherited from UatActions

CATEGORY_LIST

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from UatActions

all, category, find, form_field, form_fields, grouped_and_sorted_uat_actions, id, inherited, permitted, #report, #save, to_partial_path, uat_actions

Class Method Details

.compatible_submission_templatesArray<String>

Returns the submission templates which are compatible with the UAT action. These are submission templates which have a tube as an input asset type.

Returns:

  • (Array<String>)

    The names of the compatible submission templates

[View source]

82
83
84
85
86
87
88
89
90
# File 'app/uat_actions/uat_actions/tube_submission.rb', line 82

def self.compatible_submission_templates
  SubmissionTemplate
    .visible
    .each_with_object([]) do |submission_template, compatible|
      next unless submission_template.input_asset_type.constantize <= Tube

      compatible << submission_template.name
    end
end

.defaultUatActions::TestSubmission

Returns a default copy of the UatAction which will be used to fill in the form

Returns:

[View source]

74
75
76
# File 'app/uat_actions/uat_actions/tube_submission.rb', line 74

def self.default
  new
end

Instance Method Details

#assetsArray<Tube>

Returns the tubes to use for the submission

Returns:

  • (Array<Tube>)

    The tubes to use for the submission

[View source]

185
186
187
# File 'app/uat_actions/uat_actions/tube_submission.rb', line 185

def assets
  @assets ||= select_assets
end

#calculated_request_options_by_template_nameHash

Returns the allowance_band to prevent integration suite breakage for the scRNA Core testing suite.

Allowance bands are only supported for bulk submissions using the Limber-HTP scRNA Core cDNA Prep GEM-X 5p template. In bulk submissions, allowance_band is determined by the calculate_allowance_bands method.

The allowance_band is not included in the form, as it is a calculated value (does not require user input).

@todo: Implement allowance_band support for standard tube submissions (Y25-153) @todo: Remove this method once allowance_band is properly handled for tube submissions.

Returns:

  • (Hash)

    Request options including allowance_band if applicable.

[View source]

245
246
247
248
249
250
251
# File 'app/uat_actions/uat_actions/tube_submission.rb', line 245

def calculated_request_options_by_template_name
  if submission_template_name == SCRNA_CORE_CDNA_PREP_GEM_X_5P
    { 'allowance_band' => '2 pool attempts, 2 counts' }
  else
    {}
  end
end

#custom_request_optionsHash

Returns the custom request options to use for the submission

Returns:

  • (Hash)

    The custom request options from the form

[View source]

223
224
225
226
227
228
229
# File 'app/uat_actions/uat_actions/tube_submission.rb', line 223

def custom_request_options
  options = {}
  options[:library_type] = library_type_name if library_type_name.present?
  options[:number_of_pools] = number_of_pools.presence
  options[:cells_per_chip_well] = cells_per_chip_well.presence
  options
end

#default_request_optionsHash

Returns the default request options to use for the submission

Returns:

  • (Hash)

    The default request options to use for the submission

[View source]

206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'app/uat_actions/uat_actions/tube_submission.rb', line 206

def default_request_options
  submission_template
    .input_field_infos
    .each_with_object({}) do |ifi, options|
      options[ifi.key] = (
        if ifi.default_value.nil?
          ifi.selection&.first.presence || ifi.max.presence || ifi.min
        else
          ifi.default_value
        end
      )
    end
end

#fill_report(order) ⇒ Void

Fills the report with the information from the submission

rubocop:disable Metrics/AbcSize

Returns:

  • (Void)
[View source]

160
161
162
163
164
165
166
167
168
169
170
171
# File 'app/uat_actions/uat_actions/tube_submission.rb', line 160

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_pools'] = order.request_options[:number_of_pools] if order.request_options[
    :number_of_pools
  ].present?
  report['cells_per_chip_well'] = order.request_options[:cells_per_chip_well] if order.request_options[
    :cells_per_chip_well
  ].present?
  report['allowance_band'] = order.request_options[:allowance_band] if order.request_options[:allowance_band].present?
end

#order_request_optionsHash

Returns the request options to use for the submission

Returns:

  • (Hash)

    The request options to use for the submission

[View source]

199
200
201
# File 'app/uat_actions/uat_actions/tube_submission.rb', line 199

def order_request_options
  default_request_options.merge(custom_request_options).merge(calculated_request_options_by_template_name)
end

#performBoolean

Generates tube submission for the given template.

Returns:

  • (Boolean)

    true if the submission was successfully created

[View source]

95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'app/uat_actions/uat_actions/tube_submission.rb', line 95

def perform
  order =
    submission_template.create_with_submission!(
      study: study,
      project: project,
      user: user,
      assets: assets,
      request_options: order_request_options
    )
  fill_report(order)
  order.submission.built!
  true
end

#projectProject

Returns the project to use for UAT

Returns:

  • (Project)

    The project to use for UAT

[View source]

261
# File 'app/uat_actions/uat_actions/tube_submission.rb', line 261

delegate :project, to: :'UatActions::StaticRecords'

#select_assetsArray<Tube>

Returns the tubes from the specified barcodes in the form field

Returns:

  • (Array<Tube>)

    The tubes to use for the submission

[View source]

192
193
194
# File 'app/uat_actions/uat_actions/tube_submission.rb', line 192

def select_assets
  tube_barcodes.gsub(/(\\[trfvn])+/, ' ').split.map { |barcode| Tube.find_by_barcode(barcode) }
end

#studyStudy

Returns the study to use for UAT

Returns:

  • (Study)

    The study to use for UAT

[View source]

256
# File 'app/uat_actions/uat_actions/tube_submission.rb', line 256

delegate :study, to: :'UatActions::StaticRecords'

#submission_templateSubmissionTemplate

Returns the submisssion template to use for the submission

Returns:

[View source]

178
179
180
# File 'app/uat_actions/uat_actions/tube_submission.rb', line 178

def submission_template
  @submission_template = SubmissionTemplate.find_by(name: submission_template_name)
end

#userUser

Returns the uat user

Returns:

  • (User)

    The UAT user can be used in any places where a user is expected.

[View source]

267
# File 'app/uat_actions/uat_actions/tube_submission.rb', line 267

delegate :user, to: :'UatActions::StaticRecords'

#validate_library_type_existsObject

Validates that the library type exists for the specified library type name.

return [void]

[View source]

148
149
150
151
152
153
154
# File 'app/uat_actions/uat_actions/tube_submission.rb', line 148

def validate_library_type_exists
  return if library_type_name.blank? # optional
  return if LibraryType.exists?(name: library_type_name)

  message = format(ERROR_LIBRARY_TYPE_DOES_NOT_EXIST, library_type_name)
  errors.add(:library_type_name, message)
end

#validate_submission_template_existsvoid

This method returns an undefined value.

Validates that the submission template exists for the specified submission template name.

[View source]

113
114
115
116
117
118
119
# File 'app/uat_actions/uat_actions/tube_submission.rb', line 113

def validate_submission_template_exists
  return if submission_template_name.blank? # already validated by presence
  return if SubmissionTemplate.exists?(name: submission_template_name)

  message = format(ERROR_SUBMISSION_TEMPLATE_DOES_NOT_EXIST, submission_template_name)
  errors.add(:submission_template_name, message)
end

#validate_tubes_existvoid

This method returns an undefined value.

Validates that the tubes exist for the specified barcodes.

[View source]

124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'app/uat_actions/uat_actions/tube_submission.rb', line 124

def validate_tubes_exist
  return if tube_barcodes.blank? # already validated by presence

  barcodes =
    tube_barcodes
      .gsub(/(\\[trfvn])+/, ' ')
      .strip
      .split
      .select do |barcode|
        Tube.find_by_barcode(barcode).blank? # not found
      end
  return if barcodes.empty?

  # return if all tubes exist
  return if barcodes.blank?

  # add error message listing tubes that do not exist
  message = format(ERROR_TUBES_DO_NOT_EXIST, barcodes.join(', '))
  errors.add(:tube_barcodes, message)
end