Class: UltimaSampleSheet::SampleSheetGenerator::Generator

Inherits:
Object
  • Object
show all
Defined in:
app/controllers/ultima_sample_sheet/sample_sheet_generator.rb

Overview

Ultima sample sheet generator class. It creates a ZIP archive containing individual sample sheet CSV files for each request in the given Ultima sequencing batch.

Constant Summary collapse

PLATE_LENGTH =

rubocop:disable Metrics/ClassLength

8
HEADER_TITLE =

Assumes 96-well tag plates with 8 rows (A-H).

['[Header]'].freeze
GLOBAL_TITLE =
['[Global]'].freeze
GLOBAL_HEADERS =
%w[
  Application
  sequencing_recipe
  analysis_recipe
].freeze
SAMPLES_TITLE =
['[Samples]'].freeze
SAMPLES_HEADERS =
%w[
  Sample_ID
  Library_name
  Index_Barcode_Num
  Index_Barcode_Sequence
  Barcode_Plate_Num
  Barcode_Plate_Well
  application_type
  study_id
].freeze
NUM_COLUMS =
SAMPLES_HEADERS.size
ULTIMA_TAG_GROUPS =

The names of the Ultima tag groups are mapped to the index numbers for the Barcode_Plate_Num column, i.e. 1 or 2. The number is also used for determining the consistent starting index number for the Index_Barcode_Num column, i.e. Z0001 or Z097.

{
  'Ultima P1' => 1,
  'Ultima P2' => 2
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(batch) ⇒ void

Initializes the generator with the given batch.

Parameters:

  • batch (UltimaSequencingBatch)

    the batch to generate sample sheets for



49
50
51
# File 'app/controllers/ultima_sample_sheet/sample_sheet_generator.rb', line 49

def initialize(batch)
  @batch = batch
end

Instance Method Details

#csv_string(request) ⇒ String

Generates the CSV string for a single request.

Parameters:

Returns:

  • (String)

    the CSV content as a string with CRLF line endings



70
71
72
73
74
75
76
77
78
# File 'app/controllers/ultima_sample_sheet/sample_sheet_generator.rb', line 70

def csv_string(request)
  CSV.generate(row_sep: "\r\n", force_quotes: false, quote_empty: false) do |csv|
    add_header_section(csv, request)
    csv << pad # empty row
    add_global_section(csv, request)
    csv << pad
    add_samples_section(csv, request)
  end
end

#generateString

Generates a ZIP archive containing individual sample sheet CSV files for each request in the batch. This sorts the requests by id to ensure consistent ordering of CSV files in the zip archive.

Returns:

  • (String)

    the ZIP archive as a binary string



57
58
59
60
61
62
63
64
65
# File 'app/controllers/ultima_sample_sheet/sample_sheet_generator.rb', line 57

def generate
  zip_stream = Zip::OutputStream.write_buffer do |zip|
    batch_requests.sort_by(&:id).each do |request|
      zip.put_next_entry(entry_name(request))
      zip.write(csv_string(request).encode('UTF-8'))
    end
  end
  zip_stream.string
end