diff --git a/app/models/exports/filename_handler/ultima_balancing.rb b/app/models/exports/filename_handler/ultima_balancing.rb index 47e12d22bc..7ed1891f76 100644 --- a/app/models/exports/filename_handler/ultima_balancing.rb +++ b/app/models/exports/filename_handler/ultima_balancing.rb @@ -6,6 +6,7 @@ module FilenameHandler class UltimaBalancing def self.build_filename(labware, _page, _export) batch_ids = labware.aliquots.collect do |aliquot| + # TODO: change (and other uses) to 'detect' - 'find' just brings back .all aliquot.poly_metadata.find { |pm| pm.key == 'batch_id' }&.value end diff --git a/app/views/exports/scrna_core_final_pooling_strategy.csv.erb b/app/views/exports/scrna_core_final_pooling_strategy.csv.erb new file mode 100644 index 0000000000..ae1abc7bfc --- /dev/null +++ b/app/views/exports/scrna_core_final_pooling_strategy.csv.erb @@ -0,0 +1,71 @@ +<% + csv_rows = [ + [ + 'DONOR ID', + 'SAMPLE DESCRIPTION', + 'SANGER TUBE ID', + 'SANGER SAMPLE ID', + 'LRC PBMC Defrost 1ml or Aliquot ID', + 'Source Well', + 'LRC PBMC Defrost 1ml/ Aliquot plate Total Cells/mL', + 'LRC PBMC Defrost 1ml/ Aliquot plate Viability', + 'LRC PBMC Defrost 1ml/Aliquot plate Status', + 'LRC PBMC Pools plate ID', + 'Destination Well', + 'LRC PBMC Pools plate Total Cells/mL', + 'LRC PBMC Pools plate Viability', + 'Requested scRNA Core Cells per Chip Well', + 'Actual scRNA Core Cells per Chip Well'] + ] + + # Get parent plates using parents association, which brings back Sequencescape::Api::V2::Asset objects. + parent_plate_barcodes = @plate.parents.map { |parent_plate| parent_plate.barcode&.human } + # Requery parent plates as Sequencescape::Api::V2::Plate to get access to wells and samples + parent_plates = Sequencescape::Api::V2::Plate.where(barcode: parent_plate_barcodes) + + parent_plates.each do |parent_plate| + parent_plate.wells_in_columns.each do |parent_well| + sample = parent_well.aliquots.first&.sample + next unless sample + + # binding.pry + + pools_plate_well = parent_well.downstream_wells.first + + donor_id = sample.sample_metadata.donor_id + sample_description = sample.sample_metadata.sample_description + sanger_tube_id = parent_well.upstream_tubes.first.human_barcode if parent_well.upstream_tubes.any? # sample.sample_metadata.supplier_name + sanger_sample_id = sample.sanger_sample_id + lrc_pbmc_defrost_1ml_or_aliquot_id = parent_plate.barcode.human + source_well = parent_well.position['name'] + lrc_pbmc_defrost_1ml_or_aliquot_plate_total_cells_per_ml = parent_well.latest_total_cell_count&.value + lrc_pbmc_defrost_1ml_or_aliquot_plate_viability = parent_well.latest_cell_viability&.value + lrc_pbmc_defrost_1ml_or_aliquot_plate_status = nil # TODO - what did we decide for this? + lrc_pbmc_pools_plate_id = @plate.barcode.human + destination_well = pools_plate_well.position['name'] + lrc_pbmc_pools_plate_total_cells_per_ml = pools_plate_well.latest_total_cell_count&.value + lrc_pbmc_pools_plate_viability = pools_plate_well.latest_cell_viability&.value + requested_scrna_core_cells_per_chip_well = pools_plate_well.aliquots.first.request.first.request_metadata.cells_per_chip_well + actual_scrna_core_cells_per_chip_well = pools_plate_well.poly_metadata.detect { |pm| pm.key == 'scrna_core_pbmc_donor_pooling_number_of_cells_per_chip_well' }&.value + + csv_rows << [ + donor_id, + sample_description, + sanger_tube_id, + sanger_sample_id, + lrc_pbmc_defrost_1ml_or_aliquot_id, + source_well, + lrc_pbmc_defrost_1ml_or_aliquot_plate_total_cells_per_ml, + lrc_pbmc_defrost_1ml_or_aliquot_plate_viability, + lrc_pbmc_defrost_1ml_or_aliquot_plate_status, + lrc_pbmc_pools_plate_id, + destination_well, + lrc_pbmc_pools_plate_total_cells_per_ml, + lrc_pbmc_pools_plate_viability, + requested_scrna_core_cells_per_chip_well, + actual_scrna_core_cells_per_chip_well + ] + end + end +%> +<%= csv_rows.map(&:to_csv).join %> \ No newline at end of file diff --git a/config/exports/exports.yml b/config/exports/exports.yml index 8f74d9c6c3..1465627e2c 100644 --- a/config/exports/exports.yml +++ b/config/exports/exports.yml @@ -153,6 +153,10 @@ scrna_core_cell_extraction_sample_arraying_tube_layout: csv: scrna_core_cell_extraction_sample_arraying_tube_layout plate_includes: - wells.upstream_tubes +scrna_core_final_pooling_strategy: + csv: scrna_core_final_pooling_strategy + plate_includes: + - wells.upstream_tubes hamilton_lrc_pbmc_bank_to_lrc_bank_seq_and_spare: csv: hamilton_lrc_pbmc_bank_to_lrc_bank_seq_and_spare workflow: scRNA Core PBMC Bank diff --git a/config/purposes/scrna_core_cdna_prep.yml b/config/purposes/scrna_core_cdna_prep.yml index 17139b969d..425e6781bd 100644 --- a/config/purposes/scrna_core_cdna_prep.yml +++ b/config/purposes/scrna_core_cdna_prep.yml @@ -112,6 +112,8 @@ LRC PBMC Pools: parent: 'LRC PBMC Aliquot' - name: 'Download Cellaca Count CSV' id: 'hamilton_lrc_pbmc_pools_to_cellaca_count' + - name: 'Download final pooling strategy CSV' + id: 'scrna_core_final_pooling_strategy' # Plate containing pooled PBMCs from different donors. # This plate has come from faculty and is entering the SeqOps pipeline for the first time here. LRC GEM-X 5p GEMs Input: diff --git a/spec/views/exports/scrna_core_final_pooling_strategy.csv.erb_spec.rb b/spec/views/exports/scrna_core_final_pooling_strategy.csv.erb_spec.rb new file mode 100644 index 0000000000..fea46dbd18 --- /dev/null +++ b/spec/views/exports/scrna_core_final_pooling_strategy.csv.erb_spec.rb @@ -0,0 +1,53 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'exports/scrna_core_final_pooling_strategy.csv.erb' do +# let(:tube_a1) { create(:stock_tube, state: 'passed', purpose_name: 'Example Purpose', barcode_number: 2) } +# let(:tube_b1) { create(:stock_tube, state: 'passed', purpose_name: 'Example Purpose', barcode_number: 3) } +# let(:tube_c1) { create(:stock_tube, state: 'passed', purpose_name: 'Example Purpose', barcode_number: 4) } +# let(:tube_e7) { create(:stock_tube, state: 'passed', purpose_name: 'Example Purpose', barcode_number: 5) } +# let(:tube_g12) { create(:stock_tube, state: 'passed', purpose_name: 'Example Purpose', barcode_number: 6) } + +# let(:well_a1) { create(:stock_well, location: 'A1', state: 'passed', upstream_tubes: [tube_a1]) } +# let(:well_b1) { create(:stock_well, location: 'B1', state: 'passed', upstream_tubes: [tube_b1]) } +# let(:well_c1) { create(:stock_well, location: 'C1', state: 'passed', upstream_tubes: [tube_c1]) } +# let(:well_e7) { create(:stock_well, location: 'E7', state: 'passed', upstream_tubes: [tube_e7]) } +# let(:well_g12) { create(:stock_well, location: 'G12', state: 'passed', upstream_tubes: [tube_g12]) } + + let(:parent_plate_1) { create(:plate) } + let(:parent_plate_2) { create(:plate) } + let(:pools_plate) { create(:plate, parents: [parent_plate_1, parent_plate_2]) } + + before { assign(:plate, pools_plate) } + + def get_column(csv, index) + csv[1..].pluck(index) + end + + it 'renders the expected content' do + parsed_csv = CSV.parse(render) + # expect(parsed_csv.size).to eq 11 + # barcode = labware.labware_barcode.human + + expected_column_names = ['DONOR ID', 'SAMPLE DESCRIPTION', 'SANGER TUBE ID', 'SANGER SAMPLE ID', 'LRC PBMC Defrost 1ml or Aliquot ID', 'Source Well', 'LRC PBMC Defrost 1ml/ Aliquot plate Total Cells/mL', 'LRC PBMC Defrost 1ml/ Aliquot plate Viability', 'LRC PBMC Defrost 1ml/Aliquot plate Status', 'LRC PBMC Pools plate ID', 'Proposed Destination Well', 'Destination Well', 'LRC PBMC Pools plate Total Cells/mL', 'LRC PBMC Pools plate Viability', 'Requested scRNA Core Cells per Chip Well', 'Actual scRNA Core Cells per Chip Well'] + expect(parsed_csv[0]).to eq expected_column_names + + expected_sample_1 = ['DONOR-1', nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil] + expect(parsed_csv[1]).to eq expected_sample_1 + + # Donor ID column + # expect(get_column(parsed_csv, 0)).to eq(['DONOR-1', 'DONOR-2', nil]) + + # # chek for tube barcode content in wells + # expect(get_column(parsed_csv, 1)).to eq( + # [nil, '1', 'NT2P', 'NT3Q', 'NT4R', 'empty', 'empty', 'empty', 'empty', 'empty'] + # ) + # expect(get_column(parsed_csv, 7)).to eq( + # [nil, '7', 'empty', 'empty', 'empty', 'empty', 'NT5S', 'empty', 'empty', 'empty'] + # ) + # expect(get_column(parsed_csv, 12)).to eq( + # [nil, '12', 'empty', 'empty', 'empty', 'empty', 'empty', 'empty', 'NT6T', 'empty'] + # ) + end +end