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

Source Code for Package Bio.CAPS

  1  # Copyright 2005 by Jonathan Taylor. 
  2  # All rights reserved. 
  3  # This code is part of the Biopython distribution and governed by its 
  4  # license.  Please see the LICENSE file that should have been included 
  5  # as part of this package. 
  6  """This module deals with CAPS markers. 
  7   
  8  A CAPS marker is a location a DifferentialCutsite as described below and a 
  9  set of primers that can be used to visualize this.  More information can 
 10  be found in the paper `Konieczny and Ausubel (1993)`_ (PMID 8106085). 
 11   
 12  .. _`Konieczny and Ausubel (1993)`: http://dx.doi.org/10.1046/j.1365-313X.1993.04020403.x 
 13  """ 
 14   
 15  __docformat__ = "restructuredtext en" 
 16   
17 -class DifferentialCutsite(object):
18 """Differential enzyme cutsite in an alignment. 19 20 A differential cutsite is a location in an alignment where an enzyme cuts 21 at least one sequence and also cannot cut at least one other sequence. 22 23 Members: 24 - start - Where it lives in the alignment. 25 - enzyme - The enzyme that causes this. 26 - cuts_in - A list of sequences (as indexes into the alignment) the 27 enzyme cuts in. 28 - blocked_in - A list of sequences (as indexes into the alignment) the 29 enzyme is blocked in. 30 31 """ 32
33 - def __init__(self, **kwds):
34 """Initialize a DifferentialCutsite. 35 36 Each member (as listed in the class description) should be included as a 37 keyword. 38 """ 39 40 self.start = int(kwds["start"]) 41 self.enzyme = kwds["enzyme"] 42 self.cuts_in = kwds["cuts_in"] 43 self.blocked_in = kwds["blocked_in"]
44 45
46 -class AlignmentHasDifferentLengthsError(Exception):
47 pass
48 49
50 -class CAPSMap(object):
51 """A map of an alignment showing all possible dcuts. 52 53 Members: 54 - alignment - The alignment that is mapped. 55 - dcuts - A list of possible CAPS markers in the form of 56 DifferentialCutsites. 57 """ 58
59 - def __init__(self, alignment, enzymes = []):
60 """Initialize the CAPSMap. 61 62 Required: 63 - alignment - The alignment to be mapped. 64 65 Optional: 66 - enzymes - The enzymes to be used to create the map. 67 """ 68 69 self.sequences = [rec.seq for rec in alignment] 70 self.size = len(self.sequences) 71 self.length = len(self.sequences[0]) 72 for seq in self.sequences: 73 if len(seq) != self.length: 74 raise AlignmentHasDifferentLengthsError 75 76 self.alignment = alignment 77 self.enzymes = enzymes 78 79 # look for dcuts 80 self._digest()
81
82 - def _digest_with(self, enzyme):
83 cuts = [] # list of lists, one per sequence 84 all = [] 85 86 # go through each sequence 87 for seq in self.sequences: 88 # grab all the cuts in the sequence 89 seq_cuts = [cut - enzyme.fst5 for cut in enzyme.search(seq)] 90 # maintain a list of all cuts in all sequences 91 all.extend(seq_cuts) 92 cuts.append(seq_cuts) 93 94 # we sort the all list and remove duplicates 95 all.sort() 96 97 last = -999 98 new = [] 99 for cut in all: 100 if cut != last: 101 new.append(cut) 102 last = cut 103 all = new 104 # all now has indices for all sequences in the alignment 105 106 for cut in all: 107 # test for dcuts 108 109 cuts_in = [] 110 blocked_in = [] 111 112 for i in range(0, self.size): 113 seq = self.sequences[i] 114 if cut in cuts[i]: 115 cuts_in.append(i) 116 else: 117 blocked_in.append(i) 118 119 if cuts_in != [] and blocked_in != []: 120 self.dcuts.append(DifferentialCutsite(start = cut, enzyme = enzyme, cuts_in = cuts_in, blocked_in = blocked_in))
121
122 - def _digest(self):
123 self.dcuts = [] 124 125 for enzyme in self.enzymes: 126 self._digest_with(enzyme)
127