/usr/bin/canberra is in python-mlpy 2.2.0~dfsg1-3build2.
This file is owned by root:root, with mode 0o755.
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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | #!/usr/bin/python
## Canberra tool
## This code is written by Davide Albanese, <albanese@fbk.eu>.
## (C) 2008 Fondazione Bruno Kessler - Via Santa Croce 77, 38100 Trento, ITALY.
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
## You should have received a copy of the GNU General Public License
## along with this program. If not, see <http://www.gnu.org/licenses/>.
from numpy import *
from optparse import OptionParser
import csv
from mlpy import *
# Command line parsing
parser = OptionParser()
parser.add_option("-f", action = "store", type = "string",
dest = "flname", help = "feature-lists file - required")
parser.add_option("-s", action = "store", type = "string",
dest = "psname", help = "positions-steps file - required")
parser.add_option("-o", action = "store", type = "string",
dest = "oname", help = "output file", default = "canberra.txt")
(options, args) = parser.parse_args()
if not options.flname:
parser.error("option -f (feature-lists file) is required")
if not options.psname:
parser.error("option -s (positions-steps file) is required")
# Import feature-lists file
try:
fl_str = array([[x for x in line.split(None)] for line in open(options.flname)])
except ValueError:
raise ValueError("'%s' is not a valid feature-lists file" % options.flname)
# Import position-steps file
ps_str = open(options.psname).read()
try:
ps = [int(x) for x in ps_str.split(None)]
except ValueError:
raise ValueError("'%s' is not a valid position-steps file" % options.psname)
# Check position steps
ps = unique(ps) # Sort and unique
ps = ps[(ps > 0) & (ps <= fl_str.shape[1])]
# Link feature-name to a feature-id (from first list)
fid = {}
for id, n in enumerate(fl_str[0]):
fid[n] = id
# Build numeric feature-lists
fl_num = empty((fl_str.shape[0], fl_str.shape[1]), dtype = int)
for i in range(fl_str.shape[0]):
for j in range(fl_str.shape[1]):
fl_num[i, j] = fid[fl_str[i, j]]
# From feature-lists to position-lists
pl_num = fl_num.argsort()
# Write to file
ofile = open(options.oname, "w")
ofile_writer = csv.writer(ofile, delimiter='\t', lineterminator='\n')
for p in ps:
distance, idx1, idx2, dd = canberra(pl_num, p, dist=True)
ofile_writer.writerow([p, distance])
tmpfile = open("dist_%s.txt" % p, "w")
tmpfile_writer = csv.writer(tmpfile, delimiter='\t', lineterminator='\n')
for r in zip(idx1, idx2, dd):
ofile_writer.writerow(r)
tmpfile.close()
ofile.close()
|