From 5593b9353cbe6e837df0e18b5690c877a4eb5e69 Mon Sep 17 00:00:00 2001 From: Peter Vlasveld Date: Sat, 12 Jan 2019 10:39:41 -0500 Subject: [PATCH] added LEXF solution --- LEXF.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 LEXF.py diff --git a/LEXF.py b/LEXF.py new file mode 100644 index 0000000..80fb9da --- /dev/null +++ b/LEXF.py @@ -0,0 +1,48 @@ +#!/usr/bin/python + +#LEXF Rosalind.info Solution - Enumerating k-mers Lexicographically +#Author: Peter Vlasveld +#Date: 12/01/2019 + +#get dataset from file +f1 = open("rosalind_lexf.txt") +content = f1.readlines() +f1.close() + +#duplicate the lex set r times +firstLex = content[0].split( ) +lex = [] +for i in xrange(0, int(content[1])): + lex.extend(firstLex) + +#recursive function to get all possible combinations within the lex set +def wordCombo (arr, data, start, end, index, r): + if index == r: + tempStr = "" + for i in data: + tempStr += i + global comboList + comboList.append(tempStr) + return + i = start + while i <= end and end - i + 1 >= r - index: + data[index] = arr[i] + wordCombo(arr, data, i + 1, end, index + 1, r) + i += 1 + +#empty lsit to be passed into function +data = [0]*int(content[1]) + +#global list to be filled with combinations +comboList = [] + +#run the function, remove duplicates, and sort it alhphabetically +wordCombo(lex,data,0,len(lex)-1,0,int(content[1])) +finalList = list(set(comboList)) +sortedList = sorted(finalList) + +#print the list to a file +f2 = open("output.txt", "w") +for i in sortedList: + f2.writelines(i + "\n") +f2.close()