I'm searching for all the unique possible permutations of nucleotide given a defined length. By unique, I mean the reverse complement would not be counted.
For example, permutations of length 1 would be:
But the last two wouldn't be included because they would already be seen.
Length 2 would be:
So, 8, 11, 12, 14, 15, 16 wouldn't be included for the same reason, and so on.
def data_count(n, trantab): nn = int(n) count = 0 seen = set() with open('file.txt','w') as f: for number in range(1, nn+1): for p in itertools.product('ACGT', repeat=number): print(''.join(p)+':'+''.join(p)[::-1].translate(trantab)) if ''.join(p) in seen: pass else: seen.add(''.join(p)[::-1].translate(trantab)) count += 1 #print(x) f.write(str(number)+' = '+str(count)+'\n') count = 0
It does the job pretty well until 10 or 12, but beyond that it takes a lot of time to output results.
n is the length of the search and trantab is:
intab = 'ACGT' outtab = 'TGCA' trantab = str.maketrans(intab, outtab)
to get the reverse complement of the nucleotide.
Is there any way to improve this one?