#!/usr/bin/env python
import sys
from bitk import *

if '-h' in sys.argv:
	print'\n\tSort the vissa html file according a file with sequences in clustal format\n \
	\n\tsorbyaln_vissa vissafile.html(doc) alignment.aln [options]\n\n\n \
	\tOptions:\n \
	\t -h : Help\n \
	\t -name : NAME_SEQ/XXXXXXX = NAME_SEQ\n\n\n\n \
	\t WARNING: Probably with bug... working version!\n\n'
	sys.exit()

seq = sys.argv[1]
aln = sys.argv[2]

seq_dic = vissareader(seq)
aln_list = alnreader(aln, list = 'Yes')
if '-name' in sys.argv:
	aln_list = alnreader(aln,'Yes','Yes')

#print aln_list
#print str(len(aln_list))

output = '<html>\n<body>\n<pre>\n'
for name in aln_list:
	if name in seq_dic.keys():
		space = ' '*(42-len(name))
		output = output + name + space + seq_dic[name] 

output = output + '</pre>\n</body>\n</html>'

outfile = open( seq[:-3] + 'sorted.doc', 'w')
outfile.write(output)
outfile.close()

