sanger/limber

View on GitHub
app/views/exports/hamilton_pooling_plate_pbmc.csv.erb

Summary

Maintainability
Test Coverage
<%# This is a picking file for a Hamilton robot for pooling and resuspending PBMC samples %>
<%= CSV.generate_line [
      'SourcePlate',
      'SourceWell',
      'DestinationPlate',
      'DestinationWell',
      'SampleVolume',
      'ResuspensionVolume',
    ],
    row_sep: ''
%>
<%
  # Prepare the fields determined from the transfer requests
  transfer_request_data = []
  each_source_metadata_for_plate(@plate) do |src_barcode, src_location, dest_well|
    # Convert cells/ml into µl / 20,000 cells
    # Note: 20,000 / (cells/ml) * 1,000 is the same as 20,000,000 / (cells/ml)
    src_well = @ancestor_plate.wells_in_columns.find { |well| well.location == src_location }
    cell_count = src_well.latest_live_cell_count
    next if cell_count.nil?
    required_volume = 20000000.0 / cell_count.value.to_i

    transfer_request_data << [
      src_barcode,
      src_location,
      @plate.labware_barcode.human,
      dest_well.location,
      '%0.2f' % required_volume,
    ]
  end
%>
<%
  # Calculate the resuspension volumes from the pooled samples count
  resuspension_volume_per_sample = 2.2
  minimum_resuspension_volume = 20
  samples_by_dest_well = transfer_request_data.group_by { |tr| tr[3] }

  rows_array = transfer_request_data.map do |data|
    samples_in_pool = samples_by_dest_well[data[3]].count
    resuspension_volume = [samples_in_pool * resuspension_volume_per_sample, minimum_resuspension_volume].max
    data + ['%0.2f' % resuspension_volume]
  end
%>
<%= rows_array.sort_by{ |a| WellHelpers.well_coordinate(a[1]) }.map(&:to_csv).join %>