Back to index

python-biopython  1.60
NOEtools.py
Go to the documentation of this file.
00001 # NOEtools.py: A python module for predicting NOE coordinates from
00002 #                assignment data.  
00003 #
00004 #    The input and output are modelled on nmrview peaklists.
00005 #    This modules is suitable for directly generating an nmrview
00006 #    peaklist with predicted crosspeaks directly from the
00007 #    input assignment peaklist. 
00008 
00009 import xpktools
00010 
00011 def predictNOE(peaklist,originNuc,detectedNuc,originResNum,toResNum):
00012 # Predict the i->j NOE position based on self peak (diagonal) assignments
00013 # 
00014 # example predictNOE(peaklist,"N15","H1",10,12)
00015 #    where peaklist is of the type xpktools.peaklist
00016 #    would generate a .xpk file entry for a crosspeak
00017 #    that originated on N15 of residue 10 and ended up
00018 #    as magnetization detected on the H1 nucleus of
00019 #    residue 12.
00020 # CAVEAT: The initial peaklist is assumed to be diagonal (self peaks only)
00021 #       and currently there is not checking done to insure that this
00022 #       assumption holds true.  Check your peaklist for errors and
00023 #       off diagonal peaks before attempting to use predictNOE.
00024 
00025   returnLine = "" # The modified line to be returned to the caller
00026 
00027   datamap = _data_map(peaklist.datalabels)
00028 
00029   # Construct labels for keying into dictionary
00030   originAssCol = datamap[originNuc+".L"]+1
00031   originPPMCol = datamap[originNuc+".P"]+1
00032   detectedPPMCol = datamap[detectedNuc+".P"]+1
00033 
00034   # Make a list of the data lines involving the detected
00035   if str(toResNum) in peaklist.residue_dict(detectedNuc) \
00036   and str(originResNum) in peaklist.residue_dict(detectedNuc):
00037     detectedList=peaklist.residue_dict(detectedNuc)[str(toResNum)]
00038     originList=peaklist.residue_dict(detectedNuc)[str(originResNum)]
00039     returnLine=detectedList[0]
00040 
00041     for line in detectedList:
00042 
00043       aveDetectedPPM = _col_ave(detectedList,detectedPPMCol)
00044       aveOriginPPM = _col_ave(originList,originPPMCol)
00045       originAss = originList[0].split()[originAssCol]
00046 
00047     returnLine=xpktools.replace_entry(returnLine,originAssCol+1,originAss)
00048     returnLine=xpktools.replace_entry(returnLine,originPPMCol+1,aveOriginPPM)
00049 
00050   return returnLine
00051 
00052 
00053 def _data_map(labelline):
00054 # Generate a map between datalabels and column number
00055 #   based on a labelline
00056   i=0 # A counter
00057   datamap={} # The data map dictionary
00058   labelList=labelline.split() # Get the label line
00059 
00060   # Get the column number for each label
00061   for i in range(len(labelList)):
00062     datamap[labelList[i]] = i
00063 
00064   return datamap
00065 
00066 def _col_ave(list,col):
00067 # Compute average values from a particular column in a string list
00068   total=0
00069   n=0
00070   for element in list:
00071     total += float(element.split()[col])
00072     n += 1
00073   return total/n