Esempio n. 1
0
 def idler(self, t):
     endTime = clock.elapsed() + t
     if self.debug:
         print("Idler(%.0f)" % t)
     while clock.elapsed() < endTime:
         j = self.jobq.getJob()
         if j is None:
             break
         self.jobq.execJob(self.trp.e, j)
     if self.debug:
         print("Idler done with ", endTime - clock.elapsed(), " seconds remaining")
Esempio n. 2
0
    def pgm(self):
        self.q = QSetup(self, maxdil=16, debug=False, mindilvol=60)

        self.q.debug = True
        self.q.addReferences(dstep=10, primers=self.qprimers, ref=reagents.getsample("BT5310"),nreplicates=2)

        print("### Barcoding #### (%.0f min)" % (clock.elapsed() / 60.0))
        self.idbarcoding(self.rsrc, left=[x['left'] for x in self.inputs],
                                 right=[x['right'] for x in self.inputs])
        print("### qPCR #### (%.0f min)" % (clock.elapsed() / 60.0))
        self.q.run(confirm=False, enzName='EvaGreen')
Esempio n. 3
0
 def idler(self,t):
     endTime=clock.elapsed()+t
     if self.debug:
         print "Idler(%.0f)"%t
     while clock.elapsed()<endTime:
         j=self.jobq.getJob()
         if j is None:
             break
         self.jobq.execJob(self.trp.e,j)
     if self.debug:
         print "Idler done with ",endTime-clock.elapsed()," seconds remaining"
Esempio n. 4
0
 def idler(self,t):
     endTime=clock.elapsed()+t
     if self.debug:
         print("Idler(%.0f)"%t)
     njobs=0
     while clock.elapsed()<endTime:
         j=self.jobq.getJob()
         if j is None:
             break
         self.jobq.execJob(self.trp.e,j)
         njobs+=1
     if self.debug:
         print("Idler completed ",njobs," jobs with ",endTime-clock.elapsed()," seconds remaining")
Esempio n. 5
0
    def pgm(self):
        self.q = QSetup(self, maxdil=16, debug=False, mindilvol=100)
        self.e.addIdleProgram(self.q.idler)

        if self.doqpcr:
            self.q.addReferences(dstep=10, primers=self.qprimers, ref=reagents.getsample("BT5310"))

        print("### Barcoding #### (%.0f min)" % (clock.elapsed() / 60.0))
        bcout = self.barcoding(names=[x['name'] for x in self.inputs], left=[x['left'] for x in self.inputs],
                               right=[x['right'] for x in self.inputs])

        for i in range(len(self.inputs)):
            x = self.inputs[i]
            if 'bconc' in x and x['bconc'] is not None:
                print("Resetting concentration of %s from expected %.1f to bconc setting of %.1f nM" % \
                      (x['name'], bcout[i].conc.stock, x['bconc']))
                bcout[i].conc.stock = x['bconc']

        print("### qPCR #### (%.0f min)" % (clock.elapsed() / 60.0))
        self.q.run(confirm=False, enzName='EvaGreen')
        print("### qPCR Done #### (%.0f min)" % (clock.elapsed() / 60.0))
        print("### Final PCR Done #### (%.0f min)" % (clock.elapsed() / 60.0))
        worklist.flushQueue()

        if all(['bconc' in x and x['bconc'] is not None for x in self.inputs]):
            print("### Mixdown #### (%.0f min)" % (clock.elapsed() / 60.0))
            worklist.flushQueue()
            worklist.comment('Start mixdown only at this point')
            self.e.sanitize(force=True)
            # mixdown = self.mix(bcout, [x['weight'] for x in self.inputs])
            # Set default mix number to 1
            for x in self.inputs:
                if 'mix' not in x:
                    x['mix']=1
            mixes=set([x['mix'] for x in self.inputs])
            for m in mixes:
                sel=[ i for i in range(len(self.inputs)) if self.inputs[i]['mix']==m] 
                print("sel=",sel)
                mixdown = self.mix([bcout[i] for i in sel], [self.inputs[i]['weight'] for i in sel],prefix="Mix%d_"%m)
                mixdown.name="Mix%d_Final"%m
            # self.q.addSamples(mixdown, needDil=mixdown.conc.stock * 1e-9 / self.qconc, primers=self.qprimers,nreplicates=3)
        else:
            print("### Not doing mixdown as bconc not set in all inputs")
Esempio n. 6
0
 def reset(self):
     'Reset this experiment so we can generate it again after adjusting the reagent initial volumes and total time'
     totalTime=clock.elapsed()
     clock.reset(totalTime)
     #print "After reset, elapsed=%d"%clock.elapsed()
     worklist.reset()
     self.e=Experiment()
     self.e.setreagenttemp(6.0)
     self.e.sanitize(3,50)    # Heavy sanitize
     reagents.reset()
     Sample.clearall()
     decklayout.initWellKnownSamples()
Esempio n. 7
0
 def reset(self):
     'Reset this experiment so we can generate it again after adjusting the reagent initial volumes and total time'
     totalTime = clock.elapsed()
     clock.reset(totalTime)
     #print "After reset, elapsed=%d"%clock.elapsed()
     worklist.reset()
     self.e = Experiment()
     self.e.setreagenttemp(6.0)
     self.e.sanitize(3, 50)  # Heavy sanitize
     reagents.reset()
     Sample.clearall()
     decklayout.initWellKnownSamples()
Esempio n. 8
0
    def pgm(self):
        self.q = QSetup(self, maxdil=16, debug=False, mindilvol=60)

        #  Don't start idler (to minimize tip cross-contamination); last PCR allows plenty of time for doing dilutions without any effect on run time
        # Will start after first constriction PCR is running
        #self.q.debug = True
        # self.e.addIdleProgram(self.q.idler)

        self.q.addReferences(dstep=10, primers=self.qprimers, ref=reagents.getsample("BT5310"),nreplicates=2)

        samps=[r.getsample() for r in self.rsrc]
        for s in samps:
            self.q.addSamples([s],needDil=max(10,s.conc.stock*1e-9/self.qconc),primers=self.qprimers)
        print("### Mixdown #### (%.0f min)" % (clock.elapsed() / 60.0))
        if len(samps)>1:
            mixdown = self.mix(samps, [x['weight'] for x in self.inputs])
        else:
            mixdown=samps[0]
        self.q.addSamples(mixdown, needDil=max(1.0,mixdown.conc.stock * 1e-9 / self.qconc), primers=self.qprimers)
        print("Mixdown final concentration = %.0f pM" % (mixdown.conc.stock * 1000))
        print("### Constriction #### (%.1f min)" % (clock.elapsed() / 60.0))
        constricted = self.constrict(mixdown, mixdown.conc.stock * 1e-9)
        print("### Regeneration #### (%.0f min)" % (clock.elapsed() / 60.0))
        prefixes = set([x['left'][0] for x in self.inputs])
        self.regenerate(constricted * len(prefixes), [p for p in prefixes for _ in constricted])
        print("### qPCR #### (%.0f min)" % (clock.elapsed() / 60.0))
        self.q.run(confirm=False, enzName='EvaGreen', waitForPTC=True)
        print("### qPCR Done #### (%.0f min)" % (clock.elapsed() / 60.0))
        worklist.userprompt("qPCR done -- only need to complete final PCR", 300)
        self.e.waitpgm()
        print("### Final PCR Done #### (%.0f min)" % (clock.elapsed() / 60.0))
