From 646f3d5f72ffb1782c396490c3e7f4bb37747e7a Mon Sep 17 00:00:00 2001 From: Eric Coissac Date: Tue, 19 Feb 2008 16:53:40 +0000 Subject: [PATCH] code refactoring to rename oligo to word --- src/obitools/word/__init__.py | 33 +++++++++++++++++++++++++++++++-- src/obitools/word/options.py | 4 ++-- src/obitools/word/predicat.py | 2 +- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/obitools/word/__init__.py b/src/obitools/word/__init__.py index e9b2723..ed8b83a 100644 --- a/src/obitools/word/__init__.py +++ b/src/obitools/word/__init__.py @@ -3,7 +3,36 @@ from itertools import imap _dna='acgt' -def wordIterator(size,_prefix=''): +def wordCount(liste): + count = {} + + for e in liste: + count[e]=count.get(e,0) + 1 + + return count + + +def wordIterator(sequence,lword,step=1,endIncluded=False,circular=False): + assert not (endIncluded and circular), \ + "endIncluded and circular cannot not be set to True at the same time" + + L = len(sequence) + sequence = str(sequence) + if circular: + sequence += sequence[0:lword] + pmax=L + elif endIncluded: + pmax=L + else: + pmax = L - lword + 1 + + pos = xrange(0,pmax,step) + + for x in pos: + yield sequence[x:x+lword] + + +def allWordIterator(size,_prefix=''): ''' Iterate thought the list of all DNA word of size `size`. @@ -18,7 +47,7 @@ def wordIterator(size,_prefix=''): ''' if size: for l in _dna: - for w in wordIterator(size-1,_prefix+l): + for w in allWordIterator(size-1,_prefix+l): yield w else: yield _prefix diff --git a/src/obitools/word/options.py b/src/obitools/word/options.py index cbb790f..1133cbc 100644 --- a/src/obitools/word/options.py +++ b/src/obitools/word/options.py @@ -2,8 +2,8 @@ from logging import debug,root,DEBUG -from obitools.oligo import wordSelector,wordIterator -from obitools.oligo import predicat +from obitools.word import wordSelector,wordIterator +from obitools.word import predicat diff --git a/src/obitools/word/predicat.py b/src/obitools/word/predicat.py index beb6620..a744f2c 100644 --- a/src/obitools/word/predicat.py +++ b/src/obitools/word/predicat.py @@ -1,5 +1,5 @@ import re -from obitools.oligo import wordDist +from obitools.word import wordDist def rePredicatGenerator(regex): regex = re.compile(regex,re.I)