Exemple #1
0
    def readPeakList(self, fn, status='keep'):
        """ Six lines per peak
 1,1,2,99,1,2,'Jurgen','20-HG1|20-HN'
                       ^ assignment info
 2.340,0.050,0.041,9.049,0.026,0.026,2.000
 ^ Chemical shift 1
                   ^ Chemical shift 2
 26
 0
 0.0000E+00,8.0715E+06
            ^ peak volume
 20,5,20,1
"""
        nTmessage("Reading: %s" % fn)
        txt = readTextFromFile(fn)

        _path,name,_ext = nTpath( fn )
        peakList = PeakList( name=name, status=status )

        splitLineList = txt.splitlines()
        # Init here after some content is added; can't be done in constructor of class.
        self.chainName = self.project.molecule.allChains()[0].name

        i = 0
        while i < len(splitLineList):
#            nTdebug("Working on line %d (line 1 in block)" % i)
# 1,1,2,99,1,2,'Jurgen','20-HG1|20-HN'
#                       ^ assignment info
            line = splitLineList[i]
            wordList = line.split(',')
            assignmentListStr = wordList[ - 1]
            assignmentListStr = assignmentListStr.replace("'", '')
            barIdx = assignmentListStr.find('|')
            resonances = []
            if barIdx > 0:
                assignmentListStrList = assignmentListStr.split('|')
                for loc in assignmentListStrList:
                    resId, atomName = loc.split('-')
                    resId = int(resId)
                    resonanceListAtomName = self.getResonanceListForLoc(resId, atomName)
                    resonances.append(resonanceListAtomName)

            # work on line 2 for peak positions
# 2.340,0.050,0.041,9.049,0.026,0.026,2.000
# ^ Chemical shift 1
#                   ^ Chemical shift 2
            i += 1
            line = splitLineList[i]
#            nTdebug("Working on CS line 2: [%s]" % line)
            wordList = line.split(',')
            peakPosition1 = float(wordList[0])
            peakPosition2 = float(wordList[3])
            positions = [peakPosition1, peakPosition2]

            # work on line 5 for peak volume
            i += 3
            line = splitLineList[i]
            wordList = line.split(',')
            volume = float(wordList[ -1])
#            nTdebug("Working on volume [%s] from line 5 (%d) : [%s]" % (volume, i,line))

            peak = Peak(self.dimension,
                  positions = positions,
                  height = volume, # this is a work around the fact that later on xeasy only uses height and misses volume.
                  volume = volume,
                  resonances = resonances)

            # Use the Lister class for a string representation.
#            nTdebug("Found peak: %r" % peak)
            peakList.append( peak )
            # skip to next line 1
            i += 2
        return peakList
Exemple #2
0
    def importPeaks( self, molecule, peakFile, status='keep')   :
        """Read Xeasy peak file
           returns a PeaksList instance or None on error

           JFD: description of XEASY peak list format:
  43   1.760   3.143 1 T          0.000e+00  0.00e+00 -   0 2260 2587 0
  46   1.649   4.432 1 T          1.035e+05  0.00e+00 r   0 2583 2257 0
   ^ peak id                      ^ height
       ^ chemical shifts                     ^ height dev   ^ resonance ids
                     ^ ?                              ^ ?             ^ ?
                       ^ ?                                ^ ?

        resonance id is zero for unassigned.
        """
        #print '>>', molecule, peakFile

        self.map2molecule( molecule )

        _path,name,_ext = nTpath( peakFile )
        peaks = PeakList( name=name, status=status )


        dimension = 0
        # f stands for field.
        for f in  AwkLike( peakFile ):
            if (f.NR == 1 and f.NF == 5):
                dimension = f.int(5)

            elif (not f.isComment('#') ):
