Class: PacBio::SampleSheet

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

Constant Summary collapse

@@CONCAT_SEPARATOR =
';'

Instance Method Summary collapse

Instance Method Details

#column_headersObject


15
16
17
18
19
# File 'app/models/pac_bio/sample_sheet.rb', line 15

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


43
44
45
# File 'app/models/pac_bio/sample_sheet.rb', line 43

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

#create_csv_from_batch(batch) ⇒ Object


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

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
# 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.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


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

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


37
38
39
# File 'app/models/pac_bio/sample_sheet.rb', line 37

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

#requests_by_wells(batch) ⇒ Object


31
32
33
34
35
# File 'app/models/pac_bio/sample_sheet.rb', line 31

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


47
48
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
# File 'app/models/pac_bio/sample_sheet.rb', line 47

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