27
27
from operator import eq, ne
28
28
from random import shuffle
31
LOG = logging.getLogger('cogent.data')
33
32
__author__ = "Rob Knight, Gavin Huttley, and Peter Maxwell"
34
33
__copyright__ = "Copyright 2007-2009, The Cogent Project"
35
34
__credits__ = ["Rob Knight", "Peter Maxwell", "Gavin Huttley",
36
35
"Matthew Wakefield", "Daniel McDonald"]
37
36
__license__ = "GPL"
39
38
__maintainer__ = "Rob Knight"
40
39
__email__ = "rob@spot.colorado.edu"
41
40
__status__ = "Production"
685
684
def gettype(self):
686
685
"""Return the sequence type."""
688
return self.MolType._type
687
return self.MolType.label
690
689
def resolveambiguities(self):
691
690
"""Returns a list of tuples of strings."""
692
691
ambigs = self.MolType.resolveAmbiguity
693
692
return [ambigs(motif) for motif in self._seq]
695
def slidingWindows(self, window, step):
694
def slidingWindows(self, window, step, start=None, end=None):
696
695
"""Generator function that yield new sequence objects
697
696
of a given length at a given interval.
699
698
- window: The length of the returned sequence
700
699
- step: The interval between the start of the returned
702
for pos in range(0, len(self)-window+1,step):
703
yield self[pos:pos+window]
701
- start: first window start position
702
- end: last window start position
704
start = [start, 0][start is None]
705
end = [end, len(self)-window+1][end is None]
706
end = min(len(self)-window+1, end)
707
if start < end and len(self)-end >= window-1:
708
for pos in xrange(start, end, step):
709
yield self[pos:pos+window]
705
711
def getInMotifSize(self, motif_length=1, log_warnings=True):
706
712
"""returns sequence as list of non-overlapping motifs
715
721
length = len(seq)
716
722
remainder = length % motif_length
717
723
if remainder and log_warnings:
718
LOG.warning('Dropped remainder "%s" from end of sequence' %
724
warnings.warn('Dropped remainder "%s" from end of sequence' %
719
725
seq[-remainder:])
720
726
return [seq[i:i+motif_length]
721
727
for i in range(0, length-remainder, motif_length)]