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