Esempio n. 9
0
    def oneround(self, q, input, prefixOut, stop, prefixIn, keepCleaved, t7vol,
                 rtvol, pcrdil, cycles, pcrvol, dolig):
        primerSet = [
            set(["MX", "REF", "T7X", prefixIn[i] + "X", prefixOut[i] + "X"])
            for i in range(len(prefixIn))
        ]

        if keepCleaved:
            print "Starting new cleavage round, will add prefix: ", prefixOut
            assert (dolig)
        else:
            print "Starting new uncleaved round, will retain prefix: ", prefixIn
        print "stop=", stop, "prefixOut=", prefixOut, ", prefixIn=", prefixIn, ",t7vol=", t7vol, ",rtvol=", rtvol, ",pcrdil=", pcrdil, ",cycles=", cycles, ",dolig=", dolig
        if self.rtCarryForward:
            assert (dolig)

        names = [i.name for i in input]

        if self.rnaInput:
            rxs = input
            stopDil = 1
        else:
            print "######## T7 ########### %.0f min" % (clock.elapsed() / 60)
            print "Inputs:  (t7vol=%.2f)" % t7vol
            inconc = [inp.conc.final for inp in input]
            for inp in input:
                if inp.conc.units == 'nM':
                    print "    %s:  %.1ful@%.1f %s, use %.1f ul (%.3f pmoles)" % (
                        inp.name, inp.volume, inp.conc.stock, inp.conc.units,
                        t7vol / inp.conc.dilutionneeded(),
                        t7vol * inp.conc.final / 1000)
                    needDil = max([inp.conc.stock
                                   for inp in input]) * 1.0 / self.qConc
                else:
                    print "    %s:  %.1ful@%.1f %s, use %.1f ul" % (
                        inp.name, inp.volume, inp.conc.stock, inp.conc.units,
                        t7vol / inp.conc.dilutionneeded())
                    needDil = 100 / self.qConc  # Assume 100nM
                # inp.conc.final=inp.conc.stock*self.templateDilution
            if self.directT7 and self.rndNum == 1:
                # Just add ligands and MT7 to each well
                if not keepCleaved:
                    for i in range(len(input)):
                        if self.inputs[i]['ligand'] is not None:
                            ligand = reagents.getsample(
                                self.inputs[i]['ligand'])
                            self.e.transfer(t7vol /
                                            ligand.conc.dilutionneeded(),
                                            ligand,
                                            input[i],
                                            mix=(False, False))
                            names[i] += "+"
                mconc = reagents.getsample("MT7").conc.dilutionneeded()
                for i in range(len(input)):
                    watervol = t7vol * (1 - 1 / mconc) - input[i].volume
                    if watervol > 0.1:
                        self.e.transfer(watervol,
                                        decklayout.WATER,
                                        input[i],
                                        mix=(False, False))
                    self.e.transfer(t7vol / mconc,
                                    reagents.getsample("MT7"),
                                    input[i],
                                    mix=(False, False))
                    assert (abs(input[i].volume - t7vol) < 0.1)
                rxs = input
            elif self.rndNum == len(
                    self.rounds) and self.finalPlus and keepCleaved:
                rxs = self.runT7Setup(
                    src=input,
                    vol=t7vol,
                    srcdil=[inp.conc.dilutionneeded() for inp in input])
                for i in range(len(input)):
                    inp = input[i]
                    if self.inputs[i]['ligand'] is not None:
                        rxs += self.runT7Setup(
                            ligands=[
                                reagents.getsample(self.inputs[i]['ligand'])
                            ],
                            src=[inp],
                            vol=t7vol,
                            srcdil=[inp.conc.dilutionneeded()])
                        prefixIn += [prefixIn[i]]
                        prefixOut += [prefixOut[i]]
                        stop += [stop[i]]
                        primerSet += [primerSet[i]]
                        names += ["%s+" % names[i]]
            elif keepCleaved:
                rxs = self.runT7Setup(
                    src=input,
                    vol=t7vol,
                    srcdil=[inp.conc.dilutionneeded() for inp in input])
            else:
                rxs = self.runT7Setup(
                    ligands=[
                        reagents.getsample(inp['ligand'])
                        for inp in self.inputs
                    ],
                    src=input,
                    vol=t7vol,
                    srcdil=[inp.conc.dilutionneeded() for inp in input])

            if self.rndNum == 1 and "template" in self.qpcrStages:
                # Initial input
                for i in range(len(rxs)):
                    q.addSamples(src=rxs[i],
                                 needDil=needDil,
                                 primers=primerSet[i],
                                 names=["%s.T" % names[i]])

            needDil = needDil * max(
                [inp.conc.dilutionneeded() for inp in input])
            self.runT7Pgm(dur=self.t7dur, vol=t7vol)
            for i in range(len(rxs)):
                rxs[i].name = "%s.t7" % names[i]

            print "Estimate usable RNA concentration in T7 reaction at %.0f nM" % self.rnaConc

            print "######## Stop ########### %.0f min" % (clock.elapsed() / 60)
            self.e.lihahome()

            print "Have %.1f ul before stop" % rxs[0].volume
            preStopVolume = rxs[0].volume
            self.addEDTA(tgt=rxs, finalconc=2)  # Stop to 2mM EDTA final

            stopDil = rxs[0].volume / preStopVolume

            if self.saveRNA:
                self.saveSamps(
                    src=rxs,
                    vol=5,
                    dil=self.saveRNADilution,
                    plate=decklayout.DILPLATE,
                    dilutant=reagents.getsample("TE8"),
                    mix=(False,
                         False))  # Save to check [RNA] on Qubit, bioanalyzer

        needDil = self.rnaConc / self.qConc / stopDil

        if "stopped" in self.qpcrStages:
            for i in range(len(rxs)):
                q.addSamples(src=rxs[i:i + 1],
                             needDil=needDil,
                             primers=primerSet[i],
                             names=["%s.stopped" % names[i]])

        print "######## RT  Setup ########### %.0f min" % (clock.elapsed() /
                                                           60)
        hiTemp = 95

        stop = ["%s-Stop" % n for n in stop]
        rt = self.runRT(src=rxs,
                        vol=rtvol,
                        srcdil=self.rtDil,
                        heatInactivate=self.rtHI,
                        hiTemp=hiTemp,
                        dur=self.rtdur,
                        incTemp=50,
                        stop=[reagents.getsample(s) for s in stop],
                        stopConc=self.stopConc
                        )  # Heat inactivate also allows splint to fold

        rxs = rt
        for i in range(len(rxs)):
            if dolig and not self.singlePrefix:
                rxs[i].name = names[i] + "." + prefixOut[i] + ".rt"
            else:
                rxs[i].name = names[i] + ".rt"

        print "RT volume= [", ",".join(["%.1f " % x.volume for x in rxs]), "]"

        needDil /= self.rtDil
        if self.rtpostdil[self.rndNum - 1] > 1:
            print "Dilution after RT: %.2f" % self.rtpostdil[self.rndNum - 1]
            self.diluteInPlace(tgt=rxs, dil=self.rtpostdil[self.rndNum - 1])
            needDil = needDil / self.rtpostdil[self.rndNum - 1]

        if self.rtSave:
            rtsv = self.saveSamps(
                src=rxs,
                vol=self.rtSaveVol,
                dil=self.rtSaveDil,
                plate=decklayout.DILPLATE,
                dilutant=reagents.getsample("TE8"),
                mix=(False, False))  # Save to check RT product on gel (2x dil)

            if "rt" in self.qpcrStages:
                for i in range(len(rxs)):
                    q.addSamples(src=rtsv[i:i + 1],
                                 needDil=needDil / 2,
                                 primers=self.rtprimers[self.rndNum - 1] if
                                 hasattr(self, 'rtprimers') else primerSet[i],
                                 names=["%s.rt" % names[i]])
        else:
            if "rt" in self.qpcrStages:
                for i in range(len(rxs)):
                    q.addSamples(src=rxs[i:i + 1],
                                 needDil=needDil,
                                 primers=self.rtprimers[self.rndNum - 1] if
                                 hasattr(self, 'rtprimers') else primerSet[i],
                                 names=["%s.rt" % names[i]])

        rtCarryForwardDil = 10
        rtCarryForwardVol = 3.5

        if self.rtCarryForward and not keepCleaved:
            # Also include RT from a prior round from here on
            for r in self.lastSaved:
                newsamp = Sample("%s.samp" % r.name, decklayout.SAMPLEPLATE)
                self.e.transfer(rxs[0].volume, r, newsamp, (False, False))
                rxs.append(newsamp)

        if dolig:
            print "######## Ligation setup  ########### %.0f min" % (
                clock.elapsed() / 60)
            extdil = 5.0 / 4
            reagents.getsample("MLigase").conc = Concentration(5)
            if self.ligInPlace:
                rxs = self.runLig(rxs,
                                  inPlace=True,
                                  srcdil=extdil,
                                  incTime=self.ligdur)
            else:
                rxs = self.runLig(rxs,
                                  inPlace=False,
                                  srcdil=extdil,
                                  vol=20,
                                  incTime=self.ligdur)

            print "Ligation volume= ", [x.volume for x in rxs]
            needDil = needDil / extdil
            if self.extpostdil[self.rndNum - 1] > 1:
                print "Dilution after extension: %.2f" % self.extpostdil[
                    self.rndNum - 1]
                self.diluteInPlace(tgt=rxs,
                                   dil=self.extpostdil[self.rndNum - 1])
                needDil = needDil / self.extpostdil[self.rndNum - 1]
                pcrdil = pcrdil * 1.0 / self.extpostdil[self.rndNum - 1]

            if self.saveDil is not None:
                ext = self.saveSamps(
                    src=rxs,
                    vol=3,
                    dil=self.saveDil,
                    dilutant=reagents.getsample("TE8"),
                    tgt=[
                        Sample("%s.ext" % n, decklayout.DILPLATE)
                        for n in names
                    ],
                    mix=(False, True))  # Save cDNA product for subsequent NGS
                if "ext" in self.qpcrStages:
                    for i in range(len(ext)):
                        # Make sure we don't take more than 2 more steps
                        maxdil = q.MAXDIL * q.MAXDIL
                        if needDil / self.saveDil > maxdil:
                            logging.notice(
                                "Diluting ext by %.0fx instead of needed %.0f to save steps"
                                % (maxdil, needDil / self.saveDil))
                        q.addSamples(src=[ext[i]],
                                     needDil=min(maxdil,
                                                 needDil / self.saveDil),
                                     primers=primerSet[i],
                                     names=["%s.ext" % names[i]],
                                     save=False)
            else:
                if "ext" in self.qpcrStages:
                    print "needDil=", needDil
                    for i in range(len(names)):
                        q.addSamples(src=[rxs[i]],
                                     needDil=needDil,
                                     primers=primerSet[i],
                                     names=["%s.ext" % names[i]])
                        isave = i + len(names)
                        if isave < len(rxs):
                            # samples restored
                            q.addSamples(src=[rxs[isave]],
                                         needDil=needDil / rtCarryForwardDil,
                                         primers=primerSet[isave])
        else:
            extdil = 1
            self.extpostdil[self.rndNum - 1] = 1
            if self.rtpostdil[self.rndNum - 1] > 1:
                pcrdil = pcrdil * 1.0 / self.rtpostdil[self.rndNum - 1]

        totalDil = stopDil * self.rtDil * self.rtpostdil[
            self.rndNum - 1] * extdil * self.extpostdil[self.rndNum - 1]
        fracRetained = rxs[0].volume / (t7vol * totalDil)
        print "Total dilution from T7 to Pre-pcr Product = %.2f*%.2f*%.2f*%.2f*%.2f = %.2f, fraction retained=%.0f%%" % (
            stopDil, self.rtDil, self.rtpostdil[self.rndNum - 1], extdil,
            self.extpostdil[self.rndNum - 1], totalDil, fracRetained * 100)

        if self.rtCarryForward and not keepCleaved:
            # Remove the extra samples
            assert (len(self.lastSaved) > 0)
            rxs = rxs[:len(rxs) - len(self.lastSaved)]
            self.lastSaved = []

        if len(rxs) > len(input):
            # Have extra samples due when self.finalPlus is True
            rxs = rxs[0:len(input)]  # Only keep -target products
            prefixOut = prefixOut[0:len(input)]
            prefixIn = prefixIn[0:len(input)]
            stop = stop[0:len(input)]

        if self.dopcr and not (keepCleaved and self.noPCRCleave):
            print "######### PCR ############# %.0f min" % (clock.elapsed() /
                                                            60)
            maxvol = max([r.volume for r in rxs])
            print "PCR Volume: %.1f, Dilution: %.1f, volumes available for PCR: [%s]" % (
                pcrvol, pcrdil, ",".join(["%.1f" % r.volume for r in rxs]))

            initConc = needDil * self.qConc / pcrdil
            if keepCleaved:
                initConc = initConc * self.cleavage  # Only use cleaved as input conc
            else:
                initConc = initConc * (1 - self.cleavage)

            gain = pcrgain(initConc, 400, cycles)
            finalConc = min(200, initConc * gain)
            print "Estimated starting concentration in PCR = %.1f nM, running %d cycles -> %.0f nM\n" % (
                needDil * self.qConc / pcrdil, cycles, finalConc)
            nsplit = int(math.ceil(pcrvol * 1.0 / self.maxPCRVolume))
            print "Split each PCR into %d reactions" % nsplit
            minsrcdil = 1 / (1 - 1.0 / 3 - 1.0 / 4)
            sampNeeded = pcrvol / pcrdil
            if self.rtCarryForward and keepCleaved:
                sampNeeded += rtCarryForwardVol
            maxvol = max([r.volume for r in rxs])
            minvol = min([r.volume for r in rxs])
            if keepCleaved and self.rtCarryForward:
                assert (len(rxs) == len(rtCarryForward))
                print "Saving %.1f ul of each pre-PCR sample" % (
                    rtCarryForwardVol)
                self.lastSaved = [
                    Sample("%s.sv" % x.name, decklayout.DILPLATE) for x in rxs
                ]
                for i in range(len(rxs)):
                    # Save with rtCarryForwardDil dilution to reduce amount of RT consumed (will have Ct's 2-3 lower than others)
                    self.e.transfer(rtCarryForwardVol, rxs[i],
                                    self.lastSaved[i], (False, False))
                    self.e.transfer(
                        rtCarryForwardVol * (rtCarryForwardDil - 1),
                        decklayout.WATER, self.lastSaved[i], (False, True)
                    )  # Use pipette mixing -- shaker mixing will be too slow

            #print "NSplit=",nsplit,", PCR vol=",pcrvol/nsplit,", srcdil=",pcrdil,", input vol=",pcrvol/nsplit/pcrdil
            minvol = min([r.volume for r in rxs])
            maxpcrvol = (minvol - 15 - 1.4 * nsplit) * pcrdil
            if maxpcrvol < pcrvol:
                print "Reducing PCR volume from %.1ful to %.1ful due to limited input" % (
                    pcrvol, maxpcrvol)
                pcrvol = maxpcrvol

            if keepCleaved:
                master = "MTaqC"
            else:
                master = "MTaqU"

            if self.barcoding:
                primers = self.bcprimers[self.rndNum - 1]
                if primers is not None and nsplit > 1:
                    primers = primers * nsplit
            else:
                primers = None

            if primers is None:
                primers = [("T7%sX" % x).replace("T7T7", "T7")
                           for x in prefixOut] * nsplit

            print "Running PCR with master=", master, ", primers=", primers
            pcr = self.runPCR(src=rxs * nsplit,
                              vol=pcrvol / nsplit,
                              srcdil=pcrdil,
                              ncycles=cycles,
                              primers=primers,
                              usertime=self.usertime if keepCleaved else None,
                              fastCycling=False,
                              inPlace=False,
                              master=master,
                              lowhi=self.lowhi,
                              annealTemp=57)
            if keepCleaved and self.regenPCRCycles is not None:
                # Regenerate prefix
                pcr2 = self.runPCR(src=pcr,
                                   vol=self.regenPCRVolume,
                                   srcdil=self.regenPCRDilution,
                                   ncycles=self.regenPCRCycles,
                                   primers=None,
                                   usertime=None,
                                   fastCycling=False,
                                   inPlace=False,
                                   master="MTaqR",
                                   lowhi=self.lowhi,
                                   annealTemp=55)
                # Add BT575p for 1 more cycle
                for p in pcr2:
                    self.e.transfer(p.volume * 0.5 / 10,
                                    reagents.getsample("Unclvd-Stop"), p,
                                    (False, False))
                # One more cycle
                cycling = ' TEMP@95,30 TEMP@55,30 TEMP@68,30 TEMP@25,2'
                worklist.pyrun('PTC\\ptcsetpgm.py rfin %s' % (cycling))
                self.e.runpgm("rfin",
                              5.0,
                              False,
                              max([p.volume for p in pcr2]),
                              hotlidmode="CONSTANT",
                              hotlidtemp=100)
                pcr = pcr2  # Use 2nd PCR as actual output

            if len(pcr) <= len(names):
                # Don't relabel if we've split
                for i in range(len(pcr)):
                    pcr[i].name = names[i] + ".pcr"

            #print "Volume remaining in PCR input source: [",",".join(["%.1f"%r.volume for r in rxs]),"]"
            needDil = finalConc / self.qConc
            print "Projected final concentration = %.0f nM" % (needDil *
                                                               self.qConc)
            for i in range(len(pcr)):
                pcr[i].conc = Concentration(stock=finalConc,
                                            final=None,
                                            units='nM')

            if self.pcrSave:
                # Save samples at 1x (move all contents -- can ignore warnings)
                maxSaveVol = (100
                              if self.savedilplate else 1500) * 1.0 / nsplit

                if self.finalRound and nsplit == 1 and self.savedilplate:
                    print "Skipping save of final PCR"
                    sv = pcr
                else:
                    sv = self.saveSamps(
                        src=pcr[:len(rxs)],
                        vol=[
                            min([maxSaveVol, x.volume]) for x in pcr[:len(rxs)]
                        ],
                        dil=1,
                        plate=(decklayout.DILPLATE if self.savedilplate else
                               decklayout.EPPENDORFS),
                        atEnd=self.savePCRAtEnd)
                    if nsplit > 1:
                        # Combine split
                        for i in range(len(rxs), len(rxs) * nsplit):
                            self.e.transfer(min([maxSaveVol, pcr[i].volume]),
                                            pcr[i],
                                            sv[i % len(sv)],
                                            mix=(False,
                                                 i >= len(rxs) * (nsplit - 1)))
                        # Correct concentration (above would've assumed it was diluted)
                        for i in range(len(sv)):
                            sv[i].conc = pcr[i].conc

                if "pcr" in self.qpcrStages:
                    for i in range(len(sv)):
                        q.addSamples(sv[i],
                                     needDil,
                                     primers=primerSet[i],
                                     names=["%s.pcr" % names[i]])

                processEff = 0.5  # Estimate of overall efficiency of process
                print "Have %.2f pmoles of product (%.0f ul @ %.1f nM)" % (
                    sv[0].volume * sv[0].conc.stock / 1000, sv[0].volume,
                    sv[0].conc.stock)
                return sv
            else:
                assert "pcr" not in self.qpcrStages  ## Not implemented
                return pcr[:len(rxs)]
        elif self.noPCRCleave:
            print "Dilution instead of PCR: %.2f" % self.nopcrdil
            # Need to add enough t7prefix to compensate for all of the Stop primer currently present, regardless of whether it is for cleaved or uncleaved
            # Will result in some short transcripts corresponding to the stop primers that are not used for cleaved product, producing just GGG_W_GTCTGC in the next round.  These would be reverse-trancribed, but may compete for T7 yield
            t7prefix = reagents.getsample("BT88")
            dil = self.extpostdil[self.rndNum - 1] * userDil
            stopconc = 1000.0 / dil
            bt88conc = t7prefix.conc.stock
            relbt88 = stopconc / bt88conc
            print "Using EXT with %.0fnM of stop oligo as input to next T7, need %.2ful of BT88@%.0fnM per ul of sample" % (
                stopconc, relbt88, bt88conc)
            for r in rxs:
                vol = r.volume * relbt88
                t7prefix.conc.final = t7prefix.conc.stock * vol / (r.volume +
                                                                   vol)
                r.conc.final = r.conc.stock * r.volume / (r.volume + vol)
                self.e.transfer(vol, t7prefix, r, mix=(False, False))

            if self.nopcrdil > (1 + relbt88):
                self.diluteInPlace(tgt=rxs,
                                   dil=self.nopcrdil / (1.0 + relbt88))
                needDil = needDil / self.nopcrdil
                print "Dilution of EXT product: %.2fx * %.2fx = %2.fx\n" % (
                    1 + relbt88, self.nopcrdil / (1 + relbt88), self.nopcrdil)
            else:
                print "Dilution of EXT product: %.2fx\n" % (1 + relbt88)

            return rxs
        else:
            return rxs
