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


58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'app/models/pac_bio/sample_sheet.rb', line 58

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


104
105
106
# File 'app/models/pac_bio/sample_sheet.rb', line 104

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

#create_csv_from_batch(batch) ⇒ Object


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

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 { |requests| csv << row(requests, batch) }
    end
end

#header_metadata(batch) ⇒ Object


3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/models/pac_bio/sample_sheet.rb', line 3

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


145
146
147
148
149
150
# File 'app/models/pac_bio/sample_sheet.rb', line 145

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


98
99
100
# File 'app/models/pac_bio/sample_sheet.rb', line 98

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

#requests_by_wells(batch) ⇒ Object


92
93
94
95
96
# File 'app/models/pac_bio/sample_sheet.rb', line 92

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

rubocop:todo Metrics/AbcSize


108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'app/models/pac_bio/sample_sheet.rb', line 108

def row(requests, batch) # rubocop:todo Metrics/AbcSize
  # 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),
    # rubocop:disable Layout/LineLength
    "AcquisitionTime=#{.movie_length}|InsertSize=#{.insert_size}|StageHS=True|SizeSelectionEnabled=False|Use2ndLook=False|NumberOfCollections=#{requests.size}",
    # rubocop:enable Layout/LineLength
    'Default',
    nil,
    nil,
    nil,
    nil,
    well.uuid,
    concat(library_tubes, :uuid),
    batch.uuid,
    well.plate.barcode_number,
    concat(requests, :uuid),
    nil,
    nil
  ]
end