code refactoring to rename oligo to word

This commit is contained in:
2008-02-19 16:53:40 +00:00
parent 0909345694
commit 646f3d5f72
3 changed files with 34 additions and 5 deletions

View File

@ -3,7 +3,36 @@ from itertools import imap
_dna='acgt' _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 Iterate thought the list of all DNA word of
size `size`. size `size`.
@ -18,7 +47,7 @@ def wordIterator(size,_prefix=''):
''' '''
if size: if size:
for l in _dna: for l in _dna:
for w in wordIterator(size-1,_prefix+l): for w in allWordIterator(size-1,_prefix+l):
yield w yield w
else: else:
yield _prefix yield _prefix

View File

@ -2,8 +2,8 @@ from logging import debug,root,DEBUG
from obitools.oligo import wordSelector,wordIterator from obitools.word import wordSelector,wordIterator
from obitools.oligo import predicat from obitools.word import predicat

View File

@ -1,5 +1,5 @@
import re import re
from obitools.oligo import wordDist from obitools.word import wordDist
def rePredicatGenerator(regex): def rePredicatGenerator(regex):
regex = re.compile(regex,re.I) regex = re.compile(regex,re.I)