Back to index

python-biopython  1.60
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions
Bio.Restriction.PrintFormat.PrintFormat Class Reference
Inheritance diagram for Bio.Restriction.PrintFormat.PrintFormat:
Inheritance graph
[legend]

List of all members.

Public Member Functions

def __init__
def print_as
def print_that
def make_format

Public Attributes

 make_format

Static Public Attributes

 ConsoleWidth = RanaConf.ConsoleWidth
 NameWidth = RanaConf.NameWidth
 MaxSize = RanaConf.MaxSize
 Cmodulo = ConsoleWidth%NameWidth
 PrefWidth = ConsoleWidth-Cmodulo
 Indent = RanaConf.Indent
 linesize = PrefWidth-NameWidth

Private Member Functions

def _make_list
 make* methods to be used with the virtual method make_format
def _make_map
def _make_number
def _make_nocut
def _make_nocut_only
def _make_list_only
def _make_number_only
def _make_map_only
def __next_section
 private method to do lists:

Detailed Description

PrintFormat allow the printing of results of restriction analysis.

Definition at line 63 of file PrintFormat.py.


Constructor & Destructor Documentation

PrintFormat() -> new PrintFormat Instance

Definition at line 74 of file PrintFormat.py.

00074 
00075     def __init__(self):
00076         """PrintFormat() -> new PrintFormat Instance"""
00077         pass


Member Function Documentation

def Bio.Restriction.PrintFormat.PrintFormat.__next_section (   self,
  ls,
  into 
) [private]

private method to do lists:

FP.__next_section(ls, into) -> string.

ls is a list of tuple (string, [int, int]).
into is a string to which the formatted ls will be added.

Format ls as a string of lines:
The form is:

enzyme1     :   position1.
enzyme2     :   position2, position3.

then add the formatted ls to tot
return tot.

Definition at line 386 of file PrintFormat.py.

00386 
00387     def __next_section(self, ls, into):
00388         """FP.__next_section(ls, into) -> string.
00389 
00390         ls is a list of tuple (string, [int, int]).
00391         into is a string to which the formatted ls will be added.
00392 
00393         Format ls as a string of lines:
00394         The form is:
00395 
00396         enzyme1     :   position1.
00397         enzyme2     :   position2, position3.
00398 
00399         then add the formatted ls to tot
00400         return tot."""
00401         ls.sort()
00402         indentation = '\n' + (self.NameWidth + self.Indent) * ' '
00403         linesize = self.linesize - self.MaxSize
00404         pat = re.compile("([\w,\s()]){1,%i}[,\.]"%linesize)
00405         several, Join = '', ''.join
00406         for name, sites in ls:
00407             stringsite = ''
00408             l = Join((', '.join([str(site) for site in sites]), '.'))
00409             if len(l) > linesize:
00410                 #
00411                 #   cut where appropriate and add the indentation
00412                 #
00413                 l = [x.group() for x in re.finditer(pat, l)]
00414                 stringsite = indentation.join(l) 
00415             else:
00416                 stringsite = l    
00417             into = Join((into,
00418                          str(name).ljust(self.NameWidth),' :  ',stringsite,'\n'))
00419         return into

Here is the caller graph for this function:

def Bio.Restriction.PrintFormat.PrintFormat._make_list (   self,
  ls,
  title,
  nc,
  s1 
) [private]

make* methods to be used with the virtual method make_format

PF._make_number(ls,title, nc,s1) -> string.

return a string of form:

title.

enzyme1     :   position1, position2.
enzyme2     :   position1, position2, position3.

ls is a list of cutting enzymes.
title is the title.
nc is a list of non cutting enzymes.
s1 is the sentence before the non cutting enzymes.

Definition at line 132 of file PrintFormat.py.

00132 
00133     def _make_list(self, ls,title, nc,s1):
00134         """PF._make_number(ls,title, nc,s1) -> string.
00135 
00136         return a string of form:
00137         
00138         title.
00139 
00140         enzyme1     :   position1, position2.
00141         enzyme2     :   position1, position2, position3.
00142 
00143         ls is a list of cutting enzymes.
00144         title is the title.
00145         nc is a list of non cutting enzymes.
00146         s1 is the sentence before the non cutting enzymes."""
00147         return self._make_list_only(ls, title) + self._make_nocut_only(nc, s1)

Here is the call graph for this function:

Here is the caller graph for this function:

def Bio.Restriction.PrintFormat.PrintFormat._make_list_only (   self,
  ls,
  title,
  nc = [],
  s1 = '' 
) [private]
PF._make_list_only(ls, title) -> string.

return a string of form:

title.

enzyme1     :   position1, position2.
enzyme2     :   position1, position2, position3.
...

ls is a list of results.
title is a string.
Non cutting enzymes are not included.

Definition at line 222 of file PrintFormat.py.

00222 
00223     def _make_list_only(self, ls, title, nc = [], s1 = ''):
00224         """PF._make_list_only(ls, title) -> string.
00225 
00226         return a string of form:
00227         
00228         title.
00229 
00230         enzyme1     :   position1, position2.
00231         enzyme2     :   position1, position2, position3.
00232         ...
00233         
00234         ls is a list of results.
00235         title is a string.
00236         Non cutting enzymes are not included."""
00237         if not ls:
00238             return title
00239         return self.__next_section(ls, title)

Here is the call graph for this function:

Here is the caller graph for this function:

def Bio.Restriction.PrintFormat.PrintFormat._make_map (   self,
  ls,
  title,
  nc,
  s1 
) [private]
PF._make_number(ls,title, nc,s1) -> string.

return a string of form:

title.

    enzyme1, position
    |
AAAAAAAAAAAAAAAAAAAAA...
|||||||||||||||||||||
TTTTTTTTTTTTTTTTTTTTT...

ls is a list of cutting enzymes.
title is the title.
nc is a list of non cutting enzymes.
s1 is the sentence before the non cutting enzymes.

Definition at line 148 of file PrintFormat.py.

00148 
00149     def _make_map(self, ls,title, nc,s1):
00150         """PF._make_number(ls,title, nc,s1) -> string.
00151 
00152         return a string of form:
00153         
00154         title.
00155 
00156             enzyme1, position
00157             |
00158         AAAAAAAAAAAAAAAAAAAAA...
00159         |||||||||||||||||||||
00160         TTTTTTTTTTTTTTTTTTTTT...
00161 
00162         ls is a list of cutting enzymes.
00163         title is the title.
00164         nc is a list of non cutting enzymes.
00165         s1 is the sentence before the non cutting enzymes."""
00166         return self._make_map_only(ls, title) + self._make_nocut_only(nc, s1)

Here is the call graph for this function:

def Bio.Restriction.PrintFormat.PrintFormat._make_map_only (   self,
  ls,
  title,
  nc = [],
  s1 = '' 
) [private]
PF._make_map_only(ls, title) -> string.

return a string of form:

title.

    enzyme1, position
    |
AAAAAAAAAAAAAAAAAAAAA...
|||||||||||||||||||||
TTTTTTTTTTTTTTTTTTTTT...


ls is a list of results.
title is a string.
Non cutting enzymes are not included.

Definition at line 277 of file PrintFormat.py.

00277 
00278     def _make_map_only(self, ls, title, nc = [],  s1 = ''):
00279         """PF._make_map_only(ls, title) -> string.
00280 
00281         return a string of form:
00282         
00283         title.
00284 
00285             enzyme1, position
00286             |
00287         AAAAAAAAAAAAAAAAAAAAA...
00288         |||||||||||||||||||||
00289         TTTTTTTTTTTTTTTTTTTTT...
00290         
00291                 
00292         ls is a list of results.
00293         title is a string.
00294         Non cutting enzymes are not included.
00295         """
00296         if not ls:
00297             return title
00298         resultKeys = [str(x) for x,y in ls]
00299         resultKeys.sort()
00300         map = title or ''
00301         enzymemap = {}
00302         for (enzyme, cut) in ls:
00303             for c in cut:
00304                 if c in enzymemap:
00305                     enzymemap[c].append(str(enzyme))
00306                 else:
00307                     enzymemap[c] = [str(enzyme)]
00308         mapping = enzymemap.keys()
00309         mapping.sort()
00310         cutloc = {}
00311         x, counter, length = 0, 0, len(self.sequence)
00312         for x in xrange(60, length, 60):
00313             counter = x - 60
00314             l=[]
00315             for key in mapping:
00316                 if key <= x:
00317                     l.append(key)
00318                 else:
00319                     cutloc[counter] = l
00320                     mapping = mapping[mapping.index(key):]
00321                     break
00322             cutloc[x] = l
00323         cutloc[x] = mapping
00324         sequence = self.sequence.tostring()
00325         revsequence = self.sequence.complement().tostring()
00326         a = '|'
00327         base, counter = 0, 0
00328         emptyline = ' ' * 60
00329         Join = ''.join
00330         for base in xrange(60, length, 60):
00331             counter = base - 60
00332             line = emptyline
00333             for key in cutloc[counter]:
00334                 s = ''
00335                 if key == base:
00336                     for n in enzymemap[key] : s = ' '.join((s,n))
00337                     l = line[0:59]
00338                     lineo = Join((l, str(key), s, '\n'))
00339                     line2 = Join((l, a, '\n'))
00340                     linetot = Join((lineo, line2))
00341                     map = Join((map, linetot))
00342                     break
00343                 for n in enzymemap[key] : s = ' '.join((s,n))
00344                 k = key%60
00345                 lineo = Join((line[0:(k-1)], str(key), s, '\n'))
00346                 line = Join((line[0:(k-1)], a, line[k:]))
00347                 line2 = Join((line[0:(k-1)], a, line[k:], '\n'))
00348                 linetot = Join((lineo,line2))
00349                 map = Join((map,linetot))
00350             mapunit = '\n'.join((sequence[counter : base],a * 60,
00351                                  revsequence[counter : base],
00352                                  Join((str.ljust(str(counter+1), 15), ' '* 30,
00353                                         str.rjust(str(base), 15),'\n\n'))
00354                                  ))
00355             map = Join((map, mapunit)) 
00356         line = ' '* 60
00357         for key in cutloc[base]:
00358             s = ''
00359             if key == length:
00360                 for n in enzymemap[key]:
00361                     s = Join((s,' ',n))
00362                 l = line[0:(length-1)]
00363                 lineo = Join((l,str(key),s,'\n'))
00364                 line2 = Join((l,a,'\n'))
00365                 linetot = Join((lineo, line2))
00366                 map = Join((map, linetot))
00367                 break
00368             for n in enzymemap[key] : s = Join((s,' ',n))
00369             k = key%60
00370             lineo = Join((line[0:(k-1)],str(key),s,'\n'))
00371             line = Join((line[0:(k-1)],a,line[k:]))
00372             line2 = Join((line[0:(k-1)],a,line[k:],'\n'))
00373             linetot = Join((lineo,line2))
00374             map = Join((map,linetot))
00375         mapunit = ''
00376         mapunit = Join((sequence[base : length], '\n'))
00377         mapunit = Join((mapunit, a * (length-base), '\n'))
00378         mapunit = Join((mapunit,revsequence[base:length], '\n'))
00379         mapunit = Join((mapunit, Join((str.ljust(str(base+1), 15), ' '*(
00380             length-base-30),str.rjust(str(length), 15),
00381                                        '\n\n'))))
00382         map = Join((map,mapunit))
00383         return map
    

Here is the call graph for this function:

Here is the caller graph for this function:

def Bio.Restriction.PrintFormat.PrintFormat._make_nocut (   self,
  ls,
  title,
  nc,
  s1 
) [private]
PF._make_nocut(ls,title, nc,s1) -> string.

return a formatted string of the non cutting enzymes.

ls is a list of cutting enzymes -> will not be used.
Here for compatibility with make_format.

title is the title.
nc is a list of non cutting enzymes.
s1 is the sentence before the non cutting enzymes.

Definition at line 187 of file PrintFormat.py.

00187 
00188     def _make_nocut(self, ls,title, nc,s1):
00189         """PF._make_nocut(ls,title, nc,s1) -> string.
00190 
00191         return a formatted string of the non cutting enzymes.
00192 
00193         ls is a list of cutting enzymes -> will not be used.
00194         Here for compatibility with make_format.
00195         
00196         title is the title.
00197         nc is a list of non cutting enzymes.
00198         s1 is the sentence before the non cutting enzymes."""
00199         return title + self._make_nocut_only(nc, s1) 

Here is the call graph for this function:

def Bio.Restriction.PrintFormat.PrintFormat._make_nocut_only (   self,
  nc,
  s1,
  ls = [],
  title = '' 
) [private]
PF._make_nocut_only(nc, s1) -> string.

return a formatted string of the non cutting enzymes.

nc is a list of non cutting enzymes.
s1 is the sentence before the non cutting enzymes.

Definition at line 200 of file PrintFormat.py.

00200 
00201     def _make_nocut_only(self, nc, s1, ls =[],title=''):
00202         """PF._make_nocut_only(nc, s1) -> string.
00203 
00204         return a formatted string of the non cutting enzymes.
00205         
00206         nc is a list of non cutting enzymes.
00207         s1 is the sentence before the non cutting enzymes.
00208         """
00209         if not nc:
00210             return s1
00211         nc.sort()
00212         st = ''
00213         stringsite = s1 or '\n   Enzymes which do not cut the sequence.\n\n'    
00214         Join = ''.join
00215         for key in nc:
00216             st = Join((st, str.ljust(str(key), self.NameWidth)))
00217             if len(st) > self.linesize:
00218                 stringsite = Join((stringsite, st, '\n'))
00219                 st = ''
00220         stringsite = Join((stringsite, st, '\n'))
00221         return stringsite
    

Here is the caller graph for this function:

def Bio.Restriction.PrintFormat.PrintFormat._make_number (   self,
  ls,
  title,
  nc,
  s1 
) [private]
PF._make_number(ls,title, nc,s1) -> string.

title.

enzyme which cut 1 time:

enzyme1     :   position1.

enzyme which cut 2 times:

enzyme2     :   position1, position2.
...

ls is a list of cutting enzymes.
title is the title.
nc is a list of non cutting enzymes.
s1 is the sentence before the non cutting enzymes.

Definition at line 167 of file PrintFormat.py.

00167 
00168     def _make_number(self, ls,title, nc,s1):
00169         """PF._make_number(ls,title, nc,s1) -> string.
00170 
00171         title.
00172         
00173         enzyme which cut 1 time:
00174         
00175         enzyme1     :   position1.
00176 
00177         enzyme which cut 2 times:
00178         
00179         enzyme2     :   position1, position2.
00180         ...
00181 
00182         ls is a list of cutting enzymes.
00183         title is the title.
00184         nc is a list of non cutting enzymes.
00185         s1 is the sentence before the non cutting enzymes."""
00186         return self._make_number_only(ls, title)+self._make_nocut_only(nc,s1)
    

Here is the call graph for this function:

def Bio.Restriction.PrintFormat.PrintFormat._make_number_only (   self,
  ls,
  title,
  nc = [],
  s1 = '' 
) [private]
PF._make_number_only(ls, title) -> string.

return a string of form:

title.

enzyme which cut 1 time:

enzyme1     :   position1.

enzyme which cut 2 times:

enzyme2     :   position1, position2.
...


ls is a list of results.
title is a string.
Non cutting enzymes are not included.

Definition at line 240 of file PrintFormat.py.

00240 
00241     def _make_number_only(self, ls, title, nc = [], s1 =''):
00242         """PF._make_number_only(ls, title) -> string.
00243 
00244         return a string of form:
00245         
00246         title.
00247         
00248         enzyme which cut 1 time:
00249         
00250         enzyme1     :   position1.
00251 
00252         enzyme which cut 2 times:
00253         
00254         enzyme2     :   position1, position2.
00255         ...
00256         
00257                 
00258         ls is a list of results.
00259         title is a string.
00260         Non cutting enzymes are not included."""
00261         if not ls:
00262             return title
00263         ls.sort(lambda x,y : cmp(len(x[1]), len(y[1])))
00264         iterator = iter(ls)
00265         cur_len  = 1
00266         new_sect = []
00267         for name, sites in iterator:
00268             l = len(sites)
00269             if l > cur_len:
00270                 title += "\n\nenzymes which cut %i times :\n\n"%cur_len
00271                 title = self.__next_section(new_sect, title)
00272                 new_sect, cur_len = [(name, sites)], l
00273                 continue
00274             new_sect.append((name,sites))
00275         title += "\n\nenzymes which cut %i times :\n\n"%cur_len
00276         return self.__next_section(new_sect, title)
            

Here is the call graph for this function:

Here is the caller graph for this function:

def Bio.Restriction.PrintFormat.PrintFormat.make_format (   self,
  cut = [],
  title = '',
  nc = [],
  s1 = '' 
)
PF.make_format(cut, nc, title, s) -> string

Virtual method.
Here to be pointed to one of the _make_* methods.
You can as well create a new method and point make_format to it.

Definition at line 122 of file PrintFormat.py.

00122 
00123     def make_format(self, cut=[], title='', nc=[], s1=''):
00124         """PF.make_format(cut, nc, title, s) -> string
00125 
00126         Virtual method.
00127         Here to be pointed to one of the _make_* methods.
00128         You can as well create a new method and point make_format to it."""
00129         return self._make_list(cut,title, nc,s1)

Here is the call graph for this function:

def Bio.Restriction.PrintFormat.PrintFormat.print_as (   self,
  what = 'list' 
)
PF.print_as([what='list']) -> print the results as specified.

Valid format are:
    'list'      -> alphabetical order
    'number'    -> number of sites in the sequence
    'map'       -> a map representation of the sequence with the sites.

If you want more flexibility over-ride the virtual method make_format.

Definition at line 78 of file PrintFormat.py.

00078 
00079     def print_as(self, what='list'):
00080         """PF.print_as([what='list']) -> print the results as specified.
00081 
00082         Valid format are:
00083             'list'      -> alphabetical order
00084             'number'    -> number of sites in the sequence
00085             'map'       -> a map representation of the sequence with the sites.
00086 
00087         If you want more flexibility over-ride the virtual method make_format.
00088         """
00089         if what == 'map':
00090             self.make_format = self._make_map
00091         elif what == 'number':
00092             self.make_format = self._make_number
00093         else:
00094             self.make_format = self._make_list
00095             
00096         return
00097             

def Bio.Restriction.PrintFormat.PrintFormat.print_that (   self,
  dct,
  title = '',
  s1 = '' 
)
PF.print_that(dct, [title[, s1]]) -> Print dct nicely formatted.

dct is a dictionary as returned by a RestrictionBatch.search()

title is the title of the map.
It must be a formated string, i.e. you must include the line break.

s1 is the title separating the list of enzymes that have sites from
those without sites.
s1 must be a formatted string as well.

The format of print_that is a list.

Reimplemented in Bio.Restriction.Restriction.Analysis.

Definition at line 98 of file PrintFormat.py.

00098 
00099     def print_that(self, dct, title='',  s1=''):
00100         """PF.print_that(dct, [title[, s1]]) -> Print dct nicely formatted.
00101 
00102         dct is a dictionary as returned by a RestrictionBatch.search()
00103         
00104         title is the title of the map.
00105         It must be a formated string, i.e. you must include the line break.
00106         
00107         s1 is the title separating the list of enzymes that have sites from
00108         those without sites.
00109         s1 must be a formatted string as well.
00110 
00111         The format of print_that is a list."""
00112         if not dct:
00113             dct = self.results
00114         ls, nc = [], []
00115         for k, v in dct.iteritems():
00116             if v:
00117                 ls.append((k,v))
00118             else:
00119                 nc.append(k)
00120         print self.make_format(ls, title, nc, s1)
00121         return
       

Member Data Documentation

Reimplemented in Bio.Restriction.Restriction.Analysis.

Definition at line 69 of file PrintFormat.py.

Bio.Restriction.PrintFormat.PrintFormat.ConsoleWidth = RanaConf.ConsoleWidth [static]

Definition at line 66 of file PrintFormat.py.

Definition at line 71 of file PrintFormat.py.

Definition at line 72 of file PrintFormat.py.

Definition at line 89 of file PrintFormat.py.

Definition at line 68 of file PrintFormat.py.

Definition at line 67 of file PrintFormat.py.

Reimplemented in Bio.Restriction.Restriction.Analysis.

Definition at line 70 of file PrintFormat.py.


The documentation for this class was generated from the following file: