require 'sampler'

def sh1 fromTube, sampleVolume, bubblePt, toTube

 loadPuck fromTube, :collection
 collectSample sampleVolume, bubblePt
 lysing :lysis, 2, :waste1, 88, '5:00'
 unloadPuck :collection, toTube
  
end  #end of sh1

def daExtract fromTube, sampleVolume, bubblePt, toTube

 loadPuck fromTube, :collection
 collectSample sampleVolume, bubblePt
 lysing :AqMeOH, 2, :waste2, 71, '10:00'
 unloadPuck :collection, toTube
  
end #end of daExtract

def collectSample 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

  collectionSampler = 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 "collectSample #{sampleVolume}ml w/bubble point of #{collectionSampler.bubblePt}psi"

  collectionSampler.prime.sample sampleVolume
  collectionSampler.puckEvac

  Log.record "collectSample: Complete"
  
end


def lysing lysisSolution, lysisVolume, wastePlace, temperature, time
  
  Log.record "Lysing: Adding #{lysisSolution}"
  CBV.dialBetween :CSV, :waste1
  CTV.to :CSV
  CSV.to :CSR
  CSR.to lysisSolution
  CS.to 1
  delay 5
  CSR.to :air
  CS.pull 5
  delay 2
  CSV.to wastePlace
  CS.empty CSfast
  
  CSV.to :CSR
  CSR.to lysisSolution
  CS.to lysisVolume
  delay 5
  CSR.to :air
  CS.pull 5
  delay 2
  
  CSV.to :CTV
  CS.to 0.5
  CH.to temperature, 180; CH.hold(time).finish

  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

  Log.record "Lysing: Complete"
end
