require 'sampler'

def sh1 sampleVolume, bubblePtOrSampler=Sampler.new, optionalParameters={}
#  Do an Sandwitch Hyrbridization "1" with specified 
#  sample volume and filter bubble point.  
#  optionlParameters are specified as a ruby hash.  See sampler.rb
#
#  Examples:
#    sh1 240, 35   #sample 240ml with a filter bubble point of 35psi
#    sh1 530, 40, :maxDelay=>10   #sample 530ml with 40psi bubble pt...
#                 #wait only 10 seconds for fuild to "catch up" with plunger

  sh1Sampler = if bubblePtOrSampler.kind_of? Numeric  #assume its a bubble point in psi
    options = optionalParameters.dup
    options[:bubblePt] = bubblePtOrSampler
    Sampler.new options
  else #it must have been an already initialized sampler object
    bubblePtOrSampler.dup.with optionalParameters
  end
  
  Log.record "sh1 #{sampleVolume}ml w/bubble point of #{sh1Sampler.bubblePt}psi"

  sh1Sampler.prime.sample sampleVolume
  sh1Sampler.puckEvac
  
  sh1Finish
  
end


def sh1Finish
  
  Log.record "sh1: Adding Lysate"
  CBV.dialBetween :CSV, :waste1
  CTV.to :CSV
  CSV.to :CSR
  CSR.to :lysis
  CS.to 1
  delay 5
  CSR.to :air
  CS.pull 5
  delay 2
  CSV.to :waste
  CS.empty CSfast
  
  CSV.to :CSR
  CSR.to :lysis
  CS.to 2
  delay 5
  CSR.to :air
  CS.pull 5
  delay 2
  
  CSV.to :CTV
  CS.to 0.5
  CH.to 88, 180; CH.hold('5:00').finish  #lyse for five minutes

  CSV.to :air
  delay 1
  CS.empty CSfast
  CSV.to :CBV  #do not "connect", order is important
  CBV.to :CSV
  CS.to 6
  CTV.to :air
  delay 5
  CS.to 8
  delay 5
  CSV.to :air2

end