Esempio n. 10
0
    def pgm(self):
        q = QSetup(self, maxdil=self.maxdilstep, debug=False, mindilvol=60)
        self.e.addIdleProgram(q.idler)

        if self.barcoding:
            # Setup barcode primers for cleaved rounds only
            self.bcprimers = [[
                "BC-%s-R%d_T7" % (inp['ligand'], r + 1) for inp in self.inputs
            ] if self.rounds[r] == 'C' else None
                              for r in range(len(self.rounds))]
            for bcp in self.bcprimers:
                if bcp is not None:
                    for p in ["P-%s" % pp for pp in bcp]:
                        if not reagents.isReagent(p):
                            reagents.add(name=p,
                                         conc=4,
                                         extraVol=30,
                                         plate=decklayout.REAGENTPLATE,
                                         well="B2")
                        s = reagents.getsample(p)  # Force allocation of a well
                        print "Adding %s to reagents at well %s" % (
                            p, s.plate.wellname(s.well))
            print "BC primers=", self.bcprimers

        # Add any missing fields to inputs
        for i in range(len(self.inputs)):
            if 'ligand' not in self.inputs[i]:
                self.inputs[i]['ligand'] = None
            if 'round' not in self.inputs[i]:
                self.inputs[i]['round'] = None
            if 'name' not in self.inputs[i]:
                if self.inputs[i]['ligand'] is None:
                    self.inputs[i]['name'] = '%s_%d_R%d' % (
                        self.inputs[i]['prefix'], self.inputs[i]['ID'],
                        self.inputs[i]['round'])
                else:
                    self.inputs[i]['name'] = '%s_%d_R%d_%s' % (
                        self.inputs[i]['prefix'], self.inputs[i]['ID'],
                        self.inputs[i]['round'], self.inputs[i]['ligand'])

        # Add templates
        if self.directT7:
            self.srcs = self.addTemplates(
                [inp['name'] for inp in self.inputs],
                stockconc=self.tmplFinalConc / self.templateDilution,
                finalconc=self.tmplFinalConc,
                plate=decklayout.SAMPLEPLATE,
                looplengths=[inp['looplength'] for inp in self.inputs],
                initVol=self.t7vol[0] * self.templateDilution,
                extraVol=0)
        else:
            self.srcs = self.addTemplates(
                [inp['name'] for inp in self.inputs],
                stockconc=self.tmplFinalConc / self.templateDilution,
                finalconc=self.tmplFinalConc,
                plate=decklayout.DILPLATE,
                looplengths=[inp['looplength'] for inp in self.inputs],
                extraVol=15)

        t7in = [s.getsample() for s in self.srcs]

        if "negative" in self.qpcrStages:
            q.addSamples(decklayout.SSDDIL, 1, self.allprimers,
                         save=False)  # Negative controls
        if "reference" in self.qpcrStages:
            q.addReferences(dstep=10,
                            nsteps=5,
                            primers=["T7WX", "MX", "T7X"],
                            ref=reagents.getsample("BT5310"),
                            nreplicates=1)
            q.addReferences(dstep=10,
                            nsteps=5,
                            primers=["T7WX", "MX", "T7X"],
                            ref=reagents.getsample("BT5310"),
                            nreplicates=1)

        # Save RT product from first (uncleaved) round and then use it during 2nd (cleaved) round for ligation and qPCR measurements
        self.rndNum = 0
        self.nextID = self.firstID
        curPrefix = [inp['prefix'] for inp in self.inputs]
        r1 = t7in

        for roundType in self.rounds:
            # Run a single round of roundType with r1 as input
            # roundType is either "U" for uncleaved, or a new prefix for a cleaved round (with "T" being a T7 prepend)
            # Set r1 to new output at end

            # Computed output prefix
            if roundType == 'U':
                prefixOut = curPrefix
                stop = ["Unclvd" for p in curPrefix]
            else:
                if roundType == 'T':
                    stop = ['T7%s' % p for p in curPrefix]
                    prefixOut = curPrefix
                elif any([p == roundType for p in curPrefix]):
                    logging.error(
                        "Round %d is a cleaved round but goes to %s without changing prefix"
                        % (self.rndNum, roundType))
                    assert (False)
                else:
                    prefixOut = [roundType for p in curPrefix]
                    stop = prefixOut

            # May be explicitly overridden
            for i in range(len(self.inputs)):
                if 'stop' in self.inputs[i]:
                    if isinstance(self.inputs[i]['stop'], list):
                        assert (len(self.inputs[i]['stop']) == len(
                            self.rounds))
                        t = self.inputs[i]['stop'][self.rndNum]
                    else:
                        t = self.inputs[i]['stop']
                    if (roundType == 'U') != (t == 'U'):
                        print "Attempt to override round %d (type %s) with a input-specific round type of %s" % (
                            self.rndNum, roundType, t)
                        assert (False)
                    if roundType != 'U':
                        if t == 'T':
                            stop[i] = 'T7%s' % curPrefix[i]
                            prefixOut[i] = curPrefix[i]
                        else:
                            stop[i] = t
                            prefixOut[i] = t

            self.rndNum = self.rndNum + 1
            self.finalRound = self.rndNum == len(self.rounds)

            r1 = self.oneround(q,
                               r1,
                               prefixOut=prefixOut,
                               stop=stop,
                               prefixIn=curPrefix,
                               keepCleaved=(roundType != 'U'),
                               rtvol=self.rtvol[self.rndNum - 1],
                               t7vol=self.t7vol[self.rndNum - 1],
                               cycles=self.pcrcycles[self.rndNum - 1],
                               pcrdil=self.pcrdil[self.rndNum - 1],
                               pcrvol=self.pcrvol[self.rndNum - 1],
                               dolig=self.allLig or (roundType != 'U'))

            for i in range(len(r1)):
                r1[i].name = "%s_%d" % (prefixOut[i], self.nextID)
                if self.inputs[i]['round'] is not None:
                    r1[i].name = "%s_R%d%c" % (r1[i].name,
                                               self.inputs[i]['round'] +
                                               self.rndNum, roundType)
                if self.inputs[i]['ligand'] is not None:
                    r1[i].name = "%s_%s" % (r1[i].name,
                                            self.inputs[i]['ligand'])
                print "Used ID ", self.nextID, " for ", r1[i].name, ": ", r1[i]
                self.nextID += 1
                r1[i].conc.final = r1[i].conc.stock * self.templateDilution
            curPrefix = prefixOut

        if "finalpcr" in self.qpcrStages:
            for i in range(len(r1)):
                if self.singlePrefix:
                    q.addSamples(src=r1[i],
                                 needDil=r1[i].conc.stock / self.qConc,
                                 primers=["T7X", "MX"])
                else:
                    q.addSamples(src=r1[i],
                                 needDil=r1[i].conc.stock / self.qConc,
                                 primers=["T7X", prefixOut[i] + "X", "MX"])

        print "######### qPCR ########### %.0f min" % (clock.elapsed() / 60)
        self.allprimers = q.allprimers()
        q.run(confirm=self.qpcrWait)
