Back to index

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

List of all members.

Public Member Functions

def __init__
def __str__
def __repr__
def __contains__
def __div__
def __rdiv__
def get
def lambdasplit
def add_supplier
def current_suppliers
def __iadd__
def __add__
def remove
def add
def add_nocheck
def format
def is_restriction
def split
def elements
def as_string
def suppl_codes
def show_codes
def search

Public Attributes

 mapping
 already_mapped

Detailed Description

Definition at line 1822 of file Restriction.py.


Constructor & Destructor Documentation

def Bio.Restriction.Restriction.RestrictionBatch.__init__ (   self,
  first = [],
  suppliers = [] 
)
RestrictionBatch([sequence]) -> new RestrictionBatch.

Definition at line 1824 of file Restriction.py.

01824 
01825     def __init__(self, first=[], suppliers=[]):
01826         """RestrictionBatch([sequence]) -> new RestrictionBatch."""
01827         first = [self.format(x) for x in first]
01828         first += [eval(x) for n in suppliers for x in suppliers_dict[n][1]]
01829         set.__init__(self, first)
01830         self.mapping = dict.fromkeys(self)
01831         self.already_mapped = None
            

Here is the call graph for this function:


Member Function Documentation

b + other -> new RestrictionBatch.

Definition at line 1909 of file Restriction.py.

01909 
01910     def __add__(self, other):
01911         """ b + other -> new RestrictionBatch."""
01912         new = self.__class__(self)
01913         new.add(other)
01914         return new

Definition at line 1842 of file Restriction.py.

01842 
01843     def __contains__(self, other):
01844         try:
01845             other = self.format(other)
01846         except ValueError : # other is not a restriction enzyme
01847             return False
01848         return set.__contains__(self, other)
    

Here is the call graph for this function:

Definition at line 1849 of file Restriction.py.

01849 
01850     def __div__(self, other):
01851         return self.search(other)
    

Here is the call graph for this function:

b += other -> add other to b, check the type of other.

Definition at line 1904 of file Restriction.py.

01904 
01905     def __iadd__(self, other):
01906         """ b += other -> add other to b, check the type of other."""
01907         self.add(other)
01908         return self

Here is the call graph for this function:

Definition at line 1852 of file Restriction.py.

01852 
01853     def __rdiv__(self, other):
01854         return self.search(other)

Here is the call graph for this function:

Reimplemented in Bio.Restriction.Restriction.Analysis.

Definition at line 1839 of file Restriction.py.

01839 
01840     def __repr__(self):
01841         return 'RestrictionBatch(%s)' % self.elements()
    

Here is the call graph for this function:

Definition at line 1832 of file Restriction.py.

01832 
01833     def __str__(self):
01834         if len(self) < 5:
01835             return '+'.join(self.elements())
01836         else:
01837             return '...'.join(('+'.join(self.elements()[:2]),\
01838                                '+'.join(self.elements()[-2:])))

Here is the call graph for this function:

B.add(other) -> add other to B if other is a RestrictionType.

Safe set.add method. Verify that other is a RestrictionType or can be
evaluated to a RestrictionType.
raise a ValueError if other can not be evaluated to a RestrictionType.

Definition at line 1924 of file Restriction.py.

01924 
01925     def add(self, other):
01926         """B.add(other) -> add other to B if other is a RestrictionType.
01927 
01928         Safe set.add method. Verify that other is a RestrictionType or can be
01929         evaluated to a RestrictionType.
01930         raise a ValueError if other can not be evaluated to a RestrictionType.
01931         """
01932         return set.add(self, self.format(other))

Here is the call graph for this function:

Here is the caller graph for this function:

B.add_nocheck(other) -> add other to B. don't check type of other.

Definition at line 1933 of file Restriction.py.

01933 
01934     def add_nocheck(self, other):
01935         """B.add_nocheck(other) -> add other to B. don't check type of other.
01936         """
01937         return set.add(self, other)
        

Here is the caller graph for this function:

B.add_supplier(letter) -> add a new set of enzyme to B.

letter represents the suppliers as defined in the dictionary
RestrictionDictionary.suppliers
return None.
raise a KeyError if letter is not a supplier code.

Definition at line 1882 of file Restriction.py.

