Skip to content

Instantly share code, notes, and snippets.

@anthonykasza
Created December 7, 2015 06:38
Show Gist options
  • Save anthonykasza/fcbdb8fafd1ebd8418de to your computer and use it in GitHub Desktop.
Save anthonykasza/fcbdb8fafd1ebd8418de to your computer and use it in GitHub Desktop.
import random
from StringIO import StringIO
import string
import zlib
import base64 as b64
def get_kmer(read_str, overlap_size, kmer_size):
if read_str.pos > overlap_size:
read_str.seek(overlap_size * -1, 1)
front_overlap = read_str.read(overlap_size)
else:
front_overlap = ''
read = read_str.read(kmer_size)
try:
rear_overlap = read_str.read(overlap_size)
read_str.seek(overlap_size * -1, 1)
except:
rear_overlap = ''
return front_overlap, read, rear_overlap
read_str = StringIO('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789')
read_str = StringIO(''.join(random.choice(string.ascii_lowercase + string.ascii_uppercase + string.digits) for _ in range(9*10240)))
read_str = StringIO(b64.b64encode(zlib.compress(open("./test", 'r').read())))
kmers = []
flag = 'some_placeholder_string'
while flag:
kmer_size = random.choice(range(100, 200))
overlap_size = random.choice(range(10, 15))
front_overlap, kmer, rear_overlap = get_kmer(read_str, overlap_size, kmer_size)
kmers.append("%s%s%s" % (front_overlap, kmer, rear_overlap))
flag = rear_overlap
random.shuffle(kmers)
for kmer in kmers:
print kmer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment