Skip to content

Instantly share code, notes, and snippets.

@ElDeveloper
Last active August 29, 2015 14:22
Show Gist options
  • Save ElDeveloper/dabccfb9024378262549 to your computer and use it in GitHub Desktop.
Save ElDeveloper/dabccfb9024378262549 to your computer and use it in GitHub Desktop.
Convert nmds.py output to an emperor friendly format
#!/usr/bin/env python
from sys import argv
# USE AT YOUR OWN RISK
# first argument is file to convert, second argument is file to
# write the converted output to
with open(argv[1]) as f, open(argv[2], 'w') as g:
for line in f:
if line.startswith('samples'):
g.write(line.replace('samples', 'pc vector number'))
# inflate the values so emperor won't complain about them being
# too small
elif line.startswith('stress'):
x = line.split('\t')
g.write('eigvals\t%s\n' % '\t'.join(['1']*(len(x)-1)))
elif line.startswith('% variation explained'):
x = line.split('\t')
g.write('%% variation explained\t%s\n' % '\t'.join(['1']*(len(x)-1)))
else:
g.write(line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment