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