Module: Submission::ValidationsByTemplateName

Includes:
ScrnaCoreCdnaPrepFeasibilityValidator
Included in:
BulkSubmission
Defined in:
app/models/submission/validations_by_template_name.rb

Constant Summary collapse

SCRNA_CORE_CDNA_PREP_GEM_X_5P =

Template names

'Limber-Htp - scRNA Core cDNA Prep GEM-X 5p'
HEADER_TEMPLATE_NAME =

Column headers

'template name'
HEADER_STUDY_NAME =
'study name'
HEADER_PROJECT_NAME =
'project name'
HEADER_BARCODE =
'barcode'
HEADER_PLATE_WELLS =
'plate well'
HEADER_NUMBER_OF_POOLS =
'scrna core number of pools'
HEADER_CELLS_PER_CHIP_WELL =
'scrna core cells per chip well'
SAMPLES_PER_POOL =
{ max: 25, min: 5 }.freeze

Constants included from ScrnaCoreCdnaPrepFeasibilityValidator

ScrnaCoreCdnaPrepFeasibilityValidator::I18N_SCOPE_SCRNA_CORE_CDNA_PREP_FEASIBILITY_VALIDATOR

Constants included from ScrnaCoreCdnaPrepFeasibilityCalculator

ScrnaCoreCdnaPrepFeasibilityCalculator::ALLOWANCE_BANDS, ScrnaCoreCdnaPrepFeasibilityCalculator::HEADER_PLATE_WELL

Instance Method Summary collapse

Methods included from ScrnaCoreCdnaPrepFeasibilityValidator

#validate_required_headers, #validate_scrna_core_cdna_prep_feasibility

Methods included from ScrnaCoreCdnaPrepFeasibilityCalculator

#calculate_allowance_bands, #calculate_chip_loading_volume, #calculate_resuspension_volume, #calculate_total_cells_in_300ul, #calculate_volume_needed

Instance Method Details

#apply_additional_validations_by_template_namevoid

This method returns an undefined value.

Applies additional validations based on the submission template type.

This method determines the submission template type from the CSV data and calls the appropriate validation methods based on the template type. It assumes that all rows in the CSV have the same submission template name. If no match is found for the submission template name, no additional validations are performed.

Uses the following instance variables: csv_data_rows [Array<Array<String>>] The CSV data rows, where each row is an array of strings. headers [Array<String>] The headers of the CSV file, used to find the index of specific columns. errors [ActiveModel::Errors] The errors object to which validation errors are added.



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/models/submission/validations_by_template_name.rb', line 43

def apply_additional_validations_by_template_name
  # depending on the submission template type, call additional validations
  # NB. assumption that all rows in the csv have the same submission template name
  case submission_template_name
  # this validation is for the scRNA pipeline cDNA submission
  when SCRNA_CORE_CDNA_PREP_GEM_X_5P
    validate_consistent_column_value(HEADER_NUMBER_OF_POOLS, check_zero: true)
    if errors.empty?
      validate_consistent_column_value(HEADER_CELLS_PER_CHIP_WELL, check_zero: true)
      validate_scrna_core_cdna_prep_feasibility
    end
  end
end

#apply_number_of_samples_per_pool_validationObject



57
58
59
60
# File 'app/models/submission/validations_by_template_name.rb', line 57

def apply_number_of_samples_per_pool_validation
  # Creates groups of rows based on the study and project name (pool_number, study-project) combinations
  group_rows_by_study_and_project
end

#group_rows_by_study_and_projectObject



62
63
64
65
66
# File 'app/models/submission/validations_by_template_name.rb', line 62

def group_rows_by_study_and_project
  index_of_study_name = headers.index(HEADER_STUDY_NAME)
  index_of_project_name = headers.index(HEADER_PROJECT_NAME)
  csv_data_rows.group_by { |row| [row[index_of_study_name], row[index_of_project_name]] }
end

#submission_template_nameObject

Looks for the index of the 'template name' header in the CSV headers and returns the value from the first row in the corresponding column. Assumptions: - The CSV data has already been parsed into an array of rows. - The template name exists in the headers and is present in the first row.



25
26
27
28
# File 'app/models/submission/validations_by_template_name.rb', line 25

def submission_template_name
  index_of_template_name = headers.index(HEADER_TEMPLATE_NAME)
  csv_data_rows.first[index_of_template_name]
end

#validate_consistent_column_value(column_header, check_zero: false) ⇒ void

This method returns an undefined value.

Validates that the specified column is consistent for all rows with the same study and project name.

This method groups the rows in the CSV data by the study name and project name, and checks if the specified column has the same value for all rows within each group. If check_zero is true, it also ensures that the value is not zero. If inconsistencies or zero values are found (depending on the check), an error is added to the errors collection.

Parameters:

  • column_header (String)

    The header of the column to validate.

  • check_zero (Boolean) (defaults to: false)

    Whether to also validate that the value is not zero. Defaults to false.



78
79
80
81
82
83
84
85
86
87
88
89
# File 'app/models/submission/validations_by_template_name.rb', line 78

def validate_consistent_column_value(column_header, check_zero: false)
  index_of_column = headers.index(column_header)
  grouped_rows = group_rows_by_study_and_project

  grouped_rows.each do |study_project, rows|
    if check_zero
      validate_unique_and_non_zero_values(study_project, rows, index_of_column, column_header)
    else
      validate_unique_values(study_project, rows, index_of_column, column_header)
    end
  end
end