#!/usr/bin/env python

"""
  Diplomová práce na FIT VUT Brno, 2015
  SHLUKOVÁNÍ BIOLOGICKÝCH SEKVENCÍ
  @author Bc. Radim KUBIŠ, xkubis03 
"""

import os
import sys

if len(sys.argv) > 2:
    inFile = open(sys.argv[1], 'r')
    outFile = open(sys.argv[2], 'w')
elif len(sys.argv) > 1:
    print "ERROR: output file is not set"
    exit(1)
else:
    print "ERROR: input and output file is not set"
    exit(1)

lines = [l.strip() for l in inFile.readlines()]
cls = []

for line in lines:
    if line[0] == ">":
        cls.append([])
    else:
        cls[-1].append(line.split(">")[1][:7])

for lst in cls:
    outFile.write(":".join(sorted(lst)))
    outFile.write("\n")

inFile.close()
outFile.close()

