Class: RunCsv::PacbioSampleSheet

Inherits:
Object
  • Object
show all
Includes:
DataStructureBuilder
Defined in:
app/exchanges/run_csv/pacbio_sample_sheet.rb

Overview

RunCsv::PacbioSampleSheet Used to generate sample sheets specific to the PacBio pipeline (introduced in SMRT Link v13)

Direct Known Subclasses

PacbioSampleSheetV25

Instance Method Summary collapse

Methods included from DataStructureBuilder

#data_structure, #instance_value

Instance Method Details

#bio_sample_name(sample) ⇒ Object

Returns the bio sample name for the given sample.



100
101
102
# File 'app/exchanges/run_csv/pacbio_sample_sheet.rb', line 100

def bio_sample_name(sample)
  sample.bio_sample_name
end

#generate_smrt_cell_settings(well) ⇒ Object

Generate a hash of settings for a single cell



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/exchanges/run_csv/pacbio_sample_sheet.rb', line 39

def generate_smrt_cell_settings(well) # rubocop:disable Metrics/MethodLength
  {
    'Well Name'	=> well.used_aliquots.first.source.tube.barcode, # TRAC-2-7242
    'Library Type'	=> well.library_type, # Standard
    'Movie Acquisition Time (hours)'	=> well.movie_acquisition_time, # 24
    'Insert Size (bp)'	=> well.insert_size, # 500
    'Assign Data To Project'	=> 1, # (maybe we need to assign a run a project in traction)?
    'Library Concentration (pM)'	=> well.library_concentration, # 250
    'Include Base Kinetics'	=> well.include_base_kinetics,
    'Polymerase Kit'	=> well.polymerase_kit, # 032037102739100071224
    'Indexes'	=> well.barcode_set, # 244d96c6-f3b2-4997-5ae3-23ed33ab925f
    'Sample is indexed'	=> well.tagged?, # Set to True to Multiplex
    'Bio Sample Name' => well.tagged? ? nil : well.bio_sample_name,
    'Use Adaptive Loading'	=> well.use_adaptive_loading,
    'Consensus Mode'	=> 'molecule', # (default to molecule do we need a custom field)
    'Same Barcodes on Both Ends of Sequence'	=> well.same_barcodes_on_both_ends_of_sequence,
    'Full Resolution Base Qual' => well.full_resolution_base_qual
  }
end

#generate_smrt_cells(wells) ⇒ Object



67
68
69
70
71
# File 'app/exchanges/run_csv/pacbio_sample_sheet.rb', line 67

def generate_smrt_cells(wells)
  wells.each_with_object({}) do |(plate_well, well), acc|
    acc[plate_well] = generate_smrt_cell_settings(well)
  end
end

#generate_wellsObject

Generate a hash of settings for the cell



60
61
62
63
64
65
# File 'app/exchanges/run_csv/pacbio_sample_sheet.rb', line 60

def generate_wells
  object.plates.flat_map(&:wells).each_with_object({}) do |well, hash|
    plate_well_name = "#{well.plate.plate_number}_#{well.position_leading_zero}"
    hash[plate_well_name] = well
  end
end

#payloadObject



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'app/exchanges/run_csv/pacbio_sample_sheet.rb', line 117

def payload
  # Combine all elements into the final sample sheet
  sample_sheet = "[Run Settings]\n"

  # Start with the run settings
  sample_sheet += run_settings.map { |k, v| "#{k},#{v}" }.join("\n")

  # Add the cell settings
  sample_sheet += "\n[SMRT Cell Settings]"
  sample_sheet += ",#{plate_well_names.join(',')}\n"
  sample_sheet += smrt_cell_settings.map do |key, cells|
    "#{key}," + cells.values.join(',')
  end.join("\n")

  # Add the sample settings
  sample_sheet += "\n[Samples]\n"
  sample_sheet += samples_csv

  sample_sheet
end

#plate_well_namesObject

Generate a list of plate-well identifiers. Eg. [‘1_A01’, ‘1_A02’, ‘2_A01’, …]



31
32
33
34
35
36
# File 'app/exchanges/run_csv/pacbio_sample_sheet.rb', line 31

def plate_well_names
  wells = object.plates.flat_map(&:wells)
  wells.map do |well|
    "#{well.plate.plate_number}_#{well.position_leading_zero}"
  end
end

#run_settingsObject

Generate a hash of settings for the run



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/exchanges/run_csv/pacbio_sample_sheet.rb', line 13

def run_settings
  run = object # Pacbio::Run

  plate_data = run.plates.first(2).each_with_index.with_object({}) do |(plate, index), hash|
    hash["Plate #{index + 1}"] = plate&.sequencing_kit_box_barcode
  end

  {
    'Instrument Type' => run.system_name,
    'Run Name' =>	run.name,
    'Run Comments' =>	run.barcodes_and_concentrations
  }.merge(plate_data).merge(
    { 'CSV Version' => 1 }
  )
end

#sample_data(well, sample) ⇒ Object



89
90
91
92
93
94
95
96
# File 'app/exchanges/run_csv/pacbio_sample_sheet.rb', line 89

def sample_data(well, sample)
  [
    bio_sample_name(sample),
    well.plate_well_position,
    sample.adapter, # left adapter
    sample.adapter  # right adapter
  ]
end

#samples_csvObject

Generate a CSV of samples



105
106
107
108
109
110
111
112
113
114
115
# File 'app/exchanges/run_csv/pacbio_sample_sheet.rb', line 105

def samples_csv
  headers = ['Bio Sample Name', 'Plate Well', 'Adapter', 'Adapter2']
  CSV.generate do |csv|
    csv << headers
    object.sorted_wells.each do |well|
      well.aliquots_to_show_per_row&.each do |sample|
        csv << sample_data(well, sample)
      end
    end
  end
end

#smrt_cell_settingsObject

Each key is a plate-well identifier and the value is a hash of settings for a particular cell



83
84
85
86
87
# File 'app/exchanges/run_csv/pacbio_sample_sheet.rb', line 83

def smrt_cell_settings
  wells = generate_wells
  smrt_cells = generate_smrt_cells(wells)
  transpose_smrt_cells(smrt_cells)
end

#transpose_smrt_cells(smrt_cells) ⇒ Object



73
74
75
76
77
78
79
80
# File 'app/exchanges/run_csv/pacbio_sample_sheet.rb', line 73

def transpose_smrt_cells(smrt_cells)
  smrt_cells.each_with_object({}) do |(plate_well, cell_data), result|
    cell_data.each do |(key, value)|
      result[key] ||= {}
      result[key].merge!({ plate_well => value })
    end
  end
end