Back to index

python-biopython  1.60
Classes | Functions | Variables
Bio.NMR.xpktools Namespace Reference

Classes

class  XpkEntry
class  Peaklist

Functions

def _try_open_read
def _try_open_write
def replace_entry
def _find_start_entry
def data_table
def _sort_keys
def _read_dicts

Variables

int HEADERLEN = 6

Function Documentation

def Bio.NMR.xpktools._find_start_entry (   line,
  n 
) [private]

Definition at line 146 of file xpktools.py.

00146 
00147 def _find_start_entry(line,n):
00148         # find the starting point character for the n'th entry in
00149         # a space delimited line.  n is counted starting with 1
00150         # The n=1 field by definition begins at the first character
00151         # This function is used by replace_entry
00152 
00153         infield=0       # A flag that indicates that the counter is in a field
00154 
00155         if (n==1):
00156                 return 0        # Special case
00157 
00158         # Count the number of fields by counting spaces
00159         c=1
00160         leng=len(line)
00161 
00162         # Initialize variables according to whether the first character
00163         #  is a space or a character
00164         if (line[0]==" "):
00165                 infield=0
00166                 field=0
00167         else:
00168                 infield=1
00169                 field=1
00170 
00171 
00172         while (c<leng and field<n):
00173                 if (infield):
00174                         if (line[c]==" " and not (line[c-1]==" ")):
00175                                 infield=0
00176                 else:
00177                         if (not line[c]==" "):
00178                                 infield=1
00179                                 field=field+1
00180 
00181                 c=c+1
00182 
00183         return c-1
00184 

Here is the caller graph for this function:

def Bio.NMR.xpktools._read_dicts (   fn_list,
  keyatom 
) [private]

Definition at line 226 of file xpktools.py.

00226 
00227 def _read_dicts(fn_list, keyatom):
00228 # Read multiple files into a list of residue dictionaries
00229   dict_list=[]; datalabel_list=[]
00230   for fn in fn_list:
00231     peaklist=Peaklist(fn); dict=peaklist.residue_dict(keyatom)
00232     dict_list.append(dict)
00233     datalabel_list.append(peaklist.datalabels)
00234 
00235   return [dict_list, datalabel_list]

Here is the caller graph for this function:

def Bio.NMR.xpktools._sort_keys (   dictionary) [private]

Definition at line 221 of file xpktools.py.

00221 
00222 def _sort_keys(dictionary):
00223   keys=dictionary.keys()
00224   sorted_keys=keys.sort()
00225   return sorted_keys

def Bio.NMR.xpktools._try_open_read (   fn) [private]

Definition at line 115 of file xpktools.py.

00115 
00116 def _try_open_read(fn):
00117 # Try to open a file for reading.  Exit on IOError
00118   try:
00119     infile=open(fn,'r')
00120   except IOError, e:
00121     print "file", fn, "could not be opened for reading - quitting."
00122     sys.exit(0)
00123   return infile

Here is the call graph for this function:

def Bio.NMR.xpktools._try_open_write (   fn) [private]

Definition at line 124 of file xpktools.py.

00124 
00125 def _try_open_write(fn):
00126 # Try to open a file for writing.  Exit on IOError
00127   try:
00128     infile=open(fn,'w')
00129   except IOError, e:
00130     print "file", fn, "could not be opened for writing - quitting."
00131     sys.exit(0)
00132   return infile
00133 

Here is the call graph for this function:

Here is the caller graph for this function:

def Bio.NMR.xpktools.data_table (   fn_list,
  datalabel,
  keyatom 
)

Definition at line 185 of file xpktools.py.

00185 
00186 def data_table(fn_list, datalabel, keyatom):
00187 # Generate and generate a data table from a list of
00188 # input xpk files <fn_list>.  The data element reported is
00189 # <datalabel> and the index for the data table is by the 
00190 # nucleus indicated by <keyatom>.
00191 
00192   outlist=[]
00193 
00194   [dict_list,label_line_list]=_read_dicts(fn_list,keyatom)
00195 
00196   # Find global max and min residue numbers
00197   minr=dict_list[0]["minres"]; maxr=dict_list[0]["maxres"]
00198  
00199   for dictionary in dict_list:
00200     if (maxr < dictionary["maxres"]):
00201       maxr = dictionary["maxres"]
00202     if (minr > dictionary["minres"]):
00203       minr = dictionary["minres"]
00204 
00205   res=minr
00206   while res <= maxr:        # s.t. res numbers
00207     count=0
00208     line=str(res)
00209     for dictionary in dict_list:      # s.t. dictionaries
00210       label=label_line_list[count]
00211       if str(res) in dictionary:
00212         line=line+"\t"+XpkEntry(dictionary[str(res)][0],label).fields[datalabel]
00213       else:
00214         line=line+"\t"+"*"
00215       count=count+1
00216     line=line+"\n"
00217     outlist.append(line)
00218     res=res+1
00219 
00220   return outlist

Here is the call graph for this function:

def Bio.NMR.xpktools.replace_entry (   line,
  fieldn,
  newentry 
)

Definition at line 134 of file xpktools.py.

00134 
00135 def replace_entry(line,fieldn,newentry):
00136         # Replace an entry in a string by the field number
00137         # No padding is implemented currently.  Spacing will change if
00138         #  the original field entry and the new field entry are of
00139         #  different lengths.
00140         # This method depends on xpktools._find_start_entry
00141 
00142         start=_find_start_entry(line,fieldn)
00143         leng=len(line[start:].split()[0])
00144         newline=line[:start]+str(newentry)+line[(start+leng):]
00145         return newline

Here is the call graph for this function:


Variable Documentation

Definition at line 14 of file xpktools.py.