-
Notifications
You must be signed in to change notification settings - Fork 120
Expand file tree
/
Copy path023_LEXF.py
More file actions
27 lines (22 loc) · 768 Bytes
/
023_LEXF.py
File metadata and controls
27 lines (22 loc) · 768 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/env python
'''
A solution to a ROSALIND bioinformatics problem.
Problem Title: Enumerating k-mers Lexicographically
Rosalind ID: LEXF
Rosalind #: 023
URL: http://rosalind.info/problems/lexf/
'''
from itertools import product
# Read and parse the input data.
with open('data/rosalind_lexf.txt') as input_data:
letters, n = input_data.readlines()
letters = ''.join(letters.split())
n = int(n)
# The itertools.product function does exactly what we want.
# No use reinventing the wheel...
k_mers = [''.join(item) for item in product(letters, repeat=n)]
# Write the answer to the output file in the proper format.
with open('output/023_LEXF.txt', 'w') as output_file:
output_file.write(k_mers[0])
for item in k_mers[1:]:
output_file.write('\n'+item)