Debian Codegraph @

debian/patches/python3

raw symbols SCIP
1 From: Michael R. Crusoe <[email protected]>
2 Subject: convert scripts to Python3
3 --- a/src/scripts/mkarv
4 +++ b/src/scripts/mkarv
5 @@ -1,6 +1,6 @@
6 -#!/usr/bin/env python
7 +#!/usr/bin/python3
8 +
9
10 -from __future__ import print_function
11
12 import argparse
13 import collections
14 @@ -301,10 +301,10 @@ def add_fraction_of_reads(fragment_lengt
15 Given a map of fragment lengths to read counts, calculate the fraction of all reads represented at each fragment length.
16 """
17 total_reads = 0.0
18 - for fragment_length, count in fragment_length_counts.items():
19 + for fragment_length, count in list(fragment_length_counts.items()):
20 total_reads += count
21
22 - for fragment_length, count in fragment_length_counts.items():
23 + for fragment_length, count in list(fragment_length_counts.items()):
24 if total_reads < 1:
25 fraction = 0
26 else:
27 @@ -322,7 +322,7 @@ def prepare_fragment_length_counts(fragm
28 """
29
30 # adjust the distribution to the requested maximum fragment length
31 - prepared_counts = collections.defaultdict(long)
32 + prepared_counts = collections.defaultdict(int)
33 for fragment_length, count, fraction_of_total_reads in fragment_length_counts:
34 if fragment_length <= max_fragment_length:
35 prepared_counts[fragment_length] = count
36 @@ -336,16 +336,16 @@ def construct_fragment_length_reference(
37 """
38 Construct a reference fragment length density distribution from all metrics in `data`.
39 """
40 - metrics = data['metrics'].values()
41 + metrics = list(data['metrics'].values())
42 metrics_count = len(metrics)
43
44 - reference_distribution = collections.defaultdict(long)
45 + reference_distribution = collections.defaultdict(int)
46 for m in metrics:
47 - for fragment_length, [count, fraction_of_total_reads] in m['fragment_length_counts'].items():
48 + for fragment_length, [count, fraction_of_total_reads] in list(m['fragment_length_counts'].items()):
49 if fragment_length <= max_fragment_length:
50 reference_distribution[fragment_length] += count
51
52 - for fragment_length, count in reference_distribution.items():
53 + for fragment_length, count in list(reference_distribution.items()):
54 reference_distribution[fragment_length] /= metrics_count
55
56 add_fraction_of_reads(reference_distribution)
57 @@ -382,7 +382,7 @@ def calculate_fragment_length_distance(m
58
59 nonreference_cdf = make_cdf(metrics['fragment_length_counts'])
60
61 - diff = list(map(lambda x: x[0] - x[1], zip(nonreference_cdf, reference_cdf)))
62 + diff = list([x[0] - x[1] for x in zip(nonreference_cdf, reference_cdf)])
63 if diff:
64 distance = (abs(max(diff)) > abs(min(diff))) and max(diff) or min(diff)
65
66 @@ -404,7 +404,7 @@ def add_fragment_length_distances(data,
67
68 loaded_distribution = {}
69 try:
70 - loaded_distribution = {int(k): int(v) for k, v in json.load(open_maybe_gzipped(reference)).items()}
71 + loaded_distribution = {int(k): int(v) for k, v in list(json.load(open_maybe_gzipped(reference)).items())}
72 except:
73 with open(reference, 'rb') as f:
74 dialect = csv.Sniffer().sniff(f.read(1024))
75 @@ -425,8 +425,8 @@ def add_fragment_length_distances(data,
76 logging.warn('Reference distribution lacks value at fragment length {}; assigning zero'.format(fragment_length))
77
78 # adjust the distribution to the requested maximum fragment length
79 - cleaned_distribution = collections.defaultdict(long)
80 - for fragment_length, [count, fraction_of_all_reads] in fragment_length_reference['distribution'].items():
81 + cleaned_distribution = collections.defaultdict(int)
82 + for fragment_length, [count, fraction_of_all_reads] in list(fragment_length_reference['distribution'].items()):
83 if fragment_length <= max_fragment_length:
84 cleaned_distribution[fragment_length] = count
85
86 @@ -443,15 +443,15 @@ def add_fragment_length_distances(data,
87
88 def calculate_reference_peak_metrics(data):
89 reference_peak_metrics = {
90 - 'source': 'calculated from ' + ', '.join(sorted([m['name'] for m in data['metrics'].values()])),
91 + 'source': 'calculated from ' + ', '.join(sorted([m['name'] for m in list(data['metrics'].values())])),
92 'cumulative_fraction_of_hqaa': [],
93 'cumulative_fraction_of_territory': []
94 }
95 - cfh = zip(*[metrics['peak_percentiles']['cumulative_fraction_of_hqaa'] for name, metrics in sorted(data['metrics'].items())])
96 - reference_peak_metrics['cumulative_fraction_of_hqaa'] = map(lambda x: sum(x) / len(x), cfh)
97 + cfh = list(zip(*[metrics['peak_percentiles']['cumulative_fraction_of_hqaa'] for name, metrics in sorted(data['metrics'].items())]))
98 + reference_peak_metrics['cumulative_fraction_of_hqaa'] = [sum(x) / len(x) for x in cfh]
99
100 - cft = zip(*[metrics['peak_percentiles']['cumulative_fraction_of_territory'] for name, metrics in sorted(data['metrics'].items())])
101 - reference_peak_metrics['cumulative_fraction_of_territory'] = map(lambda x: sum(x) / len(x), cft)
102 + cft = list(zip(*[metrics['peak_percentiles']['cumulative_fraction_of_territory'] for name, metrics in sorted(data['metrics'].items())]))
103 + reference_peak_metrics['cumulative_fraction_of_territory'] = [sum(x) / len(x) for x in cft]
104
105 return reference_peak_metrics
106
107 @@ -512,12 +512,12 @@ PERCENTAGES = {
108
109
110 def prepare_for_viewer(data):
111 - for name, metrics in data.items():
112 + for name, metrics in list(data.items()):
113 del metrics['peaks']
114 del metrics['peaks_fields']
115
116 metrics['percentages'] = {}
117 - for numerator, denominator in PERCENTAGES.items():
118 + for numerator, denominator in list(PERCENTAGES.items()):
119 key = '{}__{}'.format(numerator, denominator)
120 if metrics[denominator] == 0:
121 if metrics[numerator] == 0:
122 --- a/src/scripts/srvarv
123 +++ b/src/scripts/srvarv
124 @@ -1,4 +1,4 @@
125 -#!/usr/bin/env python
126 +#!/usr/bin/python3
127
128 import argparse
129 import os
130 @@ -7,8 +7,8 @@ try:
131 import http.server as httpserver
132 import socketserver
133 except:
134 - import SimpleHTTPServer as httpserver
135 - import SocketServer as socketserver
136 + import http.server as httpserver
137 + import socketserver as socketserver
138
139
140 if __name__ == '__main__':
141 @@ -28,7 +28,7 @@ if __name__ == '__main__':
142 instance = os.path.abspath(args.instance)
143 os.chdir(args.instance)
144
145 - print('Serving ataqv web viewer instance from {} at http://localhost:{}'.format(instance, args.port))
146 + print(('Serving ataqv web viewer instance from {} at http://localhost:{}'.format(instance, args.port)))
147 try:
148 httpd.serve_forever()
149 except KeyboardInterrupt: