Package Bio :: Package Restriction
[hide private]
[frames] | no frames]

Source Code for Package Bio.Restriction

  1  #!/usr/bin/env python 
  2  # 
  3  #      Restriction Analysis Libraries. 
  4  #      Copyright (C) 2004. Frederic Sohm. 
  5  # 
  6  # This code is part of the Biopython distribution and governed by its 
  7  # license.  Please see the LICENSE file that should have been included 
  8  # as part of this package. 
  9  # 
 10  """Restriction Digest Enzymes. 
 11   
 12  Example: 
 13   
 14      >>> from Rana.fts import fts    # 
 15      >>> from Rana.Vector import *   # Just a way to get a sequence. 
 16      >>> from Bio.Seq import Seq     # Use your prefered method here. 
 17      >>> pbr = fts(pBR322)           # 
 18      >>> seq = Seq(str(pbr))         # 
 19      >>> 
 20      >>> from Bio.Restriction import * 
 21      >>> a = Analysis(AllEnzymes, seq, linear=False) 
 22      >>> b = a.blunt() 
 23      >>> a.print_that()              # no argument -> print all the results 
 24      AasI       :  2169, 2582. 
 25      AatII      :  4289. 
 26      Acc16I     :  263, 1359, 1457, 3589. 
 27      ... 
 28      More enzymes here. 
 29      ... 
 30      >>> b = a.without_site() 
 31      >>> a.print_that(b)  # Enzymes which do not cut pBR322 
 32      AarI      AatI      Acc65I    AcsI      AcvI      AdeI      AflII     AgeI 
 33      AhlI      AleI      AloI      ApaI      ApoI      AscI      AsiAI     AsiSI 
 34      Asp718I   AspA2I    AsuII     AvaIII    AvrII     AxyI      BaeI      BbrPI 
 35      BbvCI     BclI      BcuI      BfrBI     BfrI      BglII     BlnI      BlpI 
 36      BmgBI     BmgI      BplI      Bpu1102I  Bpu14I    BsaXI     Bse21I    BsePI 
 37      BseRI     BshTI     BsiWI     Bsp119I   Bsp120I   Bsp1407I  Bsp1720I  Bsp19I 
 38      BspT104I  BspTI     BsrGI     BssHI     BssHII    Bst98I    BstAUI    BstBI 
 39      BstEII    BstPI     BstSNI    BstXI     Bsu36I    BtrI      CciNI     CelII 
 40      Cfr42I    Cfr9I     CpoI      Csp45I    CspAI     CspCI     CspI      DraIII 
 41      DrdII     Ecl136II  Eco105I   Eco147I   Eco72I    Eco81I    Eco91I    EcoICRI 
 42      EcoO65I   EcoRI     EcoT22I   EspI      FalI      FbaI      FseI      FunII 
 43      HpaI      KpnI      Ksp22I    KspAI     KspI      MabI      MfeI      MluI 
 44      Mph1103I  MspCI     MssI      MunI      NcoI      NotI      NsiI      NspV 
 45      OliI      PacI      PaeR7I    PasI      PauI      PceI      Pfl23II   PinAI 
 46      PmaCI     PmeI      PmlI      Ppu10I    PsiI      Psp124BI  PspAI     PspCI 
 47      PspEI     PspLI     PspOMI    PspXI     PsrI      RleAI     Rsr2I     RsrII 
 48      SacI      SacII     SanDI     SauI      SbfI      SciI      SdaI      SexAI 
 49      SfiI      Sfr274I   Sfr303I   SfuI      SgfI      SgrBI     SlaI      SmaI 
 50      SmiI      SnaBI     SpeI      SplI      SrfI      Sse232I   Sse8387I  Sse8647I 
 51      SseBI     SspBI     SstI      StuI      SunI      SwaI      TliI      UthSI 
 52      Vha464I   XapI      XbaI      XcmI      XhoI      XmaCI     XmaI      XmaJI 
 53      Zsp2I 
 54   
 55  """ 
 56   
 57  from Bio.Restriction.Restriction import * 
 58   
 59  __docformat__ = "restructuredtext en" 
 60   
 61  # 
 62  #   OK can't put the following code in Bio.Restriction.__init__ unless 
 63  #   I put everything from Restriction in here. 
 64  #   or at least the RestrictionBatch class. 
 65  # 
 66  #   The reason for that is if I do that, I break the __contains__ method of 
 67  #   the RestrictionBatch in Restriction, which expect to find the name of 
 68  #   the enzymes in the locals() dictionary when evaluating string to see if 
 69  #   it is an enzyme. 
 70  # 
 71  #   This call for some explanations I guess: 
 72  #       When testing for the presence of a Restriction enzyme in a 
 73  #       RestrictionBatch, the user can use: 
 74  # 
 75  #           1) a class of type 'RestrictionType' 
 76  #           2) a string of the name of the enzyme (it's repr) 
 77  #               i.e: 
 78  #                   >>> from Bio.Restriction import RestrictionBatch, EcoRI 
 79  #                   >>> MyBatch = RestrictionBatch(EcoRI) 
 80  #                   >>> #!/usr/bin/env python 
 81  #                   >>> EcoRI in MyBatch        # the class EcoRI. 
 82  #                   True 
 83  #                   >>> 
 84  #                   >>> 'EcoRI' in MyBatch      # a string representation 
 85  #                   True 
 86  # 
 87  #   OK, that's how it is suppose to work. And I find it quite useful. 
 88  # 
 89  #   Now if I leave the code here I got: 
 90  #                   >>> from Bio.Restriction import RestrictionBatch, EcoRI 
 91  #                   >>> MyBatch = RestrictionBatch(EcoRI) 
 92  #                   >>> EcoRI in MyBatch # the class EcoRI. 
 93  #                   True 
 94  #                   >>> 'EcoRI' in MyBatch   # a string. 
 95  #                   False 
 96   
 97  #   There is 5 ways to change that: 
 98  #       1) abandon the evaluation of string representation. 
 99  #       2) leave the code like that and hack something in RestrictionBatch. 
