10
10
__copyright__ = "Copyright 2007-2009, The Cogent Project"
11
11
__credits__ = ["Peter Maxwell", "Gavin Huttley", "Rob Knight"]
12
12
__license__ = "GPL"
14
14
__maintainer__ = "Gavin Huttley"
15
15
__email__ = "gavin.huttley@anu.edu.au"
16
16
__status__ = "Production"
153
153
def test_slidingWindows(self):
154
154
"""test slicing of sequences"""
155
155
alignment = LoadSeqs(data = {'seq1': 'ACGTACGT', 'seq2': 'ACGTACGT', 'seq3': 'ACGTACGT'})
157
157
for bit in alignment.slidingWindows(5,2):
159
159
self.assertEqual(result[0].todict(), {'seq3': 'ACGTA', 'seq2': 'ACGTA', 'seq1': 'ACGTA'})
160
160
self.assertEqual(result[1].todict(), {'seq3': 'GTACG', 'seq2': 'GTACG', 'seq1': 'GTACG'})
162
# specify a starting window position
164
for bit in alignment.slidingWindows(5,2, start=1):
166
self.assertEqual(result[0].todict(), {'seq3': 'CGTAC', 'seq2': 'CGTAC', 'seq1': 'CGTAC'})
167
self.assertEqual(result[1].todict(), {'seq3': 'TACGT', 'seq2': 'TACGT', 'seq1': 'TACGT'})
169
# specify a ending window position
171
for bit in alignment.slidingWindows(5, 1, start=1, end=3):
173
self.assertEqual(result[0].todict(), {'seq3': 'CGTAC', 'seq2': 'CGTAC', 'seq1': 'CGTAC'})
174
self.assertEqual(result[1].todict(), {'seq3': 'GTACG', 'seq2': 'GTACG', 'seq1': 'GTACG'})
176
# start conditions < window-size from end don't return a window
177
# specify a ending window position
179
for bit in alignment.slidingWindows(5, 1, start=5):
181
self.assertEqual(result, [])
163
184
for bit in alignment.slidingWindows(5,1):
165
186
self.assertEqual(result[0].todict(), {'seq3': 'ACGTA', 'seq2': 'ACGTA', 'seq1': 'ACGTA'})
446
467
'GTAGC', 'TAGCA', 'AGCAT', 'GCATA', 'CATAG',
447
468
'ATAGC', 'TAGCT', 'AGCTC', 'GCTCG', 'CTCGA'])
471
for bit in self.seq.slidingWindows(5, 1, start=3, end=6):
473
self.assertEqual([str(x) for x in result],
474
['ACGTT', 'CGTTG', 'GTTGC'])
476
# should not get a window when starting conditions don't generate one
478
for bit in self.seq.slidingWindows(20, 1, start=6):
480
self.assertEqual(result, [])
449
482
def test_reversecomplement(self):
450
483
"""testing reversal and complementing of a sequence"""
451
484
seq = Sequence(DNA, seq='ACTGTAA')