about summary refs log tree commit diff
path: root/pkgs/by-name/ha/hap-py/python3.patch
blob: 0fee6d084cd41b8adac44eb8792b286735699c05 (plain) (blame)
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
diff --git a/src/c++/lib/tools/Roc.cpp b/src/c++/lib/tools/Roc.cpp
index fabe2be..2c6bb49 100644
--- a/src/c++/lib/tools/Roc.cpp
+++ b/src/c++/lib/tools/Roc.cpp
@@ -34,6 +34,9 @@
  */
 
 #include "helpers/Roc.hh"
+#include <stdexcept>
+#include <limits>
+
 
 #include <algorithm>
 #include <cmath>
diff --git a/src/cmake/cxx.cmake b/src/cmake/cxx.cmake
old mode 100755
new mode 100644
diff --git a/src/python/Haplo/happyroc.py b/src/python/Haplo/happyroc.py
index 152bd18..e439957 100644
--- a/src/python/Haplo/happyroc.py
+++ b/src/python/Haplo/happyroc.py
@@ -97,7 +97,7 @@ def roc(roc_table, output_path,
                 header = l.split("\t")
             else:
                 rec = {}
-                for k, v in itertools.izip(header, l.split("\t")):
+                for k, v in zip(header, l.split("\t")):
                     rec[k] = v
 
                 if filter_handling:
@@ -160,11 +160,11 @@ def roc(roc_table, output_path,
 
     if "all" not in result:
         # minimal empty DF
-        minidata = [{"Type": "SNP", "Subtype": "*", "Filter": "ALL", "Genotype": "*", "Subset": "*", "QQ": "*"} for _ in xrange(2)]
+        minidata = [{"Type": "SNP", "Subtype": "*", "Filter": "ALL", "Genotype": "*", "Subset": "*", "QQ": "*"} for _ in range(2)]
         minidata[1]["Type"] = "INDEL"
         result["all"] = pandas.DataFrame(minidata, columns=RESULT_ALLCOLUMNS)
         for i, c in enumerate(RESULT_ALLCOLUMNS):
-            result["all"][c] = result["all"][c].astype(RESULT_ALLDTYPES[i], raise_on_error=False)
+            result["all"][c] = result["all"][c].astype(RESULT_ALLDTYPES[i], errors="ignore")
 
     for k, v in result.items():
         result[k] = _postprocessRocData(pandas.DataFrame(v, columns=RESULT_ALLCOLUMNS))
diff --git a/src/python/Haplo/partialcredit.py b/src/python/Haplo/partialcredit.py
index d9e22bb..0f2b2cf 100644
--- a/src/python/Haplo/partialcredit.py
+++ b/src/python/Haplo/partialcredit.py
@@ -202,7 +202,7 @@ def partialCredit(vcfname,
     try:
         res = runParallel(pool,
                           preprocessWrapper,
-                          itertools.izip(itertools.repeat(vcfname), locations),
+                          zip(itertools.repeat(vcfname), locations),
                           {"reference": reference,
                            "decompose": decompose,
                            "leftshift": leftshift,
diff --git a/src/python/Haplo/quantify.py b/src/python/Haplo/quantify.py
index 042d13e..b1d362e 100755
--- a/src/python/Haplo/quantify.py
+++ b/src/python/Haplo/quantify.py
@@ -152,7 +152,7 @@ def run_quantify(filename,
         run_str += " -v %s" % pipes.quote(write_vcf)
 
     if regions:
-        for k, v in regions.iteritems():
+        for k, v in regions.items():
             run_str += " -R '%s:%s'" % (k, v)
 
     if roc_regions:
diff --git a/src/python/Somatic/Mutect.py b/src/python/Somatic/Mutect.py
index 7ac923c..81f08b5 100755
--- a/src/python/Somatic/Mutect.py
+++ b/src/python/Somatic/Mutect.py
@@ -148,7 +148,7 @@ def extractMutectSNVFeatures(vcfname, tag, avg_depth=None):
                 n_allele_alt_count = 0
             else:
                 n_allele_alt_count = 0
-                for a in xrange(0, len(alleles_alt)):
+                for a in range(0, len(alleles_alt)):
                     n_allele_alt_count += float(rec[n_sample + "AD"][a + 1])
 
             if n_allele_alt_count + n_allele_ref_count == 0:
@@ -163,7 +163,7 @@ def extractMutectSNVFeatures(vcfname, tag, avg_depth=None):
                 t_allele_alt_count = 0
             else:
                 t_allele_alt_count = 0
-                for a in xrange(0, len(alleles_alt)):
+                for a in range(0, len(alleles_alt)):
                     t_allele_alt_count += float(rec[t_sample + "AD"][a + 1])
 
             if t_allele_alt_count + t_allele_ref_count == 0:
@@ -344,7 +344,7 @@ def extractMutectIndelFeatures(vcfname, tag, avg_depth=None):
                 n_allele_alt_count = 0
             else:
                 n_allele_alt_count = 0
-                for a in xrange(0, len(alleles_alt)):
+                for a in range(0, len(alleles_alt)):
                     n_allele_alt_count += float(rec[n_sample + "AD"][a + 1])
 
             if n_allele_alt_count + n_allele_ref_count == 0:
@@ -359,7 +359,7 @@ def extractMutectIndelFeatures(vcfname, tag, avg_depth=None):
                 t_allele_alt_count = 0
             else:
                 t_allele_alt_count = 0
-                for a in xrange(0, len(alleles_alt)):
+                for a in range(0, len(alleles_alt)):
                     t_allele_alt_count += float(rec[t_sample + "AD"][a + 1])
 
             if t_allele_alt_count + t_allele_ref_count == 0:
diff --git a/src/python/Tools/bcftools.py b/src/python/Tools/bcftools.py
index 6146b7a..6d80d14 100755
--- a/src/python/Tools/bcftools.py
+++ b/src/python/Tools/bcftools.py
@@ -128,8 +128,8 @@ def concatenateParts(output, *args):
             to_delete.append(tf2.name)
             to_delete.append(tf1.name + ".csi")
             to_delete.append(tf2.name + ".csi")
-            half1 = [tf1.name] + list(args[:len(args)/2])
-            half2 = [tf2.name] + list(args[len(args)/2:])
+            half1 = [tf1.name] + list(args[:len(args)//2])
+            half2 = [tf2.name] + list(args[len(args)//2:])
             concatenateParts(*half1)
             runBcftools("index", tf1.name)
             concatenateParts(*half2)
diff --git a/src/python/Tools/metric.py b/src/python/Tools/metric.py
index 71ccc99..372626d 100755
--- a/src/python/Tools/metric.py
+++ b/src/python/Tools/metric.py
@@ -115,7 +115,7 @@ def replaceNaNs(xobject):
             if type(xobject[k]) is dict or type(xobject[k]) is list or type(xobject[k]) is float:
                 xobject[k] = replaceNaNs(xobject[k])
     elif type(xobject) is list:
-        for k in xrange(0, len(xobject)):
+        for k in range(0, len(xobject)):
             if type(xobject[k]) is dict or type(xobject[k]) is list or type(xobject[k]) is float:
                 xobject[k] = replaceNaNs(xobject[k])
     elif type(xobject) is float:
diff --git a/src/python/Tools/parallel.py b/src/python/Tools/parallel.py
index 9d49760..5fcb37e 100755
--- a/src/python/Tools/parallel.py
+++ b/src/python/Tools/parallel.py
@@ -17,9 +17,9 @@ import logging
 import traceback
 import subprocess
 import multiprocessing
-import cPickle
+import pickle
 import tempfile
-from itertools import islice, izip, repeat
+from itertools import islice, repeat
 
 from . import LoggingWriter
 
@@ -93,7 +93,7 @@ def runParallel(pool, fun, par, *args, **kwargs):
 
     """
     if pool:
-        result = pool.map(parMapper, izip(par, repeat( { "fun": fun, "args": args, "kwargs": kwargs } )))
+        result = pool.map(parMapper, zip(par, repeat( { "fun": fun, "args": args, "kwargs": kwargs } )))
     else:
         result = []
         for c in par:
diff --git a/src/python/Tools/sessioninfo.py b/src/python/Tools/sessioninfo.py
index 75650ec..b49bf59 100644
--- a/src/python/Tools/sessioninfo.py
+++ b/src/python/Tools/sessioninfo.py
@@ -34,7 +34,6 @@ def sessionInfo():
               'version': version,
               'runInfo': [{"key": "commandline", "value": " ".join(sys.argv)}],
               'uname': " / ".join(platform.uname()),
-              'dist': " / ".join(platform.dist()),
               'mac_ver': " / ".join([platform.mac_ver()[0], platform.mac_ver()[2]]),
               'python_implementation': platform.python_implementation(),
               'python_version': platform.python_version(),
diff --git a/src/python/Tools/vcfcallerinfo.py b/src/python/Tools/vcfcallerinfo.py
index eb7e86e..947f2c4 100755
--- a/src/python/Tools/vcfcallerinfo.py
+++ b/src/python/Tools/vcfcallerinfo.py
@@ -33,8 +33,8 @@ class CallerInfo(object):
 
     def asDict(self):
         kvd = ["name", "version", "parameters"]
-        return {"aligners": [dict(y for y in itertools.izip(kvd, x)) for x in self.aligners],
-                "callers": [dict(y for y in itertools.izip(kvd, x)) for x in self.callers]}
+        return {"aligners": [dict(y for y in zip(kvd, x)) for x in self.aligners],
+                "callers": [dict(y for y in zip(kvd, x)) for x in self.callers]}
 
     def addVCF(self, vcfname):
         """ Add caller versions from a VCF
diff --git a/src/python/hap.py b/src/python/hap.py
index 8045936..93279a4 100755
--- a/src/python/hap.py
+++ b/src/python/hap.py
@@ -188,7 +188,7 @@ def main():
         parser.print_help()
         exit(1)
 
-    print "Hap.py %s" % Tools.version        
+    print("Hap.py %s" % Tools.version)
     if args.version:
         exit(0)
 
diff --git a/src/python/ovc.py b/src/python/ovc.py
index 2837255..20b4442 100755
--- a/src/python/ovc.py
+++ b/src/python/ovc.py
@@ -34,7 +34,7 @@ lines = 1
 for line in f:
 	l = line.split("\t")
 	if len(l) > 3 and (last-1) > int(l[1]):
-		print "Overlap at %s:%i (line %i)" % (l[0], int(l[1]), lines)
+		print(Overlap at %s:%i (line %i)) % (l[0], int(l[1]), lines)
 		exit(1)
 	elif len(l) > 3:
 		last = int(l[2])
diff --git a/src/python/pre.py b/src/python/pre.py
index 5ca1644..a37a4b2 100755
--- a/src/python/pre.py
+++ b/src/python/pre.py
@@ -47,8 +47,8 @@ import Haplo.partialcredit
 def hasChrPrefix(chrlist):
     """ returns if list of chr names has a chr prefix or not """
 
-    noprefix = map(str, range(23)) + ["X", "Y", "MT"]
-    withprefix = ["chr" + x for x in map(str, range(23)) + ["X", "Y", "M"]]
+    noprefix = [str(x) for x in range(23)] + ["X", "Y", "MT"]
+    withprefix = ["chr" + str(x) for x in range(23)] + ["X", "Y", "M"]
 
     count_noprefix = len(list(set(noprefix) & set(chrlist)))
     count_prefix = len(list(set(withprefix) & set(chrlist)))
@@ -126,7 +126,7 @@ def preprocess(vcf_input,
 
         if gender == "auto":
             logging.info(mf)
-            if "female" in mf:
+            if b"female" in mf:
                 gender = "female"
             else:
                 gender = "male"
@@ -392,7 +392,7 @@ def main():
         exit(0)
 
     if args.version:
-        print "pre.py %s" % Tools.version  # noqa:E999
+        print(pre.py %s) % Tools.version  # noqa:E999
         exit(0)
 
     args.input = args.input[0]
diff --git a/src/python/qfy.py b/src/python/qfy.py
index 4f247ee..59ed68a 100755
--- a/src/python/qfy.py
+++ b/src/python/qfy.py
@@ -203,8 +203,8 @@ def quantify(args):
 
     # in default mode, print result summary to stdout
     if not args.quiet and not args.verbose:
-        print "Benchmarking Summary:"
-        print essential_numbers.to_string(index=False)
+        print("Benchmarking Summary:")
+        print(essential_numbers.to_string(index=False))
 
     # keep this for verbose output
     if not args.verbose:
@@ -213,12 +213,12 @@ def quantify(args):
         except:
             pass
 
-    for t in res.iterkeys():
+    for t in res.keys():
         metrics_output["metrics"].append(dataframeToMetricsTable("roc." + t, res[t]))
 
     # gzip JSON output
     if args.write_json:
         with gzip.open(args.reports_prefix + ".metrics.json.gz", "w") as fp:
-            json.dump(metrics_output, fp)
+            fp.write(json.dumps(metrics_output, default=np_encoder).encode('ascii'))
 
 
@@ -362,7 +363,7 @@ def main():
         exit(0)
 
     if args.version:
-        print "qfy.py %s" % Tools.version
+        print(qfy.py %s) % Tools.version
         exit(0)
 
     if args.fp_bedfile and args.preprocessing_truth_confregions:
diff --git a/src/python/som.py b/src/python/som.py
index e942351..c01d522 100755
--- a/src/python/som.py
+++ b/src/python/som.py
@@ -640,7 +640,7 @@ def main():
                              "overlap):\n" + ambie.to_string(index=False))
                 # in default mode, print result summary to stdout
                 if not args.quiet and not args.verbose:
-                    print "FP/ambiguity classes with info (multiple classes can " \
+                    print(FP/ambiguity classes with info (multiple classes can ) \
                           "overlap):\n" + ambie.to_string(index=False)
                 ambie.to_csv(args.output + ".ambiclasses.csv")
                 metrics_output["metrics"].append(dataframeToMetricsTable("ambiclasses", ambie))
@@ -659,7 +659,7 @@ def main():
                     formatters={'reason': '{{:<{}s}}'.format(ambie['reason'].str.len().max()).format}, index=False))
                 # in default mode, print result summary to stdout
                 if not args.quiet and not args.verbose:
-                    print "Reasons for defining as ambiguous (multiple reasons can overlap):\n" + ambie.to_string(
+                    print(Reasons for defining as ambiguous (multiple reasons can overlap):\n) + ambie.to_string(
                         formatters={'reason': '{{:<{}s}}'.format(ambie['reason'].str.len().max()).format}, index=False)
                 ambie.to_csv(args.output + ".ambireasons.csv")
                 metrics_output["metrics"].append(dataframeToMetricsTable("ambireasons", ambie))
@@ -936,7 +936,7 @@ def main():
         logging.info("\n" + res.to_string())
         # in default mode, print result summary to stdout
         if not args.quiet and not args.verbose:
-            print "\n" + res.to_string()
+            print(\n) + res.to_string()
 
         res["sompyversion"] = vstring
 
diff --git a/src/python/qfy.py b/src/python/qfy.py
index 59ed68a..be8d7e1 100755
--- a/src/python/qfy.py
+++ b/src/python/qfy.py
@@ -33,6 +33,7 @@ import pandas
 import json
 import tempfile
 import gzip
+import numpy as np
 
 scriptDir = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
 sys.path.append(os.path.abspath(os.path.join(scriptDir, '..', 'lib', 'python27')))
@@ -45,6 +46,10 @@ import Haplo.happyroc
 import Haplo.gvcf2bed
 from Tools import fastasize
 
+# Cannot convert data to json without a custom enconder
+def np_encoder(object):
+    if isinstance(object, np.generic):
+        return object.item()
 
 def quantify(args):
     """ Run quantify and write tables """