#                 if (f.NF == 12):
#                     dimension = 2
#                 elif (f.NF == 13 or f.NF == 14 or (f.NF>):
#                     dimension = 3
#                 else:
#                     nTerror('Xeasy.importPeaks: invalid number of fields (%d) in file "%s" on line %d (%s)',
#                              f.NF, peakFile, f.NR, f.dollar[0]
#                            )
#                     return None
#                 #end if
                if not dimension:
                    nTerror('Xeasy.importPeaks: invalid dimensionality in file "%s" (line %d, "%s")'%(
                             peakFile, f.NR, f.dollar[0]))
                    return None
                #end if

                cur = 1

                # preserve the Xeasy peak id
                peakId = f.int( cur )
                if (peakId == None): 
                    return None
                cur += 1

                peakpos = []
                for _i in range(X_AXIS, dimension):
                    p = f.float( cur )
                    if (p == None): 
                        return None
                    peakpos.append( p )
                    cur += 1
                #end if

                cur += 2 # skip two fields
                height = f.float( cur )
                if height == None: 
                    return None
                cur += 1
                heightError = f.float( cur )
                if heightError == None: 
                    return None
                cur += 1

                resonances = []
                error = 0
                cur += 2 # skip two fields
                for _i in range(X_AXIS, dimension):
                    aIndex = f.int( cur )
                    if aIndex == None: 
                        return None
                    cur += 1
                    # 0 means unassigned according to Xeasy convention
                    if aIndex == 0:
                        resonances.append( None )
                    else:
                        if not aIndex in self.prot:
                            nTerror('Xeasy.importPeaks: invalid atom id %d on line %d (%s)',
                                     aIndex, f.NR, f.dollar[0]
                                   )
                            error = 1
                            break
                        else:
                            atom = self.prot[ aIndex].atom
                            if atom != None:
                                resonances.append( atom.resonances() )
                            else:
                                resonances.append( None )
                        #end if
                    #end if
                #end for

                if not error:
                    peak = Peak( dimension=dimension,
                                 positions=peakpos,
                                 height=height, heightError=heightError,
                                 resonances = resonances,
                                )
                    # store original peak id
                    peak.xeasyIndex = peakId
                    peaks.append( peak )
                #end if
            #end if
        #end for

        nTmessage('Xeasy.importPeaks: extracted %d peaks from %s', len(peaks), peakFile )
        #end if

        return peaks
Exemple #3
0
    def readPeakList(self, fn, status='keep'):
        """ Six lines per peak
 1,1,2,99,1,2,'Jurgen','20-HG1|20-HN'
                       ^ assignment info
 2.340,0.050,0.041,9.049,0.026,0.026,2.000
 ^ Chemical shift 1
                   ^ Chemical shift 2
 26
 0
 0.0000E+00,8.0715E+06
            ^ peak volume
 20,5,20,1
"""
        nTmessage("Reading: %s" % fn)
        txt = readTextFromFile(fn)

        _path, name, _ext = nTpath(fn)
        peakList = PeakList(name=name, status=status)

        splitLineList = txt.splitlines()
        # Init here after some content is added; can't be done in constructor of class.
        self.chainName = self.project.molecule.allChains()[0].name

        i = 0
        while i < len(splitLineList):
            #            nTdebug("Working on line %d (line 1 in block)" % i)
            # 1,1,2,99,1,2,'Jurgen','20-HG1|20-HN'
            #                       ^ assignment info
            line = splitLineList[i]
            wordList = line.split(',')
            assignmentListStr = wordList[-1]
            assignmentListStr = assignmentListStr.replace("'", '')
            barIdx = assignmentListStr.find('|')
            resonances = []
            if barIdx > 0:
                assignmentListStrList = assignmentListStr.split('|')
                for loc in assignmentListStrList:
                    resId, atomName = loc.split('-')
                    resId = int(resId)
                    resonanceListAtomName = self.getResonanceListForLoc(
                        resId, atomName)
                    resonances.append(resonanceListAtomName)

            # work on line 2 for peak positions
