Class: PacBio::SampleSheet

Inherits:
Object
  • Object
show all
Defined in:
app/models/pac_bio/sample_sheet.rb

Overview

rubocop:todo Style/Documentation

Constant Summary collapse

@@CONCAT_SEPARATOR =
';'

Instance Method Summary collapse

Instance Method Details

#column_headersObject


17
18
19
20
21
# File 'app/models/pac_bio/sample_sheet.rb', line 17

def column_headers
  ['Well No.', 'Sample Name', 'DNA Template Prep Kit Box Barcode', 'Prep Kit Parameters', 'Binding Kit Box Barcode', 'Binding Kit Parameters',
   'Collection Protocol', 'CP Parameters', 'Basecaller', 'Basecaller Parameters', 'Secondary Analysis Protocol', 'Secondary Analysis Parameters',
   'Sample Comments', 'User Field 1', 'User Field 2', 'User Field 3', 'User Field 4', 'User Field 5', 'User Field 6', 'Results Data Output Path']
end

#concat(list, sym, separator = @@CONCAT_SEPARATOR) ⇒ Object


45
46
47
# File 'app/models/pac_bio/sample_sheet.rb', line 45

def concat(list, sym, separator = @@CONCAT_SEPARATOR)
  list.map(&sym).uniq.join(separator)
end

#create_csv_from_batch(batch) ⇒ Object


23
24
25
26
27
28
29
30
31
# File 'app/models/pac_bio/sample_sheet.rb', line 23

def create_csv_from_batch(batch)
  csv_string = CSV.generate(row_sep: "\r\n") do |csv|
    (batch).each { |header_row| csv << header_row }
    csv << column_headers
    requests_by_wells(batch).each do |requests|
      csv << row(requests, batch)
    end
  end
end

#header_metadata(batch) ⇒ Object


2
3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'app/models/pac_bio/sample_sheet.rb', line 2

def (batch)
  [
    ['Version', '1.0.0', nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil],
    ['Unique ID', batch.id, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil],
    ['Type', 'Plate', nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil],
    ['Owner', 'System', nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil],
    ['Created By', batch.user., nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
     nil, nil],
    ['Comments', "New plate created on #{Time.zone.now}", nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
     nil, nil, nil, nil, nil, nil, nil],
    ['Output Path', nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil],
    [nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil]
  ]
end

#lookup_collection_protocol(request) ⇒ Object


84
85
86
87
88
89
# File 'app/models/pac_bio/sample_sheet.rb', line 84

def lookup_collection_protocol(request)
  return 'Standard Seq v3' if request..sequencing_type == 'Standard'
  return 'MagBead Standard Seq v2' if request..sequencing_type == 'MagBead'

  request..sequencing_type
end

#replace_non_alphanumeric(protocol) ⇒ Object


39
40
41
# File 'app/models/pac_bio/sample_sheet.rb', line 39

def replace_non_alphanumeric(protocol)
  protocol.gsub(/[^\w]/, '_')
end

#requests_by_wells(batch) ⇒ Object


33
34
35
36
37
# File 'app/models/pac_bio/sample_sheet.rb', line 33

def requests_by_wells(batch)
  requests = batch.requests.for_pacbio_sample_sheet
  sorted_well_requests = requests.group_by { |r| r.target_asset.map.column_order }.sort
  sorted_well_requests.map { |_well_index, requests| requests }
end

#row(requests, batch) ⇒ Object


49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'app/models/pac_bio/sample_sheet.rb', line 49

def row(requests, batch)
  # Read these lines when secondary analysis activated
  #  replace_non_alphanumeric(library_tube.pac_bio_library_tube_metadata.protocol),
  # "JobName=DefaultJob_#{Time.now}",
  # request = requests.first

  library_tubes = requests.map(&:asset)
   = requests.first.
   = requests.first.

  well = requests.first.target_asset
  [
    Map.pad_description(well.map),
    concat(library_tubes, :labware_name, '-'),
    .prep_kit_barcode,
    nil,
    .binding_kit_barcode,
    nil,
    lookup_collection_protocol(requests.first),
    "AcquisitionTime=#{.movie_length}|InsertSize=#{.insert_size}|StageHS=True|SizeSelectionEnabled=False|Use2ndLook=False|NumberOfCollections=#{requests.size}",
    'Default',
    nil,
    nil,
    nil,
    nil,
    well.uuid,
    concat(library_tubes, :uuid),
    batch.uuid,
    well.plate.barcode_number,
    concat(requests, :uuid),
    nil,
    nil
  ]
end