Esempio n. 11
0
    def barcoding(self, names, left, right):
        """Perform barcoding of the given inputs;  rsrsc,left,right should all be equal length"""
        pcrcycles = [5, 10]
        pcr1inputdil = 10
        pcr1vol = 30
        pcr1postdil = 100.0 / pcr1vol

        pcr2dil = 10*pcr1postdil
        pcr2vol = 40.0

        samps = [reagents.getsample(s) for s in names]
        print("Inputs:")
        for i in range(len(samps)):
            print("%2s %-10s %8s-%-8s  %s" % (
                samps[i].plate.wellname(samps[i].well), self.inputs[i]['name'], left[i], right[i], str(samps[i].conc)))

        wellnum = 5
        for s in left + right:
            primer = "P-" + s
            if not reagents.isReagent(primer):
                reagents.add(primer, conc=Concentration(2.67, 0.4, 'uM'), extraVol=30, plate=decklayout.REAGENTPLATE,
                             well=decklayout.REAGENTPLATE.wellname(wellnum))
                wellnum += 1
        for s in samps:
            # Dilute down to desired conc
            dil = s.conc.stock / self.pcr1inputconc / pcr1inputdil
            if dil < 1.0:
                logging.error("Input %s requires dilution of %.2f" % (s.name, dil))
            elif dil > 1.0:
                dilvol = s.volume * dil
                if dilvol > 150.0:
                    maxdil = 150.0 / s.volume
                    logging.info(
                        "Dilution of input %s (%.1f ul) by %.2f would require %.1f ul -- only diluting by %.1fx" % (
                            s.name, s.volume, dil, dilvol, maxdil))
                    dil = maxdil
                self.diluteInPlace(tgt=[s], dil=dil)
                print("Diluting %s by %.1f" % (s.name, dil))

        print("### PCR1 #### (%.0f min)" % (clock.elapsed() / 60.0))

        pcr1 = self.runPCR(src=samps, srcdil=[s.conc.stock / self.pcr1inputconc for s in samps], ncycles=pcrcycles[0],
                           vol=pcr1vol,
                           primers=[[left[i], right[i]] for i in range(len(left))], usertime=30, fastCycling=False,
                           inPlace=False, master="MPCR1", kapa=False, annealTemp=57)

        pcr1finalconc = self.pcr1inputconc * 2 ** pcrcycles[0]
        print("PCR1 output concentration = %.1f nM" % pcr1finalconc)

        if pcr1postdil > 1:
            pcr1finalconc /= pcr1postdil
            print("Post dilute PCR1 by %.2fx to %.3f nM " % (pcr1postdil, pcr1finalconc))
            self.diluteInPlace(tgt=pcr1, dil=pcr1postdil)

        for x in pcr1:
            x.conc = Concentration(stock=pcr1finalconc, units='nM')

        if len(pcrcycles) > 1:
            # Second PCR with 235p/236p on mixture (use at least 4ul of prior)
            print("### PCR2 #### (%.0f min)" % (clock.elapsed() / 60.0))

            pcr2 = self.runPCR(src=pcr1, srcdil=pcr2dil / pcr1postdil, vol=pcr2vol, ncycles=pcrcycles[1],
                               primers=None, fastCycling=False, master="MPCR2", kapa=True, annealTemp=64)

            pcr2finalconc = pcr1finalconc / (pcr2dil / pcr1postdil) * 2 ** pcrcycles[1]
            print("PCR2 final conc = %.1f nM" % pcr2finalconc)
            if pcr2finalconc > 200:
                print("Capping at 200nM")
                pcr2finalconc = 200

            for x in pcr2:
                x.conc = Concentration(stock=pcr2finalconc, units='nM')

            if self.doqpcr:
                self.q.addSamples(src=pcr2, needDil=pcr2finalconc * 1e-9 / self.qconc, primers=self.qprimers)
            res = pcr2
        else:
            self.q.addSamples(src=pcr1, needDil=pcr1finalconc / (self.qconc * 1e9), primers=self.qprimers, save=True,
                              nreplicates=1)
            res = pcr1

        return res