# 2.340,0.050,0.041,9.049,0.026,0.026,2.000
# ^ Chemical shift 1
#                   ^ Chemical shift 2
            i += 1
            line = splitLineList[i]
            #            nTdebug("Working on CS line 2: [%s]" % line)
            wordList = line.split(',')
            peakPosition1 = float(wordList[0])
            peakPosition2 = float(wordList[3])
            positions = [peakPosition1, peakPosition2]

            # work on line 5 for peak volume
            i += 3
            line = splitLineList[i]
            wordList = line.split(',')
            volume = float(wordList[-1])
            #            nTdebug("Working on volume [%s] from line 5 (%d) : [%s]" % (volume, i,line))

            peak = Peak(
                self.dimension,
                positions=positions,
                height=
                volume,  # this is a work around the fact that later on xeasy only uses height and misses volume.
                volume=volume,
                resonances=resonances)

            # Use the Lister class for a string representation.
            #            nTdebug("Found peak: %r" % peak)
            peakList.append(peak)
            # skip to next line 1
            i += 2
        return peakList
Exemple #4
0
    def importPeaks(self, molecule, peakFile, status='keep'):
        """Read Xeasy peak file
           returns a PeaksList instance or None on error

           JFD: description of XEASY peak list format:
  43   1.760   3.143 1 T          0.000e+00  0.00e+00 -   0 2260 2587 0
  46   1.649   4.432 1 T          1.035e+05  0.00e+00 r   0 2583 2257 0
   ^ peak id                      ^ height
       ^ chemical shifts                     ^ height dev   ^ resonance ids
                     ^ ?                              ^ ?             ^ ?
                       ^ ?                                ^ ?

        resonance id is zero for unassigned.
        """
        #print '>>', molecule, peakFile

        self.map2molecule(molecule)

        _path, name, _ext = nTpath(peakFile)
        peaks = PeakList(name=name, status=status)

        dimension = 0
        # f stands for field.
        for f in AwkLike(peakFile):
            if (f.NR == 1 and f.NF == 5):
                dimension = f.int(5)

            elif (not f.isComment('#')):
                #                 if (f.NF == 12):
                #                     dimension = 2
                #                 elif (f.NF == 13 or f.NF == 14 or (f.NF>):
                #                     dimension = 3
                #                 else:
                #                     nTerror('Xeasy.importPeaks: invalid number of fields (%d) in file "%s" on line %d (%s)',
                #                              f.NF, peakFile, f.NR, f.dollar[0]
                #                            )
                #                     return None
                #                 #end if
                if not dimension:
                    nTerror(
                        'Xeasy.importPeaks: invalid dimensionality in file "%s" (line %d, "%s")'
                        % (peakFile, f.NR, f.dollar[0]))
                    return None
                #end if

                cur = 1

                # preserve the Xeasy peak id
                peakId = f.int(cur)
                if (peakId == None):
                    return None
                cur += 1

                peakpos = []
                for _i in range(X_AXIS, dimension):
                    p = f.float(cur)
                    if (p == None):
                        return None
                    peakpos.append(p)
                    cur += 1
                #end if

                cur += 2  # skip two fields
                height = f.float(cur)
                if height == None:
                    return None
                cur += 1
                heightError = f.float(cur)
                if heightError == None:
                    return None
                cur += 1

                resonances = []
                error = 0
                cur += 2  # skip two fields
                for _i in range(X_AXIS, dimension):
                    aIndex = f.int(cur)
                    if aIndex == None:
                        return None
                    cur += 1
                    # 0 means unassigned according to Xeasy convention
                    if aIndex == 0:
                        resonances.append(None)
                    else:
                        if not aIndex in self.prot:
                            nTerror(
                                'Xeasy.importPeaks: invalid atom id %d on line %d (%s)',
                                aIndex, f.NR, f.dollar[0])
                            error = 1
                            break
                        else:
                            atom = self.prot[aIndex].atom
                            if atom != None:
                                resonances.append(atom.resonances())
                            else:
                                resonances.append(None)
                        #end if
                    #end if
                #end for

                if not error:
                    peak = Peak(
                        dimension=dimension,
                        positions=peakpos,
                        height=height,
                        heightError=heightError,
                        resonances=resonances,
                    )
                    # store original peak id
                    peak.xeasyIndex = peakId
                    peaks.append(peak)
                #end if
            #end if
        #end for

        nTmessage('Xeasy.importPeaks: extracted %d peaks from %s', len(peaks),
                  peakFile)
        #end if

        return peaks