/usr/bin/canberraq is in python-mlpy 2.2.0~dfsg1-2.1.
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 92 93 94 | #!/usr/bin/python2.7
## Canberraq 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("-a", action = "store", type = "string",
dest = "aname", help = "alphabet file - required")
parser.add_option("-o", action = "store", type = "string",
dest = "oname", help = "output file", default = "canberra.txt")
parser.add_option("-n", "--normalize", action = "store_true", default = False,
dest = "norm", help = "normalized distance in complete mode")
(options, args) = parser.parse_args()
if not options.flname:
parser.error("option -f (feature-lists file) is required")
if not options.aname:
parser.error("option -a (alphabet file) is required")
# Import feature-lists file
try:
fl_str = [[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 alphabet file
atmp = open(options.aname).read()
try:
a_str = [x for x in atmp.split(None)]
except ValueError:
ValueError("'%s' is not a valid alphabet file" % options.aname)
# Link feature-name to a feature-id (from first list)
fid = {}
for id, n in enumerate(a_str):
fid[n] = id
# Build numeric position-lists
pl_num = -ones((len(fl_str), len(a_str)), dtype = int)
for i, r in enumerate(fl_str):
for j, c in enumerate(r):
pl_num[i, fid[c]] = j
# Write to file
ofile = open(options.oname, "w")
ofile_writer = csv.writer(ofile, delimiter='\t', lineterminator='\n')
distance_comp, idx1_comp, idx2_comp, dd_comp = canberraq(pl_num, True, options.norm, dist=True)
distance_core, idx1_core, idx2_core, dd_core = canberraq(pl_num, False)
ofile_writer.writerow(["Complete", distance_comp])
ofile_writer.writerow(["Core", distance_core])
ofile.close()
tmpfile = open("dist_complete.txt", "w")
tmpfile_writer = csv.writer(tmpfile, delimiter='\t', lineterminator='\n')
for r in zip(idx1_comp, idx2_comp, dd_comp):
tmpfile_writer.writerow(r)
tmpfile.close()
tmpfile = open("dist_core.txt", "w")
tmpfile_writer = csv.writer(tmpfile, delimiter='\t', lineterminator='\n')
for r in zip(idx1_core, idx2_core, dd_core):
tmpfile_writer.writerow(r)
tmpfile.close()
|