Esempio n. 12
0
    def runPCR(self,primers,src,srcdil,vol=None,tgt=None,ncycles=20,usertime=None,fastCycling=False,inPlace=False,master="MTaq",annealTemp=None,kapa=False):
        ## PCR
        if inPlace:
            if vol!=None:
                print "runPCR: cannot specify volume when using inPlace=True, srcdil and input volume determine reaction volume"
                assert(False)
            if tgt!=None:
                print "runPCR: cannot specify tgt when using inPlace=True"
                assert(False)
            [primers,src,vol,srcdil]=listify([primers,src,vol,srcdil])
            vol=[src[i].volume*srcdil[i] for i in range(len(src))]
            tgt=src
        else: 
            [primers,src,tgt,vol,srcdil]=listify([primers,src,tgt,vol,srcdil])
            for i in range(len(tgt)):
                if tgt[i] is None:
                    if isinstance(primers[i],list):
                        tgt[i]=Sample("%s.P%s"%(src[i].name,"+".join(primers[i])),src[i].plate)
                    else:
                        tgt[i]=Sample("%s.P%s"%(src[i].name,primers[i]),src[i].plate)

        # Adjust source dilution
        for i in range(len(src)):
            src[i].conc=Concentration(srcdil[i],1)
        
        logging.notice( "primer="+str(primers))

        # Add reagent entries for any missing primers
        if isinstance(primers[0],list):
            allprimers=[x for y in primers for x in y]
        else:
            allprimers=primers
        for up in set(allprimers):
            s="P-%s"%up
            if not reagents.isReagent(s):
                reagents.add(name=s,conc=4,extraVol=30)

        if isinstance(primers[0],list):
            # Multiple primers
            if inPlace:
                assert len(primers[0])==2
                self.runRxInPlace(src,vol,reagents.getsample(master),master2=[reagents.getsample("P-%s"%p[0]) for p in primers],master3=[reagents.getsample("P-%s"%p[1]) for p in primers],returnPlate=False)
            else:
                for i in range(len(primers)):
                    self.e.stage('PCR%d'%i,[reagents.getsample(master)]+[reagents.getsample("P-%s"%s) for s in primers[i]],src[i:i+1] ,tgt[i:i+1],vol[i:i+1],destMix=False)
                #self.e.shakeSamples(tgt,returnPlate=False)
        else:
            # Single primer
            if inPlace:
                self.runRxInPlace(src,vol,reagents.getsample(master),master2=[reagents.getsample("P-%s"%p) for p in primers],returnPlate=False)
            else:
                for up in set(primers):
                    self.e.stage('PCR%s'%up,[reagents.getsample(master),reagents.getsample("P-%s"%up)],[src[i] for i in range(len(src)) if primers[i]==up],[tgt[i] for i in range(len(tgt)) if primers[i]==up],[vol[i] for i in range(len(vol)) if primers[i]==up],destMix=False)
                #self.e.shakeSamples(tgt,returnPlate=False)

        pgm="PCR%d"%ncycles

        if usertime is None:
            runTime=0
        else:
            runTime=usertime

        if annealTemp is None:
            annealTemp=60 if kapa else 57

        meltTemp=98 if kapa else 95
        hotTime=180 if kapa else 30
        extTemp=72 if kapa else 68
        
        if fastCycling:
            cycling='TEMP@37,%d TEMP@95,%d TEMP@%.1f,10 TEMP@%.1f,10 TEMP @%.1f,1 GOTO@3,%d TEMP@%.1f,60 TEMP@25,2'%(1 if usertime is None else usertime*60,hotTime,meltTemp,annealTemp,extTemp,ncycles-1,extTemp)
            runTime+=hotTime/60+2.8+1.65*ncycles
        else:
            cycling='TEMP@37,%d TEMP@95,%d TEMP@%.1f,30 TEMP@%.1f,30 TEMP@%.1f,30 GOTO@3,%d TEMP@%.1f,60 TEMP@25,2'%(1 if usertime is None else usertime*60,hotTime,meltTemp,annealTemp,extTemp,ncycles-1,extTemp)
            runTime+=hotTime/60+2.8+3.0*ncycles
            
        print "PCR volume=[",",".join(["%.1f"%t.volume for t in tgt]), "], srcdil=[",",".join(["%.1fx"%s for s in srcdil]),"], program: %s"%cycling

        worklist.pyrun('PTC\\ptcsetpgm.py %s %s'%(pgm,cycling))
        self.e.runpgm(pgm,runTime,False,max(vol),hotlidmode="CONSTANT",hotlidtemp=100)
        # Mark samples as mixed (by thermal convection)
        print "Marking samples as mixed (by thermal convection)"
        for t in tgt:
            t.wellMixed=True
            t.lastMixed=clock.elapsed()
        #self.e.shakeSamples(tgt,returnPlate=True)
        return tgt
