Exemple #1
0
  def matchPeaks(self):
  
    # assign relative to reference
    
    if self.assignPeakList and self.assignPeakList.peaks and self.refPeakList and self.satPeakList:
 
      tolH = float( self.tolHEntry.get() )
      tolN = float( self.tolNEntry.get() )
      pickNewPeaks = self.pickPeaksSelect.get()
      doAssign     = self.assignSelect.get()
 
      dimH  = findSpectrumDimsByIsotope(self.assignPeakList.dataSource,'1H' )[0]
      dimHA = findSpectrumDimsByIsotope(self.refPeakList.dataSource,'1H' )[0]
      dimHB = findSpectrumDimsByIsotope(self.satPeakList.dataSource,'1H' )[0]
      dimN  = 1-dimH
      dimNA = 1-dimHA
      dimNB = 1-dimHB
 
      tolerancesA = [0,0]
      tolerancesA[dimHA] = tolH
      tolerancesA[dimNA] = tolN

      tolerancesB = [0,0]
      tolerancesB[dimHB] = tolH
      tolerancesB[dimNB] = tolN
 
      self.peakPairs = matchHnoePeaks(self.assignPeakList,self.refPeakList,
                                      self.satPeakList,tolerancesA,tolerancesB,
                                      pickNewPeaks,doAssign)
 
      self.updateAfter()
Exemple #2
0
 def getPeakLists(self):
 
   names = []
   peakLists = []
   
   for experiment in self.nmrProject.sortedExperiments():
     for dataSource in experiment.sortedDataSources():
       if dataSource.numDim == 2:
         dimsN = findSpectrumDimsByIsotope(dataSource,'15N')
         dimsH = findSpectrumDimsByIsotope(dataSource,'1H')
         if len(dimsN) == 1 and len(dimsH) == 1:
           for peakList in dataSource.sortedPeakLists():
             name = self.getPeakListName(peakList)
             names.append( name )
             peakLists.append(peakList)
   
   return names, peakLists
Exemple #3
0
  def update(self):

    if self.refPeakList:
      self.peaksALabel.set( 'Number of Ref Peaks: %d' % len(self.refPeakList.peaks) )
    else:
      self.peaksALabel.set( 'Number of Ref Peaks: %d' % 0 )
    if self.satPeakList:
      self.peaksBLabel.set( 'Number of Sat Peaks: %d' % len(self.satPeakList.peaks) )
    else:
      self.peaksBLabel.set( 'Number of Sat Peaks: %d' % 0 )
    if self.assignPeakList:
      self.peaksCLabel.set( 'Number of Assign Peaks: %d' % len(self.assignPeakList.peaks) )
    else:
      self.peaksCLabel.set( 'Number of Assign Peaks: %d' % 0 )

    if self.refPeakList and self.satPeakList and self.assignPeakList:
      if self.refPeakList is self.satPeakList:
        self.pairButtons.buttons[0].disable()
      else:
        self.pairButtons.buttons[0].enable()
    else:
      self.pairButtons.buttons[0].disable()
 
    if self.selectedPair:
      self.pairButtons.buttons[1].enable()
      self.pairButtons.buttons[2].enable()
    else:
      self.pairButtons.buttons[1].disable()
      self.pairButtons.buttons[2].disable()

    if self.peakPairs:
      self.pairButtons.buttons[3].enable()
      dsA = self.peakPairs[0][0].peakList.dataSource
      dsB = self.peakPairs[0][1].peakList.dataSource
      dimHA = findSpectrumDimsByIsotope(dsA,'1H')[0]
      dimHB = findSpectrumDimsByIsotope(dsB,'1H')[0]
      dimNA = findSpectrumDimsByIsotope(dsA,'15N')[0]
      dimNB = findSpectrumDimsByIsotope(dsB,'15N')[0]
    else:
      self.pairButtons.buttons[3].disable()
    
    objectList  = []
    textMatrix  = []

    i = 0
    for (peakA,peakB) in self.peakPairs:
      i += 1

      peakDimsA = peakA.sortedPeakDims()
      peakDimsB = peakB.sortedPeakDims()

      ppm0 = peakDimsA[dimHA].value
      ppm1 = peakDimsB[dimHB].value
      ppm2 = peakDimsA[dimNA].value
      ppm3 = peakDimsB[dimNB].value
      d0 = abs(ppm0-ppm1)
      d1 = abs(ppm2-ppm3)
      intensA = getPeakIntensity(peakA,self.intensityType)
      intensB = getPeakIntensity(peakB,self.intensityType)
      datum = []
      datum.append( i )
      datum.append( getPeakAnnotation(peakA, doPeakDims=False) )
      datum.append( getPeakAnnotation(peakB, doPeakDims=False) )
      datum.append( ppm0 )
      datum.append( ppm1 )
      datum.append( ppm2 )
      datum.append( ppm3 )
      datum.append( sqrt((d0*d0)+(d1*d1)) )
      datum.append( intensA )
      datum.append( intensB )
      if intensB:
        datum.append( float(intensA)/intensB )
      else:
        datum.append( None )
      seqCodes = ','.join(['%s' % seqCode for seqCode in getPeakSeqCodes(peakB)])
      datum.append(seqCodes)
      
      objectList.append( (peakA,peakB) )
      textMatrix.append( datum )
      
    if not objectList:
      textMatrix.append([])

    self.scrolledMatrix.update(objectList=objectList, textMatrix=textMatrix)

    self.waiting = False
