Back to index

python-biopython  1.60
__init__.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 #      Restriction Analysis Libraries.
00004 #      Copyright (C) 2004. Frederic Sohm.
00005 #
00006 # This code is part of the Biopython distribution and governed by its
00007 # license.  Please see the LICENSE file that should have been included
00008 # as part of this package.
00009 #
00010 """
00011 Usage:
00012 =====
00013 
00014     >>> from Rana.fts import fts    # 
00015     >>> from Rana.Vector import *   # Just a way to get a sequence.
00016     >>> from Bio.Seq import Seq     # Use your prefer method here.
00017     >>> pbr = fts(pBR322)           #
00018     >>> seq = Seq(str(pbr))         #
00019     >>>
00020     >>> from Bio.Restriction import *
00021     >>> a = Analysis(AllEnzymes, seq, linear=False)
00022     >>> b = a.blunt()
00023     >>> a.print_that()              # no argument -> print all the results
00024     AasI       :  2169, 2582.
00025     AatII      :  4289.
00026     Acc16I     :  263, 1359, 1457, 3589.
00027     ...
00028         More enzymes here.
00029     ...
00030     >>> b = a.without_site()
00031     >>> a.print_that(b, '', '\n Enzymes which do not cut pBR322.\n\n')
00032 
00033      Enzymes which do not cut pBR322.
00034 
00035     AarI      AatI      Acc65I    AcsI      AcvI      AdeI      AflII     AgeI      
00036     AhlI      AleI      AloI      ApaI      ApoI      AscI      AsiAI     AsiSI     
00037     Asp718I   AspA2I    AsuII     AvaIII    AvrII     AxyI      BaeI      BbrPI     
00038     BbvCI     BclI      BcuI      BfrBI     BfrI      BglII     BlnI      BlpI      
00039     BmgBI     BmgI      BplI      Bpu1102I  Bpu14I    BsaXI     Bse21I    BsePI     
00040     BseRI     BshTI     BsiWI     Bsp119I   Bsp120I   Bsp1407I  Bsp1720I  Bsp19I    
00041     BspT104I  BspTI     BsrGI     BssHI     BssHII    Bst98I    BstAUI    BstBI     
00042     BstEII    BstPI     BstSNI    BstXI     Bsu36I    BtrI      CciNI     CelII     
00043     Cfr42I    Cfr9I     CpoI      Csp45I    CspAI     CspCI     CspI      DraIII    
00044     DrdII     Ecl136II  Eco105I   Eco147I   Eco72I    Eco81I    Eco91I    EcoICRI   
00045     EcoO65I   EcoRI     EcoT22I   EspI      FalI      FbaI      FseI      FunII     
00046     HpaI      KpnI      Ksp22I    KspAI     KspI      MabI      MfeI      MluI      
00047     Mph1103I  MspCI     MssI      MunI      NcoI      NotI      NsiI      NspV      
00048     OliI      PacI      PaeR7I    PasI      PauI      PceI      Pfl23II   PinAI     
00049     PmaCI     PmeI      PmlI      Ppu10I    PsiI      Psp124BI  PspAI     PspCI     
00050     PspEI     PspLI     PspOMI    PspXI     PsrI      RleAI     Rsr2I     RsrII     
00051     SacI      SacII     SanDI     SauI      SbfI      SciI      SdaI      SexAI     
00052     SfiI      Sfr274I   Sfr303I   SfuI      SgfI      SgrBI     SlaI      SmaI      
00053     SmiI      SnaBI     SpeI      SplI      SrfI      Sse232I   Sse8387I  Sse8647I  
00054     SseBI     SspBI     SstI      StuI      SunI      SwaI      TliI      UthSI     
00055     Vha464I   XapI      XbaI      XcmI      XhoI      XmaCI     XmaI      XmaJI     
00056     Zsp2I     
00057 
00058     >>>
00059     """
00060 
00061 from Bio.Restriction.Restriction import *
00062 #
00063 #   OK can't put the following code in Bio.Restriction.__init__ unless
00064 #   I put everything from Restriction in here.
00065 #   or at least the RestrictionBatch class.
00066 #
00067 #   The reason for that is if I do that, I break the __contains__ method of
00068 #   the RestrictionBatch in Restriction, which expect to find the name of
00069 #   the enzymes in the locals() dictionary when evaluating string to see if
00070 #   it is an enzyme.
00071 #
00072 #   This call for some explanations I guess:
00073 #       When testing for the presence of a Restriction enzyme in a
00074 #       RestrictionBatch, the user can use:
00075 #
00076 #           1) a class of type 'RestrictionType'
00077 #           2) a string of the name of the enzyme (it's repr)
00078 #               i.e:
00079 #                   >>> from Bio.Restriction import RestrictionBatch, EcoRI
00080 #                   >>> MyBatch = RestrictionBatch(EcoRI)
00081 #                   >>> #!/usr/bin/env python
00082 #                   >>> EcoRI in MyBatch        # the class EcoRI.
00083 #                   True
00084 #                   >>>
00085 #                   >>> 'EcoRI' in MyBatch      # a string representation
00086 #                   True
00087 #
00088 #   OK, that's how it is suppose to work. And I find it quite useful.
00089 #
00090 #   Now if I leave the code here I got:
00091 #                   >>> from Bio.Restriction import RestrictionBatch, EcoRI
00092 #                   >>> MyBatch = RestrictionBatch(EcoRI)
00093 #                   >>> EcoRI in MyBatch # the class EcoRI.
00094 #                   True
00095 #                   >>> 'EcoRI' in MyBatch   # a string.
00096 #                   False
00097 
00098 #   There is 5 ways to change that:
00099 #       1) abandon the evaluation of string representation.
00100 #       2) leave the code like that and hack something in RestrictionBatch.
00101 #       3) Move back the code in Bio.Restriction.Restriction
00102 #       4) Move RestrictionBatch here.
00103 #       5) Remove Restriction.Restriction and move all the code in here
00104 #
00105 #   1) no fun in that.
00106 #   2) there is a simpler way to do it.
00107 #   3) I prefer to keep all the code together.
00108 #   4) and 5) both are OK. Only a matter of preference.
00109 #
00110 #   So the following code has been moved back to Bio.Restricion.Restriction
00111 #   For the user the results is transparent:
00112 #   from Bio.Restriction import * works as before.
00113 #
00114         
00115 ###
00116 ###   The restriction enzyme classes are created dynamically when the module is
00117 ###   imported. Here is the magic which allow the creation of the
00118 ###   restriction-enzyme classes.
00119 ###
00120 ###   The reason for the two dictionaries in Restriction_Dictionary
00121 ###   one for the types (which will be called pseudo-type as they really
00122 ###   correspond to the values that instances of RestrictionType can take)
00123 ###   and one for the enzymes is efficiency as the bases are evaluated
00124 ###   once per pseudo-type.
00125 ###
00126 ###   However Restriction is still a very inefficient module at import. But
00127 ###   remember that around 660 classes (which is more or less the size of Rebase)
00128 ###   have to be created dynamically. However, this processing take place only
00129 ###   once.
00130 ###   This inefficiency is however largely compensated by the use of metaclass
00131 ###   which provide a very efficient layout for the class themselves mostly
00132 ###   alleviating the need of if/else loops in the class methods.
00133 ###
00134 ###   It is essential to run Restriction with doc string optimisation (-OO switch)
00135 ###   as the doc string of 660 classes take a lot of processing.
00136 ###
00137 ##CommOnly    = RestrictionBatch()    # commercial enzymes
00138 ##NonComm     = RestrictionBatch()    # not available commercially
00139 ##for TYPE, (bases, enzymes) in typedict.iteritems():
00140 ##    #
00141 ##    #   The keys are the pseudo-types TYPE (stored as type1, type2...)
00142 ##    #   The names are not important and are only present to differentiate
00143 ##    #   the keys in the dict. All the pseudo-types are in fact RestrictionType.
00144 ##    #   These names will not be used after and the pseudo-types are not
00145 ##    #   kept in the locals() dictionary. It is therefore impossible to
00146 ##    #   import them.
00147 ##    #   Now, if you have look at the dictionary, you will see that not all the
00148 ##    #   types are present as those without corresponding enzymes have been
00149 ##    #   removed by Dictionary_Builder().
00150 ##    #
00151 ##    #   The values are tuples which contain
00152 ##    #   as first element a tuple of bases (as string) and
00153 ##    #   as second element the names of the enzymes.
00154 ##    #
00155 ##    #   First eval the bases.
00156 ##    #
00157 ##    bases = tuple([eval(x) for x in bases])
00158 ##    #
00159 ##    #   now create the particular value of RestrictionType for the classes
00160 ##    #   in enzymes.
00161 ##    #
00162 ##    T = type.__new__(RestrictionType, 'RestrictionType', bases, {})
00163 ##    for k in enzymes:
00164 ##        #
00165 ##        #   Now, we go through all the enzymes and assign them their type.
00166 ##        #   enzymedict[k] contains the values of the attributes for this
00167 ##        #   particular class (self.site, self.ovhg,....).
00168 ##        #
00169 ##        newenz = T(k, bases, enzymedict[k])
00170 ##        #
00171 ##        #   we add the enzymes to the corresponding batch.
00172 ##        #
00173 ##        #   No need to verify the enzyme is a RestrictionType -> add_nocheck
00174 ##        #
00175 ##        if newenz.is_comm() : CommOnly.add_nocheck(newenz)
00176 ##        else : NonComm.add_nocheck(newenz)
00177 ###
00178 ###   AllEnzymes is a RestrictionBatch with all the enzymes from Rebase.
00179 ###
00180 ##AllEnzymes = CommOnly | NonComm
00181 ###
00182 ###   Now, place the enzymes in locals so they can be imported.
00183 ###
00184 ##names = [str(x) for x in AllEnzymes]
00185 ##locals().update(dict(map(None, names, AllEnzymes)))
00186 ###
00187 ###   Limit what can be imported by from Restriction import *
00188 ###   Most of the classes here will never be used outside this module
00189 ###   (Defined,Palindromic...). It is still possible to request them specifically
00190 ###
00191 ###   also delete the variable that are no longer needed.
00192 ###   
00193 ###
00194 ##__all__=['Analysis', 'RestrictionBatch','AllEnzymes','CommOnly','NonComm']+names
00195 ##del k, x, enzymes, TYPE, bases, names