Esempio n. 13
0
    def oneround(self, q, inputs, prefixOut, stop, prefixIn, keepCleaved, t7vol, rtvol, pcrdil, cycles, pcrvol, dolig,pcrtgt=None):
        primerSet=[set(["REF","T7X",prefixIn[i]+"X",prefixOut[i]+"X"]+(["MX"] if self.useMX else [])) for i in range(len(prefixIn))]
        if self.extraQPCRPrimers is not None:
            primerSet=[set(list(p) + self.extraQPCRPrimers) for p in primerSet]
            print("primerSet=",primerSet)
            
        if keepCleaved:
            print("Starting new cleavage round, will add prefix: ",prefixOut)
            assert dolig
        else:
            print("Starting new uncleaved round, will retain prefix: ",prefixIn)
        print("stop=",stop,"prefixOut=",prefixOut,", prefixIn=",prefixIn,",t7vol=",round(t7vol,ndigits=2),",rtvol=",rtvol,",pcrdil=",pcrdil,",cycles=",cycles,",dolig=",dolig)
        if self.rtCarryForward:
            assert dolig
            
        names=[i.name for i in inputs]
            
        if self.rnaInput:
            rxs=inputs
            stopDil=1
        else:
            print("######## T7 ########### %.0f min"%(clock.elapsed()/60))
            db.pushStatus("T7")
            print("Inputs:  (t7vol=%.2f)"%t7vol)
            for inp in inputs:
                if inp.conc.units=='nM':
                    print("    %s:  %.1ful@%.1f %s, use %.1f ul (%.3f pmoles)"%(inp.name,inp.volume,inp.conc.stock,inp.conc.units,t7vol/inp.conc.dilutionneeded(), t7vol*inp.conc.final/1000))
                else:
                    print("    %s:  %.1ful@%.1f %s, use %.1f ul"%(inp.name,inp.volume,inp.conc.stock,inp.conc.units,t7vol/inp.conc.dilutionneeded()))
                # inp.conc.final=inp.conc.stock*self.templateDilution
            units=list(set([inp.conc.units for inp in inputs]))
            if len(units)>1:
                print("Inputs have inconsistent concentration units: ",units)
                assert False
            if units[0]=='nM':
                needDil = max([inp.conc.stock for inp in inputs]) * 1.0 / self.qConc
            else:
                needDil = 100 / self.qConc  # Assume 100nM

            if self.directT7 and  self.rndNum==1:
                # Just add ligands and MT7 to each well
                mconc=reagents.getsample("MT7").conc.dilutionneeded()
                for i in range(len(inputs)):
                    watervol=t7vol*(1-1/mconc) - inputs[i].volume
                    if watervol<-0.1:
                        print("Negative amount of water (%.1f ul) needed for T7 setup"%watervol)
                        assert False
                    elif watervol>0.1:
                        self.e.transfer(watervol, decklayout.WATER, inputs[i], mix=(False, False))
                    self.e.transfer(t7vol / mconc, reagents.getsample("MT7"), inputs[i], mix=(False, False))
                    assert(abs(inputs[i].volume - t7vol) < 0.1)
                # Add ligands last in case they crash out when they hit aqueous;  this way, they'll be as dilute as possible
                if keepCleaved:
                    for i in range(len(inputs)):
                        if self.inputs[i]['negligand'] is not None:
                            negligand=reagents.getsample(self.inputs[i]['negligand'])
                            self.e.transfer(t7vol / negligand.conc.dilutionneeded(), negligand, inputs[i], mix=(False, False))
                            names[i]+="+"
                else:
                    for i in range(len(inputs)):
                        if self.inputs[i]['ligand'] is not None:
                            ligand=reagents.getsample(self.inputs[i]['ligand'])
                            self.e.transfer(t7vol / ligand.conc.dilutionneeded(), ligand, inputs[i], mix=(False, False))
                            names[i]+="+"
                rxs=inputs
                self.e.shakeSamples(inputs,returnPlate=True)
            elif self.rndNum==len(self.rounds) and self.finalPlus and keepCleaved:
                rxs = self.runT7Setup(ligands=[reagents.getsample(inp['ligand']) for inp in self.inputs],src=inputs, vol=t7vol, srcdil=[inp.conc.dilutionneeded() for inp in inputs])
                for i in range(len(inputs)):
                    inp=inputs[i]
                    if self.inputs[i]['ligand'] is not None:
                        rxs += self.runT7Setup(ligands=[reagents.getsample(self.inputs[i]['ligand'])],src=[inp],vol=t7vol,srcdil=[inp.conc.dilutionneeded()])
                        prefixIn+=[prefixIn[i]]
                        prefixOut+=[prefixOut[i]]
                        stop+=[stop[i]]
                        primerSet+=[primerSet[i]]
                        names+=["%s+"%names[i]]
            elif keepCleaved:
                rxs = self.runT7Setup(ligands=[reagents.getsample(inp['negligand']) for inp in self.inputs], src=inputs, vol=t7vol, srcdil=[inp.conc.dilutionneeded() for inp in inputs])
            else:
                rxs = self.runT7Setup(ligands=[reagents.getsample(inp['ligand']) for inp in self.inputs], src=inputs, vol=t7vol, srcdil=[inp.conc.dilutionneeded() for inp in inputs])

            if self.rndNum==1 and "template" in self.qpcrStages:
                # Initial input 
                for i in range(len(rxs)):
                    q.addSamples(src=rxs[i],needDil=needDil,primers=primerSet[i],names=["%s.T"%names[i]])

            self.runT7Pgm(dur=self.t7dur,vol=t7vol)
            for i in range(len(rxs)):
                rxs[i].name="%s.t7"%names[i]

            self.e.lihahome()
            print("Estimate usable RNA concentration in T7 reaction at %.0f nM"%self.rnaConc)

            if self.rndNum==1:
                worklist.userprompt("T7 Incubation Started",120)
            
            self.e.waitpgm()   # So elapsed time will be updated
            db.popStatus()
            if self.edtastop:
                print("######## Stop ########### %.0f min"%(clock.elapsed()/60))
                db.pushStatus("Stop")
                print("Have %.1f ul before stop"%rxs[0].volume)
                preStopVolume=rxs[0].volume
                self.addEDTA(tgt=rxs,finalconc=2)	# Stop to 2mM EDTA final
                db.popStatus("Stop")

                stopDil=rxs[0].volume/preStopVolume
            else:
                stopDil=1

            if self.pauseAfterStop:
                worklist.userprompt("Post EDTA pause")
                
            if self.saveRNA:
                self.saveSamps(src=rxs,vol=self.saveRNAVolume,dil=self.saveRNADilution,plate=self.savePlate,dilutant=reagents.getsample("TE8"),mix=(False,False))   # Save to check [RNA] on Qubit, bioanalyzer

        needDil = self.rnaConc/self.qConc/stopDil

        if "stopped" in self.qpcrStages:
            for i in range(len(rxs)):
                q.addSamples(src=rxs[i:i+1],needDil=needDil,primers=primerSet[i],names=["%s.stopped"%names[i]])
        
        print("######## RT  Setup ########### %.0f min"%(clock.elapsed()/60))
        db.pushStatus("RT")
        hiTemp=95

        stop=["%s-Stop"%n for n in stop]
        rt=self.runRT(src=rxs,vol=rtvol,srcdil=self.rtDil,heatInactivate=self.rtHI,hiTemp=hiTemp,dur=self.rtdur,incTemp=50,stop=[reagents.getsample(s) for s in stop],stopConc=self.stopConc)    # Heat inactivate also allows splint to fold
        
        rxs=rt
        for i in range(len(rxs)):
            if dolig and not self.singlePrefix:
                rxs[i].name=names[i]+"."+prefixOut[i]+".rt"
            else:
                rxs[i].name=names[i]+".rt"

        print("RT volume= [",",".join(["%.1f "%x.volume for x in rxs]),"]")
        
        needDil /=self.rtDil
        if self.rtpostdil[self.rndNum-1]>1:
            print("Dilution after RT: %.2f"%self.rtpostdil[self.rndNum-1])
            self.diluteInPlace(tgt=rxs,dil=self.rtpostdil[self.rndNum-1])
            needDil=needDil/self.rtpostdil[self.rndNum-1]

        # Discard extra volume of any sample that has more than current rt volume so that we can shake at high speed
        for r in Sample.getAllOnPlate(rxs[0].plate):
            if r not in rxs and r.volume>max(15+1.4,rxs[0].volume)+4:
                remove=r.volume-(15+1.4)
                oldvol=r.volume
                if r.lastMixed is None:
                    r.lastMixed=clock.elapsed  # Override since we don't care about mixing for disposal
                self.e.dispose(remove,r)
                print("Discarding some of %s to reduce volume from %.1f to %.1f to allow faster shaking"%(r.name,oldvol,r.volume))

        print("RT volume= ",[x.volume for x in rxs])
        self.e.shakeSamples(rxs)
        
        if self.rtSave:
            rtsv=self.saveSamps(src=rxs,vol=self.rtSaveVol,dil=self.rtSaveDil,plate=self.savePlate,dilutant=reagents.getsample("TE8"),mix=(False,False))   # Save to check RT product on gel (2x dil)

            if "rt" in self.qpcrStages:
                for i in range(len(rxs)):
                    q.addSamples(src=rtsv[i:i+1],needDil=needDil/2,primers=self.rtprimers[self.rndNum-1] if hasattr(self,'rtprimers') else primerSet[i],names=["%s.rt"%names[i]])
        else:
            if "rt" in self.qpcrStages:
                for i in range(len(rxs)):
                    q.addSamples(src=rxs[i:i+1],needDil=needDil,primers=self.rtprimers[self.rndNum-1] if hasattr(self,'rtprimers') else primerSet[i],names=["%s.rt"%names[i]])

        rtCarryForwardDil=10
        rtCarryForwardVol=3.5

        if self.rtCarryForward and not keepCleaved:
            # Also include RT from a prior round from here on
            for r in self.lastSaved:
                newsamp=Sample("%s.samp"%r.name,decklayout.SAMPLEPLATE)
                self.e.transfer(rxs[0].volume,r,newsamp,(False,False))
                rxs.append(newsamp)
        db.popStatus()

        if dolig:
            print("######## Ligation setup  ########### %.0f min"%(clock.elapsed()/60))
            db.pushStatus("Ligation")
            extdil=5.0/4
            reagents.getsample("MLigase").conc=Concentration(5)
            if self.ligInPlace:
                rxs=self.runLig(rxs,inPlace=True,srcdil=extdil,incTime=self.ligdur)
            else:
                rxs=self.runLig(rxs,inPlace=False,srcdil=extdil,vol=20,incTime=self.ligdur)

            print("Ligation volume= ",[x.volume for x in rxs])
            needDil=needDil/extdil
            if self.extpostdil[self.rndNum-1]>1:
                print("Dilution after extension: %.2f"%self.extpostdil[self.rndNum-1])
                self.diluteInPlace(tgt=rxs,dil=self.extpostdil[self.rndNum-1])
                needDil=needDil/self.extpostdil[self.rndNum-1]
                pcrdil=pcrdil*1.0/self.extpostdil[self.rndNum-1]
                
            if self.saveDil is not None:
                ext=self.saveSamps(src=rxs,vol=3,dil=self.saveDil,dilutant=reagents.getsample("TE8"),tgt=[Sample("%s.ext"%n,self.savePlate) for n in names],mix=(False,True))   # Save cDNA product for subsequent NGS
                if "ext" in self.qpcrStages:
                    for i in range(len(ext)):
                        # Make sure we don't take more than 2 more steps
                        maxdil=q.MAXDIL*q.MAXDIL
                        if needDil/self.saveDil>maxdil:
                            logging.notice( "Diluting ext by %.0fx instead of needed %.0f to save steps"%(maxdil,needDil/self.saveDil))
                        pset=primerSet[i]
                        if "extraQPCR" in self.inputs[i]:
                            pset.udpate(self.inputs[i]["extraQPCR"])
                        q.addSamples(src=[ext[i]],needDil=min(maxdil,needDil/self.saveDil),primers=pset,names=["%s.ext"%names[i]],save=False)
            else:
                if "ext" in self.qpcrStages:
                    print("needDil=",needDil)
                    for i in range(len(names)):
                        pset=primerSet[i]
                        if "extraQPCR" in self.inputs[i]:
                            pset.update(self.inputs[i]["extraQPCR"])
                        q.addSamples(src=[rxs[i]],needDil=needDil,primers=pset,names=["%s.ext"%names[i]])
                        isave=i+len(names)
                        if isave<len(rxs):
                            # samples restored
                            q.addSamples(src=[rxs[isave]],needDil=needDil/rtCarryForwardDil,primers=primerSet[isave])
            db.popStatus()
        else:
            extdil=1
            self.extpostdil[self.rndNum-1]=1
            if self.rtpostdil[self.rndNum-1]>1:
                pcrdil=pcrdil*1.0/self.rtpostdil[self.rndNum-1]

        totalDil=stopDil*self.rtDil*self.rtpostdil[self.rndNum-1]*extdil*self.extpostdil[self.rndNum-1]
        fracRetained=rxs[0].volume/(t7vol*totalDil)
        print("Total dilution from T7 to Pre-pcr Product = %.2f*%.2f*%.2f*%.2f*%.2f = %.2f, fraction retained=%.0f%%"%(stopDil,self.rtDil,self.rtpostdil[self.rndNum-1],extdil,self.extpostdil[self.rndNum-1],totalDil,fracRetained*100))

        if self.rtCarryForward and not keepCleaved:
            # Remove the extra samples
            assert(len(self.lastSaved)>0)
            rxs=rxs[:len(rxs)-len(self.lastSaved)]
            self.lastSaved=[]

        if len(rxs)>len(inputs):
            # Have extra samples due when self.finalPlus is True
            rxs= rxs[0:len(inputs)]    # Only keep -target products
            prefixOut= prefixOut[0:len(inputs)]
            prefixIn= prefixIn[0:len(inputs)]
            stop= stop[0:len(inputs)]
            
        if self.dopcr and not (keepCleaved and self.noPCRCleave):
            print("######### PCR ############# %.0f min"%(clock.elapsed()/60))
            db.pushStatus("PCR")
            print("PCR Volume: %.1f, Dilution: %.1f, volumes available for PCR: [%s]"%(pcrvol, pcrdil,",".join(["%.1f"%r.volume for r in rxs])))

            initConc=needDil*self.qConc/pcrdil
            if keepCleaved:
                initConc=initConc*self.cleavage		# Only use cleaved as input conc
            else:
                initConc=initConc*(1-self.cleavage)
                
            gain=pcrgain(initConc,400,cycles)
            finalConc=min(200,initConc*gain)
            print("Estimated starting concentration in PCR = %.1f nM, running %d cycles -> %.0f nM\n"%(needDil*self.qConc/pcrdil,cycles,finalConc))
            nsplit=int(math.ceil(pcrvol*1.0/self.maxPCRVolume))
            print("Split each PCR into %d reactions"%nsplit)
            sampNeeded=pcrvol/pcrdil
            if self.rtCarryForward and keepCleaved:
                sampNeeded+=rtCarryForwardVol
            if keepCleaved and self.rtCarryForward:
                print("Saving %.1f ul of each pre-PCR sample" % rtCarryForwardVol)
                self.lastSaved=[Sample("%s.sv"%x.name,self.savePlate) for x in rxs]
                for i in range(len(rxs)):
                    # Save with rtCarryForwardDil dilution to reduce amount of RT consumed (will have Ct's 2-3 lower than others)
                    self.e.transfer(rtCarryForwardVol,rxs[i],self.lastSaved[i],(False,False))
                    self.e.transfer(rtCarryForwardVol*(rtCarryForwardDil-1),decklayout.WATER,self.lastSaved[i],(False,True))  # Use pipette mixing -- shaker mixing will be too slow

            #print "NSplit=",nsplit,", PCR vol=",pcrvol/nsplit,", srcdil=",pcrdil,", input vol=",pcrvol/nsplit/pcrdil
            minvol=min([r.volume for r in rxs])
            maxpcrvol=(minvol-15-1.4*nsplit)*pcrdil
            if maxpcrvol<pcrvol:
                print("Reducing PCR volume from %.1ful to %.1ful due to limited input"%(pcrvol, maxpcrvol))
                pcrvol=maxpcrvol

            if keepCleaved:
                master="MTaqC"
            else:
                master="MTaqU"

            reagents.getsample(master)    # Allocate for this before primers
            
            if self.barcoding:
                primers=self.bcprimers[self.rndNum-1]
                if primers is not None and nsplit>1:
                    primers=primers*nsplit
            else:
                primers=None

            if primers is None:
                primers=[("T7%sX"%x).replace("T7T7","T7") for x in prefixOut]*nsplit

            rnddef = self.rnddef[self.rndNum-1]
            bcout=[]
            if 'barcode' in rnddef:
                # Add barcoding primers 
                assert len(rnddef['barcode'])==len(rxs)
                dil=self.saveSamps(rxs,dil=50,vol=2,plate=decklayout.SAMPLEPLATE)
                for i in range(len(rxs)):
                    dil[i].conc=Concentration(25,1)
                    for bc in rnddef['barcode'][i]:
                        tgt=Sample("%s.%s"%(rxs[i].name,bc),decklayout.SAMPLEPLATE)
                        bparts=bc.split("/")
                        for b in bparts:
                            if not reagents.isReagent("P-%s"%b):
                                reagents.add(name="P-%s"%b,conc=Concentration(2.67,0.4,'uM'),extraVol=30)
                        print("PCR-%s"%bc)
                        self.e.stage("PCR-%s"%bc,reagents=[reagents.getsample("MTaqBar"),reagents.getsample("P-%s"%bparts[0]),reagents.getsample("P-%s"%bparts[1])],samples=[tgt],sources=[dil[i] ],volume=50,destMix=False)
                        bcout.append(tgt)
                        print(tgt.name,"wellMixed=",tgt.wellMixed)
                        
            print("Running PCR with master=",master,", primers=",primers)
            pcr=self.runPCR(src=rxs*nsplit,vol=pcrvol/nsplit,srcdil=pcrdil,ncycles=cycles,primers=primers,usertime=self.usertime if keepCleaved else None,fastCycling=False,inPlace=False,master=master,lowhi=self.lowhi,annealTemp=57)
            if keepCleaved and self.regenPCRCycles is not None:
                # Regenerate prefix
                pcr2=self.runPCR(src=pcr,vol=self.regenPCRVolume,srcdil=self.regenPCRDilution,ncycles=self.regenPCRCycles,primers=None,usertime=None,fastCycling=False,inPlace=False,master="MTaqR",lowhi=self.lowhi,annealTemp=55)
                # Add BT575p for 1 more cycle
                for p in pcr2:
                    self.e.transfer(p.volume*0.5/10,reagents.getsample("Unclvd-Stop"),p,(False,False))
                # One more cycle
                cycling=' TEMP@95,30 TEMP@55,30 TEMP@68,30 TEMP@25,2'
                thermocycler.setpgm('rfin',100,cycling)
                self.e.runpgm("rfin",5.0,False,max([p.volume for p in pcr2]))
                pcr=pcr2	# Use 2nd PCR as actual output

            if len(pcr)<=len(names):
                # Don't relabel if we've split
                for i in range(len(pcr)):
                    pcr[i].name=names[i]+".pcr"
                
            #print "Volume remaining in PCR input source: [",",".join(["%.1f"%r.volume for r in rxs]),"]"
            needDil=finalConc/self.qConc
            print("Projected final concentration = %.0f nM"%(needDil*self.qConc))
            for i in range(len(pcr)):
                pcr[i].conc=Concentration(stock=finalConc,final=None,units='nM')
            db.popStatus()

            if self.pcrSave:
                # Save samples at 1x (move all contents -- can ignore warnings)
                maxSaveVol=(100 if self.savedilplate else 1500)*1.0/nsplit

                if self.finalRound and nsplit==1 and self.savedilplate and pcrtgt is None:
                    print("Skipping save of final PCR")
                    sv=pcr
                else:
                    residual=2.4   # Amount to leave behind to avoid aspirating air
                    sv=self.saveSamps(src=pcr[:len(rxs)],vol=[min([maxSaveVol,x.volume-residual]) for x in pcr[:len(rxs)]],dil=1,plate=(self.savePlate if self.savedilplate else decklayout.EPPENDORFS),tgt=pcrtgt)
                    if nsplit>1:
                        # Combine split
                        for i in range(len(rxs),len(rxs)*nsplit):
                            self.e.transfer(min([maxSaveVol,pcr[i].volume-residual]),pcr[i],sv[i%len(sv)],mix=(False,False))
                        # Correct concentration (above would've assumed it was diluted)
                        for i in range(len(sv)):
                            sv[i].conc=pcr[i].conc
                        # Shake
                        self.e.shakeSamples(sv)

                if "pcr" in self.qpcrStages:
                    for i in range(len(sv)):
                        q.addSamples(sv[i],needDil,primers=primerSet[i],names=["%s.pcr"%names[i]])

                print("Have %.2f pmoles of product (%.0f ul @ %.1f nM)"%(sv[0].volume*sv[0].conc.stock/1000,sv[0].volume,sv[0].conc.stock))

                # Save barcoded products too
                if len(bcout)>0:
                    print("bcout=",",".join(str(b) for b in bcout))
                    print("mixed=",bcout[0].isMixed(),", wellMixed=",bcout[0].wellMixed)
                    bcsave=self.saveSamps(src=bcout,vol=[b.volume for b in bcout],dil=1,plate=self.savePlate,mix=(False,False))
                    if "bc" in self.qpcrStages:
                        print("Doing qPCR of barcoding: ",bcsave)
                        for i in range(len(bcsave)):
                            needDil=640
                            q.addSamples(src=bcsave[i],needDil=needDil,primers=["T7X","WX","ZX"]+(["MX"] if self.useMX else []),save=False)
                else:
                    bcsave=[]
                    
                return sv, bcsave
            else:
                assert "pcr" not in self.qpcrStages   ## Not implemented
                return pcr[:len(rxs)], bcout

        elif self.noPCRCleave:
            print("Dilution instead of PCR: %.2f"%self.nopcrdil)
            # Need to add enough t7prefix to compensate for all of the Stop primer currently present, regardless of whether it is for cleaved or uncleaved
            # Will result in some short transcripts corresponding to the stop primers that are not used for cleaved product, producing just GGG_W_GTCTGC in the next round.  These would be reverse-trancribed, but may compete for T7 yield
            t7prefix=reagents.getsample("BT88")
            dil=self.extpostdil[self.rndNum-1]  # FIXME: Is this correct?  Used to have a 'userDil' term
            stopconc=1000.0/dil
            bt88conc=t7prefix.conc.stock
            relbt88=stopconc/bt88conc
            print("Using EXT with %.0fnM of stop oligo as input to next T7, need %.2ful of BT88@%.0fnM per ul of sample"%(stopconc,relbt88,bt88conc))
            for r in rxs:
                vol=r.volume*relbt88
                t7prefix.conc.final=t7prefix.conc.stock*vol/(r.volume+vol)
                r.conc.final=r.conc.stock*r.volume/(r.volume+vol)
                self.e.transfer(vol,t7prefix,r,mix=(False,False))

            if self.nopcrdil>(1+relbt88):
                self.diluteInPlace(tgt=rxs,dil=self.nopcrdil/(1.0+relbt88))
                #needDil=needDil/self.nopcrdil  # needDil not used subsequently
                print("Dilution of EXT product: %.2fx * %.2fx = %2.fx\n"%(1+relbt88,self.nopcrdil/(1+relbt88),self.nopcrdil))
            else:
                print("Dilution of EXT product: %.2fx\n"%(1+relbt88))

            return rxs, []
        else:
            return rxs, []
