A few solutions, all processing the supersequence and the subsequence in parallel, taking linear time and constant memory.
Using your easy example:
full = iter(range(1, 16))
skip = iter([3,5,6,8,10,11])
Solution 0: (the one I came up with last, but should've done first)
s = next(skip, None)
for x in full:
if x == s:
s = next(skip, None)
else:
print(x)
Solution 1:
from heapq import merge
from itertools import groupby
for x, g in groupby(merge(full, skip)):
if len(list(g)) == 1:
print(x)
Solution 2:
for s in skip:
for x in iter(full.__next__, s):
print(x)
for x in full:
print(x)
Solution 3:
from functools import partial
until = partial(iter, full.__next__)
for s in skip:
for x in until(s):
print(x)
for x in full:
print(x)
Solution 4:
from itertools import takewhile
for s in skip:
for x in takewhile(s.__ne__, full):
print(x)
for x in full:
print(x)
Output of all solutions:
1
2
4
7
9
12
13
14
15
Solution 0 for your actual problem:
import csv
import itertools
with open('in.txt') as tsvfile:
tsvreader = csv.reader(tsvfile, delimiter=' ')
skip = next(tsvreader, [None])[0]
for i in itertools.product('ACTG', repeat=18):
oneKmer = ''.join(i)
if oneKmer == skip:
skip = next(tsvreader, [None])[0]
else:
print(oneKmer)
Slight variation:
import csv
from itertools import product
from operator import itemgetter
with open('in.txt') as tsvfile:
tsvreader = csv.reader(tsvfile, delimiter=' ')
skips = map(itemgetter(0), tsvreader)
skip = next(skips, None)
for oneKmer in map(''.join, product('ACTG', repeat=18)):
if oneKmer == skip:
skip = next(skips, None)
else:
print(oneKmer)