#!/usr/bin/env python

import os
import seqlib
import sys

_, file_to_split, targetdir = sys.argv

with open(file_to_split) as f:
    sequences = list(seqlib.read_sequences(f))

_, file_to_split = os.path.split(file_to_split)
file_to_split = os.path.join(targetdir, file_to_split)
name, extension = os.path.splitext(file_to_split)

for i in range(1, len(sequences) + 1):
    with open('%s%d%s' % (name, i, extension), 'w') as f:
        for j in range(i):
            seqlib.write_sequence(sequences[j], f)
