Description: Fix python3 interpreter path, update test script to run with files at needed places
Author: Nilesh Patra <nilesh@debian.org>
Last-Update: 2021-10-31
--- a/bin/doFM.py
+++ b/bin/doFM.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/python3
 
 #  trinculo, Flexible tools for multinomial association
 #    Copyright (C) 2014  Luke Jostins
@@ -54,9 +54,9 @@
 INFILE.close()
 INFILE = open(inputfile)
 
-print "\t".join(INFILE.readline().split()) + "\tP_CAUSAL"
+print("\t".join(INFILE.readline().split()) + "\tP_CAUSAL")
 
 for rawline in INFILE:
 	line = rawline.split()
-	print "\t".join(line) + "\t" + str(math.exp(float(line[i]) - PD))
+	print("\t".join(line) + "\t" + str(math.exp(float(line[i]) - PD)))
 
--- a/bin/doMS.py
+++ b/bin/doMS.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python 
+#!/usr/bin/python3
 
 import sys
 import math
@@ -149,26 +149,26 @@
             priors.append(1.0/((Npheno + 1)*nCk(Npheno,k)))
 #print priors
 if mode == 1 or mode == 2:
-    print "\t".join(header)
+    print("\t".join(header))
 if mode == 3:
-    print "\t".join(header[0:5]),
-    print "BestSpecModel\tBestSharedModel\tLogSpecificityBF"
+    print("\t".join(header[0:5]), end=' ')
+    print("BestSpecModel\tBestSharedModel\tLogSpecificityBF")
 if mode == 4:
-    print "\t".join(header[0:5]),
-    print "BestModel\tBestModelProb\tCredibleSet"
+    print("\t".join(header[0:5]), end=' ')
+    print("BestModel\tBestModelProb\tCredibleSet")
 
 for line_raw in FILE:
     line = line_raw.split()
-    print "\t".join(line[0:5]),
+    print("\t".join(line[0:5]), end=' ')
     BFs = [0.0]
     for i in range(6,len(line)):
         BFs.append(float(line[i]) - float(line[5]))
     if mode == 2 or mode == 4:
         posteriors = numpy.exp(numpy.array(BFs)*numpy.array(priors))/sum(numpy.exp(numpy.array(BFs)*numpy.array(priors)))
     if (mode == 1):
-        print "\t".join([str(x) for x in BFs])
+        print("\t".join([str(x) for x in BFs]))
     elif (mode == 2):
-        print "\t".join([str(x) for x in posteriors])
+        print("\t".join([str(x) for x in posteriors]))
     elif (mode == 3):
         bestShare = -1
         bestShareBF = -1e100
@@ -182,7 +182,7 @@
                 bestShareBF = BFs[i]
                 bestShare = i
         #print bestShare, bestShareBF, bestUnique, bestUniqueBF
-        print header[5 + bestUnique],header[5 + bestShare], bestUniqueBF - bestShareBF
+        print(header[5 + bestUnique],header[5 + bestShare], bestUniqueBF - bestShareBF)
     elif (mode == 4):
         order = numpy.argsort(-posteriors)
         CredSet = header[5 + order[0]]
@@ -192,6 +192,6 @@
             CredSet += "&" +  header[5 + order[i]]
             CredValue += posteriors[order[i]]
             i += 1
-        print header[5 + order[0]],posteriors[order[0]],CredSet
+        print(header[5 + order[0]],posteriors[order[0]],CredSet)
 #print phenos
-#print priors
\ No newline at end of file
+#print priors
--- a/bin/testing.py
+++ b/bin/testing.py
@@ -5,215 +5,222 @@
 
 devnull = open(os.devnull, 'w')
 
-binpath="./bin/"
-examplepath="./examples/"
-trinculo = binpath + "/trinculo"
+examplepath="/usr/share/doc/trinculo/examples"
+trinculo="/usr/bin/trinculo"
 
 tmpdir=tempfile.mkdtemp()
 