Exemple #4
0
def getCloseSingleShiftMatches(peakList,
                               network,
                               covalent,
                               labelling=None,
                               minLabelFraction=0.1,
                               intensityType='height',
                               progressBar=None):

    spectrum = peakList.dataSource
    experiment = spectrum.experiment
    shiftList = experiment.shiftList
    hDims = findSpectrumDimsByIsotope(spectrum, '1H')
    tolerances = getDimTolerances(spectrum)
    bondedDims = getBondedDimsDict(spectrum)

    meanIntensity = getMeanPeakIntensity(peakList.peaks,
                                         intensityType=intensityType)

    info = (experiment.name, spectrum.name, peakList.serial,
            len(peakList.peaks))

    if progressBar:
        progressBar.setText('Unique shift matches for\n%s:%s:%d - %d peaks' %
                            info)
        progressBar.set(0)
        progressBar.total = len(peakList.peaks)
        progressBar.open()
        progressBar.update_idletasks()
    else:
        print 'Determining unique shift matches for %s:%s:%d - %d peaks' % info

    for peak in peakList.peaks:

        if progressBar:
            progressBar.increment()

        hResonances = []

        peakDims = peak.sortedPeakDims()
        boundResonances = {}
        for dim in hDims:
            peakDim = peakDims[dim]
            if peakDim.peakDimContribs:
                hResonances.append(
                    [contrib.resonance for contrib in peakDim.peakDimContribs])

            else:
                resonances = []
                shifts = findMatchingPeakDimShifts(peakDim,
                                                   shiftRanges=None,
                                                   tolerance=tolerances[dim],
                                                   aliasing=True,
                                                   findAssigned=False)
                dim2 = bondedDims.get(dim)
                peakDim2 = None
                if dim2 is not None:
                    peakDim2 = peakDims[dim2]
                    shifts2 = []

                    if peakDim2.peakDimContribs:
                        for contrib in peakDim2.peakDimContribs:
                            shift = contrib.resonance.findFirstShift(
                                parentList=shiftList)
                            if shift:
                                shifts2.append(shift)

                    else:
                        shifts2 = findMatchingPeakDimShifts(
                            peakDim2,
                            shiftRanges=None,
                            tolerance=tolerances[dim2],
                            aliasing=True,
                            findAssigned=False)
                    for shift in shifts:
                        resonance1 = shift.resonance
                        for shift2 in shifts2:
                            resonance2 = shift2.resonance
                            if areResonancesBound(resonance1, resonance2):
                                if labelling:
                                    fraction = getResonancePairLabellingFraction(
                                        resonance1, resonance2, labelling)
                                    if fraction < minLabelFraction:
                                        continue

                                resonances.append(resonance1)
                                boundResonances[resonance1] = resonance2
                                break

                else:
                    for shift in shifts:
                        resonance = shift.resonance

                        if labelling:
                            fraction = getResonanceLabellingFraction(
                                resonance, labelling)

                            if fraction < minLabelFraction:
                                continue

                        resonances.append(resonance)

                if len(resonances) == 1:
                    #resonance  = resonances[0]
                    #assignResToDim(peakDim,resonance,doWarning=False)

                    #resonance2 = boundResonances.get(resonance)
                    #if peakDim2 and (resonance2 is not None):
                    #   assignResToDim(peakDim2,resonance2,doWarning=False)

                    hResonances.append(resonances)

        if len(hResonances) == 2:

            peakIntensity = peak.findFirstPeakIntensity(
                intensityType=intensityType)
            if peakIntensity:
                intensity = peakIntensity.value
                intensity /= float(len(hResonances[0]))
                intensity /= float(len(hResonances[1]))
                intensity /= meanIntensity

                for resonance1 in hResonances[0]:
                    if network.get(resonance1) is None:
                        covalent[resonance1] = {}
                        network[resonance1] = {}

                    intensity2 = intensity
                    if resonance1.resonanceSet:
                        intensity2 /= float(
                            len(resonance1.resonanceSet.findFirstAtomSet().
                                atoms))

                    for resonance2 in hResonances[1]:
                        if network.get(resonance2) is None:
                            network[resonance2] = {}
                            covalent[resonance2] = {}

                        if resonance2.resonanceSet:
                            intensity2 /= float(
                                len(resonance2.resonanceSet.findFirstAtomSet().
                                    atoms))

                        network[resonance1][resonance2] = [intensity2, peak]
                        network[resonance2][resonance1] = [intensity2, peak]

    return network, covalent
Exemple #5
0
def assignCloseSingleShiftMatches(peakList):

    spectrum = peakList.dataSource
    experiment = spectrum.experiment
    shiftList = experiment.shiftList
    hDims = findSpectrumDimsByIsotope(spectrum, '1H')
    tolerances = getDimTolerances(spectrum)
    bondedDims = getBondedDimsDict(spectrum)

    info = (experiment.name, spectrum.name, peakList.serial,
            len(peakList.peaks))
    print 'Assigning obvious shift matches for %s:%s:%d - %d peaks' % info

    c = 0
    for peak in peakList.peaks:
        if c and (c % 100 == 0):
            print '   %d' % (c, )
        c += 1

        peakDims = peak.sortedPeakDims()
        boundResonances = {}
        for dim in hDims:
            peakDim = peakDims[dim]
            if not peakDim.peakDimContribs:
                resonances = []
                shifts = findMatchingPeakDimShifts(peakDim,
                                                   shiftRanges=None,
                                                   tolerance=tolerances[dim],
                                                   aliasing=True,
                                                   findAssigned=False)
                dim2 = bondedDims.get(dim)
                peakDim2 = None
                if dim2 is not None:
                    peakDim2 = peakDims[dim2]
                    shifts2 = []

                    if peakDim2.peakDimContribs:
                        for contrib in peakDim2.peakDimContribs:
                            shift = contrib.resonance.findFirstShift(
                                parentList=shiftList)
                            if shift:
                                shifts2.append(shift)

                    else:
                        shifts2 = findMatchingPeakDimShifts(
                            peakDim2,
                            shiftRanges=None,
                            tolerance=tolerances[dim2],
                            aliasing=True,
                            findAssigned=False)
                    for shift in shifts:
                        resonance1 = shift.resonance
                        for shift2 in shifts2:
                            resonance2 = shift2.resonance
                            if areResonancesBound(resonance1, resonance2):
                                resonances.append(resonance1)
                                boundResonances[resonance1] = resonance2
                                break

                else:
                    for shift in shifts:
                        resonances.append(shift.resonance)

                if len(resonances) == 1:
                    resonance = resonances[0]
                    assignResToDim(peakDim, resonance, doWarning=False)

                    resonance2 = boundResonances.get(resonance)
                    if peakDim2 and (resonance2 is not None):
                        assignResToDim(peakDim2, resonance2, doWarning=False)