01882 
01883     def add_supplier(self, letter):
01884         """B.add_supplier(letter) -> add a new set of enzyme to B.
01885 
01886         letter represents the suppliers as defined in the dictionary
01887         RestrictionDictionary.suppliers
01888         return None.
01889         raise a KeyError if letter is not a supplier code."""
01890         supplier = suppliers_dict[letter]
01891         self.suppliers.append(letter)
01892         for x in supplier[1]:
01893             self.add_nocheck(eval(x))
01894         return

Here is the call graph for this function:

B.as_string() -> list.

return a list of the name of the elements of B.

Definition at line 1995 of file Restriction.py.

01995 
01996     def as_string(self):
01997         """B.as_string() -> list.
01998 
01999         return a list of the name of the elements of B."""
02000         return [str(e) for e in self]

B.current_suppliers() -> add a new set of enzyme to B.

return a sorted list of the suppliers which have been used to
create the batch.

Definition at line 1895 of file Restriction.py.

01895 
01896     def current_suppliers(self):
01897         """B.current_suppliers() -> add a new set of enzyme to B.
01898 
01899         return a sorted list of the suppliers which have been used to
01900         create the batch."""
01901         suppl_list = [suppliers_dict[x][0] for x in self.suppliers]
01902         suppl_list.sort()
01903         return suppl_list

Here is the call graph for this function:

B.elements() -> tuple.

give all the names of the enzymes in B sorted alphabetically.

Definition at line 1987 of file Restriction.py.

01987 
01988     def elements(self):
01989         """B.elements() -> tuple.
01990 
01991         give all the names of the enzymes in B sorted alphabetically."""
01992         l = [str(e) for e in self]
01993         l.sort()
01994         return l

Here is the caller graph for this function:

B.format(y) -> RestrictionType or raise ValueError.

if y is a RestrictionType return y
if y can be evaluated to a RestrictionType return eval(y)
raise a Value Error in all other case.

Definition at line 1938 of file Restriction.py.

01938 
01939     def format(self, y):
01940         """B.format(y) -> RestrictionType or raise ValueError.
01941 
01942         if y is a RestrictionType return y
01943         if y can be evaluated to a RestrictionType return eval(y)
01944         raise a Value Error in all other case."""
01945         try:
01946             if isinstance(y, RestrictionType):
01947                 return y
01948             elif isinstance(eval(str(y)), RestrictionType):
01949                 return eval(y)
01950             
01951             else:
01952                 pass
01953         except (NameError, SyntaxError):
01954             pass
01955         raise ValueError('%s is not a RestrictionType' % y.__class__)
01956         

Here is the caller graph for this function:

def Bio.Restriction.Restriction.RestrictionBatch.get (   self,
  enzyme,
  add = False 
)
B.get(enzyme[, add]) -> enzyme class.

if add is True and enzyme is not in B add enzyme to B.
if add is False (which is the default) only return enzyme.
if enzyme is not a RestrictionType or can not be evaluated to
a RestrictionType, raise a ValueError.

Definition at line 1855 of file Restriction.py.

01855 
01856     def get(self, enzyme, add=False):
01857         """B.get(enzyme[, add]) -> enzyme class.
01858 
01859         if add is True and enzyme is not in B add enzyme to B.
01860         if add is False (which is the default) only return enzyme.
01861         if enzyme is not a RestrictionType or can not be evaluated to
01862         a RestrictionType, raise a ValueError."""
01863         e = self.format(enzyme)
01864         if e in self:
01865             return e
01866         elif add:
01867             self.add(e)
01868             return e
01869         else:
01870             raise ValueError('enzyme %s is not in RestrictionBatch' \
01871                              % e.__name__)

Here is the call graph for this function:

B.is_restriction(y) -> bool.

True is y or eval(y) is a RestrictionType.

Definition at line 1957 of file Restriction.py.

01957 
01958     def is_restriction(self, y):
01959         """B.is_restriction(y) -> bool.
01960 
01961         True is y or eval(y) is a RestrictionType.""" 
01962         return isinstance(y, RestrictionType) or \
01963                isinstance(eval(str(y)), RestrictionType)
    
B.lambdasplit(func) -> RestrictionBatch .

the new batch will contains only the enzymes for which
func return True.

Definition at line 1872 of file Restriction.py.

01872 
01873     def lambdasplit(self, func):
01874         """B.lambdasplit(func) -> RestrictionBatch .
01875 
01876         the new batch will contains only the enzymes for which
01877         func return True."""
01878         d = [x for x in itertools.ifilter(func, self)]
01879         new = RestrictionBatch()
01880         new._data = dict(zip(d, [True]*len(d)))
01881         return new

B.remove(other) -> remove other from B if other is a RestrictionType.

Safe set.remove method. Verify that other is a RestrictionType or can be
evaluated to a RestrictionType.
raise a ValueError if other can not be evaluated to a RestrictionType.
raise a KeyError if other is not in B.

Definition at line 1915 of file Restriction.py.

01915 
01916     def remove(self, other):
01917         """B.remove(other) -> remove other from B if other is a RestrictionType.
01918 
01919         Safe set.remove method. Verify that other is a RestrictionType or can be
01920         evaluated to a RestrictionType.
01921         raise a ValueError if other can not be evaluated to a RestrictionType.
01922         raise a KeyError if other is not in B."""
01923         return set.remove(self, self.format(other))

Here is the call graph for this function:

def Bio.Restriction.Restriction.RestrictionBatch.search (   self,
  dna,
  linear = True 
)
B.search(dna) -> dict.

Definition at line 2016 of file Restriction.py.

02016 
02017     def search(self, dna, linear=True):
02018         """B.search(dna) -> dict."""
02019         #
02020         #   here we replace the search method of the individual enzymes
02021         #   with one unique testing method.
02022         #
02023         if not hasattr(self, "already_mapped") :
02024             #TODO - Why does this happen!
02025             #Try the "doctest" at the start of PrintFormat.py
02026             self.already_mapped = None
02027         if isinstance(dna, DNA):
02028             # For the searching, we just care about the sequence as a string,
02029             # if that is the same we can use the cached search results.
02030             # At the time of writing, Seq == method isn't implemented,
02031             # and therefore does object identity which is stricter.
02032             if (str(dna), linear) == self.already_mapped:
02033                 return self.mapping
02034             else:
02035                 self.already_mapped = str(dna), linear
02036                 fseq = FormattedSeq(dna, linear)
02037                 self.mapping = dict([(x, x.search(fseq)) for x in self])
02038                 return self.mapping
02039         elif isinstance(dna, FormattedSeq):
02040             if (str(dna), dna.linear) == self.already_mapped:
02041                 return self.mapping
02042             else:
02043                 self.already_mapped = str(dna), dna.linear
02044                 self.mapping = dict([(x, x.search(dna)) for x in self])
02045                 return self.mapping
02046         raise TypeError("Expected Seq or MutableSeq instance, got %s instead"\
02047                         %type(dna))

Here is the caller graph for this function:

Definition at line 2010 of file Restriction.py.

02010 
02011     def show_codes(self):
02012         "B.show_codes() -> letter codes for the suppliers"""
02013         supply = [' = '.join(i) for i in self.suppl_codes().iteritems()]
02014         print '\n'.join(supply)
02015         return

def Bio.Restriction.Restriction.RestrictionBatch.split (   self,
  classes,
  bool 
)
B.split(class, [class.__name__ = True]) -> new RestrictionBatch.

it works but it is slow, so it has really an interest when splitting
over multiple conditions.

Definition at line 1964 of file Restriction.py.

01964 
01965     def split(self, *classes, **bool):
01966         """B.split(class, [class.__name__ = True]) -> new RestrictionBatch.
01967 
01968         it works but it is slow, so it has really an interest when splitting
01969         over multiple conditions."""
01970         def splittest(element):
01971             for klass in classes:
01972                 b = bool.get(klass.__name__, True)
01973                 if issubclass(element, klass):
01974                     if b:
01975                         continue
01976                     else:
01977                         return False
01978                 elif b:
01979                     return False
01980                 else:
01981                     continue
01982             return True
01983         d = [k for k in itertools.ifilter(splittest, self)]
01984         new = RestrictionBatch()
01985         new._data = dict(zip(d, [True]*len(d)))
01986         return new
      
B.suppl_codes() -> dict

letter code for the suppliers

Definition at line 2002 of file Restriction.py.

02002 
02003     def suppl_codes(self):
02004         """B.suppl_codes() -> dict
02005 
02006         letter code for the suppliers"""
02007         supply = dict([(k,v[0]) for k,v in suppliers_dict.iteritems()]) 
02008         return supply


Member Data Documentation

Definition at line 1830 of file Restriction.py.

Definition at line 1829 of file Restriction.py.


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