Created
August 1, 2014 01:05
-
-
Save olgabot/38f11e73679c39349639 to your computer and use it in GitHub Desktop.
split up track hubs into chunks so UCSC doesn't get mad
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def single_track(track): | |
within_track = False | |
lines = [] | |
with open(track) as f: | |
for line in f: | |
# print line, | |
if line.startswith('track') and within_track: | |
within_track = False | |
yield lines | |
lines = [line] | |
else: | |
lines.append(line) | |
within_track = True | |
MAX_FILE_SIZE = 262144 | |
all_written = False | |
n = 0 | |
single_tracks = single_track('trackDb.txt') | |
while not all_written: | |
filename = 'trackDb_{}.txt'.format(n) | |
with open(filename, 'w') as f: | |
while os.stat(filename).st_size < MAX_FILE_SIZE: | |
try: | |
f.writelines(single_tracks.next()) | |
except StopIteration: | |
all_written = True | |
break | |
n += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment