#! /usr/bin/env python 
###################################
#    Davi Ortega 3/12/2012 
###################################
import sys
import fuzzy_davi
import sys
import time
import os
if '-h' in sys.argv:
	print 'Reads RMSD matrix and return points in 2D'
	sys.exit()

start = time.time()
m0 = fuzzy_davi.memory()

names, Dmatrix = fuzzy_davi.readDmGEN(sys.argv[1],';')
print "File loaded in: " + str(time.time() - start)
print "Memory load: " + str(fuzzy_davi.memory(m0))


names.sort()
print len(Dmatrix)
print names

X, X_2D = fuzzy_davi.coord(names, Dmatrix, sys.argv[1])

output = ''
out = ''

old_prefix = ''
tabs = 0
for name in names:
	line = X_2D[name]
        output = output + name + '{'
	out += name
	if name[:6] != old_prefix:
		tabs += 1
		old_prefix = name[:6]
	out += '\t'*tabs*len(line)
        for val in line:
		
                output = output + str(val) + ' , '
		out += str(val).replace('(','').replace('+0j)','') + '\t'
        output = output + '}\n'
	out += '\n'

fileout = open(sys.argv[1][:-3] + 'coord.dat', 'w')
fileout.write(out)
fileout.close()

