Add FrequentWords and FrequencyMap functions

This commit is contained in:
coolneng 2019-10-21 03:47:52 +02:00
parent 51b9d935f4
commit 4fa3efbb2b
2 changed files with 22 additions and 1 deletions

20
Code/FrequentWords.py Normal file
View File

@ -0,0 +1,20 @@
def FrequentWords(Text, k):
words = []
freq = FrequencyMap(Text, k)
m = max(freq.values())
for key in freq:
if freq[key] == m:
words.append(key)
return words
def FrequencyMap(Text, k):
freq = {}
n = len(Text)
for i in range(n - k + 1):
Pattern = Text[i:i + k]
freq[Pattern] = 0
for i in range(n - k + 1):
Pattern = Text[i:i + k]
freq[Pattern] += 1
return freq

View File

@ -22,3 +22,4 @@
*** Vocabulary *** Vocabulary
- k-mer: subsquences of length /k/ in a biological sequence - k-mer: subsquences of length /k/ in a biological sequence
- Frequency map: sequence --> frequency of the sequence