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

Source Code for Package Bio.CAPS

  1  """This module deals with CAPS markers. 
  2   
  3  A CAPS marker is a location a DifferentialCutsite as described below and a 
  4  set of primers that can be used to visualize this.  More information can 
  5  be found in the paper located at: 
  6   
  7  http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?cmd=Retrieve&db=PubMed&list_uids=8106085&dopt=Abstract 
  8   
  9  Copyright Jonathan Taylor 2005 
 10  """ 
 11   
12 -class DifferentialCutsite:
13 """A differential cutsite is a location in an alignment where an enzyme cuts 14 at least one sequence and also cannot cut at least one other sequence. 15 16 Members: 17 start Where it lives in the alignment. 18 enzyme The enzyme that causes this. 19 cuts_in A list of sequences (as indexes into the alignment) the 20 enzyme cuts in. 21 blocked_in A list of sequences (as indexes into the alignment) the 22 enzyme is blocked in. 23 24 """ 25
26 - def __init__(self, **kwds):
27 """Initialize a DifferentialCutsite. 28 29 Each member (as listed in the class description) should be included as a 30 keyword. 31 """ 32 33 self.start = int(kwds["start"]) 34 self.enzyme = kwds["enzyme"] 35 self.cuts_in = kwds["cuts_in"] 36 self.blocked_in = kwds["blocked_in"]
37
38 -class AlignmentHasDifferentLengthsError(Exception):
39 pass
40
41 -class CAPSMap:
42 """A map of an alignment showing all possible dcuts. 43 44 Members: 45 alignment The alignment that is mapped. 46 dcuts A list of possible CAPS markers in the form of 47 DifferentialCutsites. 48 """ 49
50 - def __init__(self, alignment, enzymes = []):
51 """Initialize the CAPSMap 52 53 Required: 54 alignment The alignment to be mapped. 55 56 Optional: 57 enzymes The enzymes to be used to create the map. 58 """ 59 60 self.sequences = [rec.seq for rec in alignment.get_all_seqs()] 61 self.size = len(self.sequences) 62 self.length = len(self.sequences[0]) 63 for seq in self.sequences: 64 if len(seq) != self.length: 65 raise AlignmentHasDifferentLengthsError 66 67 self.alignment = alignment 68 self.enzymes = enzymes 69 70 # look for dcuts 71 self._digest()
72
73 - def _digest_with(self, enzyme):
74 cuts = {} 75 all = [] 76 77 # go through each sequence 78 for seq in self.sequences: 79 80 # grab all the cuts in the sequence 81 cuts[seq] = [cut - enzyme.fst5 for cut in enzyme.search(seq)] 82 83 # maintain a list of all cuts in all sequences 84 all.extend(cuts[seq]) 85 86 # we sort the all list and remove duplicates 87 all.sort() 88 89 last = -999 90 new = [] 91 for cut in all: 92 if cut != last: 93 new.append(cut) 94 last = cut 95 96 all = new 97 # all now has indices for all sequences in the alignment 98 99 for cut in all: 100 # test for dcuts 101 102 cuts_in = [] 103 blocked_in = [] 104 105 for i in range(0, self.size): 106 seq = self.sequences[i] 107 if cut in cuts[seq]: 108 cuts_in.append(i) 109 else: 110 blocked_in.append(i) 111 112 if cuts_in != [] and blocked_in != []: 113 self.dcuts.append(DifferentialCutsite(start = cut, enzyme = enzyme, cuts_in = cuts_in, blocked_in = blocked_in))
114
115 - def _digest(self):
116 self.dcuts = [] 117 118 for enzyme in self.enzymes: 119 self._digest_with(enzyme)
120