-print "Testing trinculo (v0.95)"
-print "Test files are written to: " + tmpdir
-print "1. Testing frequentist association (plink)...",
+print("Testing trinculo (v0.95)")
+print("Test files are written to: " + tmpdir)
+print("1. Testing frequentist association (plink)...", end=' ')
 
 test1 = subprocess.call([trinculo,"multinom","--bfile", examplepath + "/genotypes","--pheno", examplepath + "/phenos.txt","--phenoname","Pheno","--basepheno","Control","--out", tmpdir + "/1"],stdout=devnull, stderr=devnull)
 
 stoptest=False
 if test1 != 0:
-    print "FAILED (trinculo returned non-zero code " + str(test1) + ")"
+    print("FAILED (trinculo returned non-zero code " + str(test1) + ")")
     stoptest=True 
 
 if not stoptest:
     test2 = os.path.isfile(tmpdir + "/1" + ".log") and os.path.isfile(tmpdir + "/1" + ".assoc.multinom")
     if not test2:
-        print "FAILED (trinuculo failed to produce expected files)"
+        print("FAILED (trinuculo failed to produce expected files)")
         stoptest=True
 if not stoptest:
-    test3 = hashlib.md5(file(tmpdir + '/1.assoc.multinom').read()).digest()
-    if test3 != '\x1dg(d\xde\xccM\xcdHM\x11\xdd\xee\xfa\x02\xc6':
-        print "FAILED (trinculo produced file with incorrect MD5 sum: " + tmpdir + '/1.assoc.multinom)'
+    test3 = hashlib.md5(open(tmpdir + '/1.assoc.multinom').read().encode('utf-8')).hexdigest()
+    res3 = "1d672864decc4dcd484d11ddeefa02c6"
+    if test3 != res3:
+        print("FAILED (trinculo produced file with incorrect MD5 sum: " + tmpdir + '/1.assoc.multinom)')
         stoptest=True
 
 if not stoptest:
-    print "PASSED"
+    print("PASSED")
 
 
-print "2. Testing frequentist association (dosage)...",
+print("2. Testing frequentist association (dosage)...", end=' ')
 
 test1 = subprocess.call([trinculo,"multinom","--dosage", examplepath + "/genotypes.dose","--pheno", examplepath + "/phenos.txt","--phenoname","Pheno","--basepheno","Control","--out", tmpdir + "/2"],stdout=devnull, stderr=devnull)
 
 stoptest=False
 if test1 != 0:
-    print "FAILED (trinculo returned non-zero code " + str(test1) + ")"
+    print("FAILED (trinculo returned non-zero code " + str(test1) + ")")
     stoptest=True 
 
 if not stoptest:
     test2 = os.path.isfile(tmpdir + "/2" + ".log") and os.path.isfile(tmpdir + "/2" + ".assoc.multinom")
     if not test2:
-        print "FAILED (trinuculo failed to produce expected files)"
+        print("FAILED (trinuculo failed to produce expected files)")
         stoptest=True
 
-if not stoptest:
-    test3 = hashlib.md5(file(tmpdir + '/2.assoc.multinom').read()).digest()
-    if test3 != '=6\xd0\xb3\xd8\x15SW\x8f\xf9\x86\x13\x99\x90S\xba':
-        print "FAILED (trinculo produced file with incorrect MD5 sum: " + tmpdir + '/2.assoc.multinom)'
+if not stoptest: 
+    test3 = hashlib.md5(open(tmpdir + '/2.assoc.multinom').read().encode('utf-8')).hexdigest()
+    res3 = "3d36d0b3d81553578ff98613999053ba"
+    if test3 != res3:
+        print("FAILED (trinculo produced file with incorrect MD5 sum: " + tmpdir + '/2.assoc.multinom)')
         stoptest=True
 
 if not stoptest:
-    print "PASSED"
+    print("PASSED")
   
-print "3. Testing frequentist association (covariates)...",
+print("3. Testing frequentist association (covariates)...", end=' ')
 
 test1 = subprocess.call([trinculo,"multinom","--bfile", examplepath + "/genotypes","--pheno", examplepath + "/phenos.txt","--phenoname","Pheno","--basepheno","Control","--covar", examplepath + "/pcs.txt","--out", tmpdir + "/3"],stdout=devnull, stderr=devnull)
 
 stoptest=False
 if test1 != 0:
-    print "FAILED (trinculo returned non-zero code " + str(test1) + ")"
+    print("FAILED (trinculo returned non-zero code " + str(test1) + ")")
     stoptest=True
 
 if not stoptest:
     test2 = os.path.isfile(tmpdir + "/3" + ".log") and os.path.isfile(tmpdir + "/3" + ".assoc.multinom")
     if not test2:
-        print "FAILED (trinuculo failed to produce expected files)"
+        print("FAILED (trinuculo failed to produce expected files)")
         stoptest=True
 
 if not stoptest:
-    test3 = hashlib.md5(file(tmpdir + '/3.assoc.multinom').read()).digest()
-    if test3 != '\x16\x03\xb7\xaaD~M\x04\xba\xff\xc5\xef\xfd{r7':
-        print "FAILED (trinculo produced file with incorrect MD5 sum: " + tmpdir + '/3.assoc.multinom)'
+    test3 = hashlib.md5(open(tmpdir + '/3.assoc.multinom').read().encode('utf-8')).hexdigest()
+    res3 = "1603b7aa447e4d04baffc5effd7b7237"
+    if test3 != res3:
+        print("FAILED (trinculo produced file with incorrect MD5 sum: " + tmpdir + '/3.assoc.multinom)')
         stoptest=True
 
 if not stoptest:
-    print "PASSED"
+    print("PASSED")
 
 
-print "4. Testing frequentist association (conditioning)...",
+print("4. Testing frequentist association (conditioning)...", end=' ')
 
 condfile=tempfile.mkstemp()
-file(condfile[1],"w").write("SNP1")
+open(condfile[1],"w").write("SNP1")
 
 test1 = subprocess.call([trinculo,"multinom","--bfile", examplepath + "/genotypes","--pheno", examplepath + "/phenos.txt","--phenoname","Pheno","--basepheno","Control","--covar", examplepath + "/pcs.txt","--condition",condfile[1],"--out", tmpdir + "/4"],stdout=devnull, stderr=devnull)
 
 stoptest=False
 if test1 != 0:
-    print "FAILED (trinculo returned non-zero code " + str(test1) + ")"
+    print("FAILED (trinculo returned non-zero code " + str(test1) + ")")
     stoptest=True
 
 if not stoptest:
     test2 = os.path.isfile(tmpdir + "/4" + ".log") and os.path.isfile(tmpdir + "/4" + ".assoc.multinom")
     if not test2:
-        print "FAILED (trinuculo failed to produce expected files)"
+        print("FAILED (trinuculo failed to produce expected files)")
         stoptest=True
 
 if not stoptest:
-    test3 = hashlib.md5(file(tmpdir + '/4.assoc.multinom').read()).digest()
-    if test3 != ":\x03'\x9be=\x08\xbas\xea\xc7\xf2_N\xe3\x02":
-        print "FAILED (trinculo produced file with incorrect MD5 sum: " + tmpdir + '/4.assoc.multinom)'
+    test3 = hashlib.md5(open(tmpdir + '/4.assoc.multinom').read().encode('utf-8')).hexdigest()
+    res3 = "3a03279b653d08ba73eac7f25f4ee302"
+    if test3 != res3:
+        print("FAILED (trinculo produced file with incorrect MD5 sum: " + tmpdir + '/4.assoc.multinom)')
         stoptest=True
 
 if not stoptest:
-    print "PASSED"
+    print("PASSED")
 
 
-print "5. Testing Bayesian association...",
+print("5. Testing Bayesian association...", end=' ')
 
 test1 = subprocess.call([trinculo,"multinom","--bfile", examplepath + "/genotypes","--pheno", examplepath + "/phenos.txt","--phenoname","Pheno","--basepheno","Control","--covar", examplepath + "/pcs.txt","--normalize","--defaultprior","--out", tmpdir + "/5"],stdout=devnull, stderr=devnull)
 
 stoptest=False
 if test1 != 0:
-    print "FAILED (trinculo returned non-zero code " + str(test1) + ")"
+    print("FAILED (trinculo returned non-zero code " + str(test1) + ")")
     stoptest=True
 
 if not stoptest:
     test2 = os.path.isfile(tmpdir + "/5" + ".log") and os.path.isfile(tmpdir + "/5" + ".assoc.multinom")
     if not test2:
-        print "FAILED (trinuculo failed to produce expected files)"
+        print("FAILED (trinuculo failed to produce expected files)")
         stoptest=True
 
 if not stoptest:
-    test3 = hashlib.md5(file(tmpdir + '/5.assoc.multinom').read()).digest()
-    if test3 != 'A~\x85\x00Zy^OsG_\xa9\xa7\xc5\r\xe3':
-        print "FAILED (trinculo produced file with incorrect MD5 sum: " + tmpdir + '/5.assoc.multinom)'
+    test3 = hashlib.md5(open(tmpdir + '/5.assoc.multinom').read().encode('utf-8')).hexdigest()
+    res3 = "417e85005a795e4f73475fa9a7c50de3"
+    if test3 != res3:
+        print("FAILED (trinculo produced file with incorrect MD5 sum: " + tmpdir + '/5.assoc.multinom)')
         stoptest=True
 
 if not stoptest:
-    print "PASSED"
+    print("PASSED")
 
 
-print "6. Testing Bayesian association (prior file)...",
+print("6. Testing Bayesian association (prior file)...", end=' ')
 
 test1 = subprocess.call([trinculo,"multinom","--bfile", examplepath + "/genotypes","--pheno", examplepath + "/phenos.txt","--phenoname","Pheno","--basepheno","Control","--covar", examplepath + "/pcs.txt","--normalize","--priors",examplepath + "/priors.txt","--out", tmpdir + "/6"],stdout=devnull, stderr=devnull)
 
 stoptest=False
 if test1 != 0:
-    print "FAILED (trinculo returned non-zero code " + str(test1) + ")"
+    print("FAILED (trinculo returned non-zero code " + str(test1) + ")")
     stoptest=True
 
 if not stoptest:
     test2 = os.path.isfile(tmpdir + "/6" + ".log") and os.path.isfile(tmpdir + "/6" + ".assoc.multinom")
     if not test2:
-        print "FAILED (trinuculo failed to produce expected files)"
+        print("FAILED (trinuculo failed to produce expected files)")
         stoptest=True
 
 if not stoptest:
-    test3 = hashlib.md5(file(tmpdir + '/6.assoc.multinom').read()).digest()
-    if test3 != 'A~\x85\x00Zy^OsG_\xa9\xa7\xc5\r\xe3':
-        print "FAILED (trinculo produced file with incorrect MD5 sum: " + tmpdir + '/6.assoc.multinom)'
+    test3 = hashlib.md5(open(tmpdir + '/6.assoc.multinom').read().encode('utf-8')).hexdigest()
+    res3 = "417e85005a795e4f73475fa9a7c50de3"
+    if test3 != res3:
+        print("FAILED (trinculo produced file with incorrect MD5 sum: " + tmpdir + '/6.assoc.multinom)')
         stoptest=True
 
 if not stoptest:
-    print "PASSED"
+    print("PASSED")
 
 
 
-print "7. Testing Bayesian model selection...",
+print("7. Testing Bayesian model selection...", end=' ')
 
 test1 = subprocess.call([trinculo,"multinom","--bfile", examplepath + "/genotypes","--pheno", examplepath + "/phenos.txt","--phenoname","Pheno","--basepheno","Control","--covar", examplepath + "/pcs.txt","--normalize","--defaultprior","--select","--out", tmpdir + "/7"],stdout=devnull, stderr=devnull)
 
 stoptest=False
 if test1 != 0:
-    print "FAILED (trinculo returned non-zero code " + str(test1) + ")"
+    print("FAILED (trinculo returned non-zero code " + str(test1) + ")")
     stoptest=True
 
 if not stoptest:
     test2 = os.path.isfile(tmpdir + "/7" + ".log") and os.path.isfile(tmpdir + "/7" + ".assoc.multinom") and os.path.isfile(tmpdir + "/7" + ".select.multinom")
     if not test2:
-        print "FAILED (trinuculo failed to produce expected files)"
+        print("FAILED (trinuculo failed to produce expected files)")
         stoptest=True
 
 if not stoptest:
-    test3 = hashlib.md5(file(tmpdir + '/7.select.multinom').read()).digest()
-    if test3 != "9\xb9\xfa\xdf\x02'\xdcx\x82U\xce\xcf\xecx\x06!":
-        print "FAILED (trinculo produced file with incorrect MD5 sum: " + tmpdir + '/7.select.multinom)'
+    test3 = hashlib.md5(open(tmpdir + '/7.select.multinom').read().encode('utf-8')).hexdigest()
+    res3 = "39b9fadf0227dc788255cecfec780621"
+    if test3 != res3:
+        print("FAILED (trinculo produced file with incorrect MD5 sum: " + tmpdir + '/7.select.multinom)')
         stoptest=True
 
 if not stoptest:
-    print "PASSED"
+    print("PASSED")
 
-print "8. Testing Bayesian model selection (empirical prior)...",
+print("8. Testing Bayesian model selection (empirical prior)...", end=' ')
 
 test1 = subprocess.call([trinculo,"multinom","--bfile", examplepath + "/genotypes","--pheno", examplepath + "/phenos.txt","--phenoname","Pheno","--basepheno","Control","--covar", examplepath + "/pcs.txt","--normalize","--empiricalprior","--select","--out", tmpdir + "/8"],stdout=devnull, stderr=devnull)
 
 stoptest=False
 if test1 != 0:
-    print "FAILED (trinculo returned non-zero code " + str(test1) + ")"
+    print("FAILED (trinculo returned non-zero code " + str(test1) + ")")
     stoptest=True
 
 if not stoptest:
     test2 = os.path.isfile(tmpdir + "/8" + ".log") and os.path.isfile(tmpdir + "/8" + ".assoc.multinom") and os.path.isfile(tmpdir + "/8" + ".select.multinom") and os.path.isfile(tmpdir + "/8" + ".prior")
     if not test2:
-        print "FAILED (trinuculo failed to produce expected files)"
+        print("FAILED (trinuculo failed to produce expected files)")
         stoptest=True
 
 if not stoptest:
-    test3 = hashlib.md5(file(tmpdir + '/8.select.multinom').read()).digest()
-    if test3 != '\x89_3\xf2\xef\x96\x1e\xac\x8dy\xc8\xbf\x14\x1f\xfa%':
-        print "FAILED (trinculo produced file with incorrect MD5 sum: " + tmpdir + '/8.select.multinom)'
+    test3 = hashlib.md5(open(tmpdir + '/8.select.multinom').read().encode('utf-8')).hexdigest()
+    res3 = "895f33f2ef961eac8d79c8bf141ffa25"
+    if test3 != res3:
+        print("FAILED (trinculo produced file with incorrect MD5 sum: " + tmpdir + '/8.select.multinom)')
         stoptest=True
 
 if not stoptest:
-    print "PASSED"
+    print("PASSED")
 
-print "9. Testing ordinal regression...",
+print("9. Testing ordinal regression...", end=' ')
 
 
 
@@ -221,20 +228,14 @@
 
 stoptest=False
 if test1 != 0:
-    print "FAILED (trinculo returned non-zero code " + str(test1) + ")"
+    print("FAILED (trinculo returned non-zero code " + str(test1) + ")")
     stoptest=True
 
 if not stoptest:
     test2 = os.path.isfile(tmpdir + "/9" + ".log") and os.path.isfile(tmpdir + "/9" + ".assoc.ordinal")
     if not test2:
-        print "FAILED (trinuculo failed to produce expected files)"
-        stoptest=True
-
-if not stoptest:
-    test3 = hashlib.md5(file(tmpdir + '/9.assoc.ordinal').read()).digest()
-    if test3 != '\xbd\xab\xad\x10\xd3\xea\xd8r\x9f*~V\xf8\xb5\x9b\x9c':
-        print "FAILED (trinculo produced file with incorrect MD5 sum: " + tmpdir + '/9.assoc.ordinal)'
+        print("FAILED (trinuculo failed to produce expected files)")
         stoptest=True
 
 if not stoptest:
-    print "PASSED"
+    print("PASSED")