100  #       3) Move back the code in Bio.Restriction.Restriction 
101  #       4) Move RestrictionBatch here. 
102  #       5) Remove Restriction.Restriction and move all the code in here 
103  # 
104  #   1) no fun in that. 
105  #   2) there is a simpler way to do it. 
106  #   3) I prefer to keep all the code together. 
107  #   4) and 5) both are OK. Only a matter of preference. 
108  # 
109  #   So the following code has been moved back to Bio.Restricion.Restriction 
110  #   For the user the results is transparent: 
111  #   from Bio.Restriction import * works as before. 
112  # 
113   
114  # ## 
115  # ##   The restriction enzyme classes are created dynamically when the module is 
116  # ##   imported. Here is the magic which allow the creation of the 
117  # ##   restriction-enzyme classes. 
118  # ## 
119  # ##   The reason for the two dictionaries in Restriction_Dictionary 
120  # ##   one for the types (which will be called pseudo-type as they really 
121  # ##   correspond to the values that instances of RestrictionType can take) 
122  # ##   and one for the enzymes is efficiency as the bases are evaluated 
123  # ##   once per pseudo-type. 
124  # ## 
125  # ##   However Restriction is still a very inefficient module at import. But 
126  # ##   remember that around 660 classes (which is more or less the size of Rebase) 
127  # ##   have to be created dynamically. However, this processing take place only 
128  # ##   once. 
129  # ##   This inefficiency is however largely compensated by the use of metaclass 
130  # ##   which provide a very efficient layout for the class themselves mostly 
131  # ##   alleviating the need of if/else loops in the class methods. 
132  # ## 
133  # ##   It is essential to run Restriction with doc string optimisation (-OO switch) 
134  # ##   as the doc string of 660 classes take a lot of processing. 
135  # ## 
136  # # CommOnly    = RestrictionBatch()    # commercial enzymes 
137  # # NonComm     = RestrictionBatch()    # not available commercially 
138  # # for TYPE, (bases, enzymes) in typedict.items(): 
139  # #    # 
140  # #    #   The keys are the pseudo-types TYPE (stored as type1, type2...) 
141  # #    #   The names are not important and are only present to differentiate 
142  # #    #   the keys in the dict. All the pseudo-types are in fact RestrictionType. 
143  # #    #   These names will not be used after and the pseudo-types are not 
144  # #    #   kept in the locals() dictionary. It is therefore impossible to 
145  # #    #   import them. 
146  # #    #   Now, if you have look at the dictionary, you will see that not all the 
147  # #    #   types are present as those without corresponding enzymes have been 
148  # #    #   removed by Dictionary_Builder(). 
149  # #    # 
150  # #    #   The values are tuples which contain 
151  # #    #   as first element a tuple of bases (as string) and 
152  # #    #   as second element the names of the enzymes. 
153  # #    # 
154  # #    #   First eval the bases. 
155  # #    # 
156  # #    bases = tuple(eval(x) for x in bases) 
157  # #    # 
158  # #    #   now create the particular value of RestrictionType for the classes 
159  # #    #   in enzymes. 
160  # #    # 
161  # #    T = type.__new__(RestrictionType, 'RestrictionType', bases, {}) 
162  # #    for k in enzymes: 
163  # #        # 
164  # #        #   Now, we go through all the enzymes and assign them their type. 
165  # #        #   enzymedict[k] contains the values of the attributes for this 
166  # #        #   particular class (self.site, self.ovhg,....). 
167  # #        # 
168  # #        newenz = T(k, bases, enzymedict[k]) 
169  # #        # 
170  # #        #   we add the enzymes to the corresponding batch. 
171  # #        # 
172  # #        #   No need to verify the enzyme is a RestrictionType -> add_nocheck 
173  # #        # 
174  # #        if newenz.is_comm() : CommOnly.add_nocheck(newenz) 
175  # #        else : NonComm.add_nocheck(newenz) 
176  # ## 
177  # ##   AllEnzymes is a RestrictionBatch with all the enzymes from Rebase. 
178  # ## 
179  # # AllEnzymes = CommOnly | NonComm 
180  # ## 
181  # ##   Now, place the enzymes in locals so they can be imported. 
182  # ## 
183  # # names = [str(x) for x in AllEnzymes] 
184  # # locals().update(dict(map(None, names, AllEnzymes))) 
185  # ## 
186  # ##   Limit what can be imported by from Restriction import * 
187  # ##   Most of the classes here will never be used outside this module 
188  # ##   (Defined,Palindromic...). It is still possible to request them specifically 
189  # ## 
190  # ##   also delete the variable that are no longer needed. 
191  # ## 
192  # ## 
193  # # __all__=['Analysis', 'RestrictionBatch','AllEnzymes','CommOnly','NonComm']+names 
194  # # del k, x, enzymes, TYPE, bases, names 
195