Esempio n. 14
0
    def pgm(self):
        q = QSetup(self,maxdil=self.maxdilstep,debug=False,mindilvol=60)
        self.e.addIdleProgram(q.idler)

        if self.barcoding:
            # Setup barcode primers for cleaved rounds only
            self.bcprimers=[["BC-%s-R%d_T7"%(inp['ligand'],r+1) for inp in self.inputs] if self.rounds[r]=='C' else None for r in range(len(self.rounds))]
            for bcp in self.bcprimers:
                if bcp is not None:
                    for p in ["P-%s"%pp for pp in bcp]:
                        if not reagents.isReagent(p):
                            reagents.add(name=p,conc=4,extraVol=30,plate=decklayout.REAGENTPLATE,well="B2")
                        s=reagents.getsample(p)   # Force allocation of a well
                        print("Adding %s to reagents at well %s"%(p,s.plate.wellname(s.well)))
            print("BC primers=", self.bcprimers)
            
        # Add any missing fields to inputs
        for i in range(len(self.inputs)):
            if 'ligand' not in self.inputs[i]:
                self.inputs[i]['ligand']=None
            if 'negligand' not in self.inputs[i]:
                self.inputs[i]['negligand']=None
            if 'round' not in self.inputs[i]:
                self.inputs[i]['round']=None
            if 'name' not in self.inputs[i]:
                if self.inputs[i]['ligand'] is None:
                    self.inputs[i]['name']='%s_%d_R%d'%(self.inputs[i]['prefix'],self.inputs[i]['ID'],self.inputs[i]['round'])
                else:
                    self.inputs[i]['name']='%s_%d_R%d_%s'%(self.inputs[i]['prefix'],self.inputs[i]['ID'],self.inputs[i]['round'],self.inputs[i]['ligand'])

        # Add templates
        if self.directT7:
            self.srcs = self.addTemplates([inp['name'] for inp in self.inputs],stockconc=self.tmplFinalConc/self.templateDilution,finalconc=self.tmplFinalConc,plate=decklayout.SAMPLEPLATE,looplengths=[inp['looplength'] for inp in self.inputs],initVol=self.t7vol[0]*self.templateDilution,extraVol=0)
        else:
            self.srcs = self.addTemplates([inp['name'] for inp in self.inputs],stockconc=self.tmplFinalConc/self.templateDilution,finalconc=self.tmplFinalConc,plate=decklayout.DILPLATE,looplengths=[inp['looplength'] for inp in self.inputs],extraVol=15) 

        if self.dopcr:
            # Reserve space for  PCR products
            pcrprods=[ [Sample("R%d-T%s"%(r,inp['ligand']),self.savePlate) for inp in self.inputs] for r in range(len(self.rounds))]
        else:
            pcrprods=None

        t7in = [s.getsample()  for s in self.srcs]
        
        if "negative" in self.qpcrStages:
            q.addSamples(decklayout.SSDDIL,1,self.allprimers,save=False)   # Negative controls
        if "reference" in self.qpcrStages:
            q.addReferences(dstep=10,nsteps=5,primers=["WX","MX","T7X"] if self.useMX else ["WX","T7X"],ref=reagents.getsample("BT5310"),nreplicates=1)

        # Save RT product from first (uncleaved) round and then use it during 2nd (cleaved) round for ligation and qPCR measurements
        self.rndNum=0
        self.nextID=self.firstID
        curPrefix=[inp['prefix'] for inp in self.inputs]
        r1=t7in
        
        for roundType in self.rounds:
            # Run a single round of roundType with r1 as input
            # roundType is either "U" for uncleaved, or a new prefix for a cleaved round (with "T" being a T7 prepend)
            # Set r1 to new output at end

            if self.roundCallback is not None:
                self.roundCallback(self,self.rndNum,roundType)
                
            # Computed output prefix
            if roundType=='U':
                prefixOut=curPrefix
                stop=["Unclvd" for _ in curPrefix]
            else:
                if roundType=='T':
                    stop=['T7%s'%p for p in curPrefix]
                    prefixOut=curPrefix
                elif any([p==roundType for p in curPrefix]):
                    logging.error( "Round %d is a cleaved round but goes to %s without changing prefix"%(self.rndNum, roundType))
                    assert False
                else:
                    prefixOut=[roundType for _ in curPrefix]
                    stop=prefixOut

            # May be explicitly overridden
            for i in range(len(self.inputs)):
                if 'stop' in self.inputs[i]:
                    if isinstance(self.inputs[i]['stop'],list):
                        assert(len(self.inputs[i]['stop'])==len(self.rounds))
                        t=self.inputs[i]['stop'][self.rndNum]
                    else:
                        t=self.inputs[i]['stop']
                    if (roundType=='U') != (t=='U'):
                        print("Attempt to override round %d (type %s) with a input-specific round type of %s"%(self.rndNum, roundType, t))
                        assert False
                    if roundType!='U':
                        if t=='T':
                            stop[i]='T7%s'%curPrefix[i]
                            prefixOut[i]=curPrefix[i]
                        else:
                            stop[i]=t
                            prefixOut[i]=t

            self.rndNum=self.rndNum+1
            self.finalRound=self.rndNum==len(self.rounds)

            db.pushStatus("%s%d"%(roundType,self.rndNum))
            [r1,bc1]=self.oneround(q,r1,prefixOut=prefixOut,stop=stop,prefixIn=curPrefix,keepCleaved=(roundType!='U'),rtvol=self.rtvol[self.rndNum-1],t7vol=self.t7vol[self.rndNum-1],cycles=self.pcrcycles[self.rndNum-1],pcrdil=self.pcrdil[self.rndNum-1],pcrvol=self.pcrvol[self.rndNum-1],dolig=self.allLig or (roundType!='U'),pcrtgt=None if pcrprods is None else pcrprods[self.rndNum-1])
            db.popStatus()

            # Add TRefs specified in rnddefs 
            if 'tref' in self.rnddef[self.rndNum-1]:
                tref=self.rnddef[self.rndNum-1]['tref']
                assert len(tref)==len(r1)
                for i in range(len(r1)):
                    if tref[i] is not None:
                        trefname='TRef%d'%tref[i]
                        print("Adding %s to %s"%(trefname,r1[i].name))
                        if not reagents.isReagent(trefname):
                            reagents.add(name=trefname,conc=10,extraVol=30,well="E4")
                        trefSamp=reagents.getsample(trefname)
                        oldConc=r1[i].conc.stock
                        oldUnits=r1[i].conc.units
                        oldVol=r1[i].volume
                        self.e.transfer(r1[i].volume/(trefSamp.conc.dilutionneeded()-1),trefSamp,r1[i],mix=(False,False))    # TODO: Check that these end up mixed
                        r1[i].conc=Concentration(stock=oldConc*oldVol/r1[i].volume, units=oldUnits)   # Treat TRef as straight dilution
                        print("New conc=",r1[i].conc)

            for i in range(len(r1)):
                if self.inputs[i]['round'] is None:
                    r1[i].name="%s_%d"%(prefixOut[i],self.nextID)
                else:
                    r1[i].name="%d_%s_R%d%c"%(self.nextID,prefixOut[i],self.inputs[i]['round']+self.rndNum,roundType)
                if self.inputs[i]['ligand'] is not None:
                    r1[i].name="%s_%s"%(r1[i].name,self.inputs[i]['ligand'])
                print("Used ID ", self.nextID," for ", r1[i].name,": ",r1[i])
                self.nextID+=1
                r1[i].conc.final=r1[i].conc.stock*self.templateDilution
            for i in range(len(bc1)):
                #print("Renaming",bc1[i].name)
                pts=bc1[i].name.split(".")
                bc1[i].name="%d_BC_R%d%c"%(self.nextID,self.inputs[i//2]['round']+self.rndNum,roundType)
                if self.inputs[i//2]['ligand'] is not None:
                    bc1[i].name="%s_%s"%(bc1[i].name,self.inputs[i//2]['ligand'])
                bc1[i].name+="_"+pts[-2]
                print("Used ID ", self.nextID," for ", bc1[i].name,":",bc1[i])
                self.nextID+=1
            curPrefix=prefixOut


        if "finalpcr" in self.qpcrStages:
            for i in range(len(r1)):
                if self.singlePrefix:
                    q.addSamples(src=r1[i],needDil=r1[i].conc.stock/self.qConc,primers=["T7X","MX"] if self.useMX else ["T7X"])
                else:
                    # noinspection PyUnboundLocalVariable
                    q.addSamples(src=r1[i],needDil=r1[i].conc.stock/self.qConc,primers=["T7X",prefixOut[i]+"X"]+(["MX"] if self.useMX else []))

        # Add TRefs if needed
        for i in range(len(r1)):
            if 'tref' in self.inputs[i]:
                trefname='TRef%d'%self.inputs[i]['tref']
                if not reagents.isReagent(trefname):
                    reagents.add(name=trefname,conc=10,extraVol=30)
                tref=reagents.getsample(trefname)
                self.e.transfer(r1[i].volume/(tref.conc.dilutionneeded()-1),tref,r1[i],mix=(False,False))

        db.pushStatus('qPCR')
        print("######### qPCR ########### %.0f min"%(clock.elapsed()/60))
        self.allprimers=q.allprimers()
        q.run(confirm=self.qpcrWait)
        db.popStatus()