/usr/share/pyshared/qiime/nmds.py is in qiime 1.8.0+dfsg-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | #!/usr/bin/env python
from __future__ import division
import numpy
import os.path
import cogent.cluster.nmds as nmds_module
from qiime.format import format_nmds_coords
from qiime.parse import parse_distmat
__author__ = "Justin Kuzynski"
__copyright__ = "Copyright 2011, The QIIME Project"
__credits__ = ["Justin Kuczynski"]
__license__ = "GPL"
__version__ = "1.8.0"
__maintainer__ = "Justin Kuczynski"
__email__ = "justinak@gmail.com"
def nmds(file,dimensions=2):
samples, distmtx = parse_distmat(file)
nmds_res = nmds_module.NMDS(distmtx,verbosity=0,dimension=dimensions)
pts = nmds_res.getPoints()
stress = nmds_res.getStress()
return format_nmds_coords(samples, pts, stress)
def multiple_file_nmds(input_dir, output_dir,dimensions=2):
"""perform PCoAs on all distance matrices in the input_dir
"""
if not os.path.exists(output_dir):
os.makedirs(output_dir)
file_names = os.listdir(input_dir)
file_names = [fname for fname in file_names if not fname.startswith('.')]
for fname in file_names:
base_fname, ext = os.path.splitext(fname)
infile = os.path.join(input_dir, fname)
lines = open(infile, 'U')
nmds_res_string = nmds(lines,dimensions)
outfile = os.path.join(output_dir, 'nmds_'+base_fname+'.txt')
outfile = open(outfile, 'w')
outfile.write(nmds_res_string)
outfile.close()
|