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 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442
|
Description: Use 2to3 to port to Python3
Bug-Debian: https://bugs.debian.org/936281
Author: Andreas Tille <tille@debian.org>
Last-Update: Tue, 10 Sep 2019 08:02:24 +0200
--- a/Makefile
+++ b/Makefile
@@ -364,11 +364,11 @@ centrifuge.bat:
centrifuge-build.bat:
echo "@echo off" > centrifuge-build.bat
- echo "python %~dp0/centrifuge-build %*" >> centrifuge-build.bat
+ echo "python3 %~dp0/centrifuge-build %*" >> centrifuge-build.bat
centrifuge-inspect.bat:
echo "@echo off" > centrifuge-inspect.bat
- echo "python %~dp0/centrifuge-inspect %*" >> centrifuge-inspect.bat
+ echo "python3 %~dp0/centrifuge-inspect %*" >> centrifuge-inspect.bat
.PHONY: centrifuge-src
--- a/centrifuge-build
+++ b/centrifuge-build
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/python3
"""
Copyright 2014, Daehwan Kim <infphilo@gmail.com>
--- a/centrifuge-inspect
+++ b/centrifuge-inspect
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/python3
"""
Copyright 2014, Daehwan Kim <infphilo@gmail.com>
--- a/evaluation/centrifuge_evaluate.py
+++ b/evaluation/centrifuge_evaluate.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/python3
import sys, os, subprocess, inspect
import platform, multiprocessing
@@ -25,7 +25,7 @@ def read_taxonomy_tree(tax_file):
"""
def compare_scm(centrifuge_out, true_out, taxonomy_tree, rank):
ancestors = set()
- for tax_id in taxonomy_tree.keys():
+ for tax_id in list(taxonomy_tree.keys()):
if tax_id in ancestors:
continue
while True:
@@ -106,7 +106,7 @@ def compare_scm(centrifuge_out, true_out
unclassified += 1
raw_unique_classified = 0
- for value in db_dic.values():
+ for value in list(db_dic.values()):
if len(value) == 1:
raw_unique_classified += 1
return classified, unique_classified, unclassified, len(db_dic), raw_unique_classified
@@ -152,7 +152,7 @@ def compare_abundance(centrifuge_out, tr
if tax_id in db_dic:
SSR += (abundance - db_dic[tax_id]) ** 2;
if debug:
- print >> sys.stderr, "\t\t\t\t{:<10}: {:.6} vs. {:.6} (truth vs. centrifuge)".format(tax_id, abundance, db_dic[tax_id])
+ print("\t\t\t\t{:<10}: {:.6} vs. {:.6} (truth vs. centrifuge)".format(tax_id, abundance, db_dic[tax_id]), file=sys.stderr)
else:
SSR += (abundance) ** 2
@@ -179,7 +179,7 @@ def sql_execute(sql_db, sql_query):
"""
def create_sql_db(sql_db):
if os.path.exists(sql_db):
- print >> sys.stderr, sql_db, "already exists!"
+ print(sql_db, "already exists!", file=sys.stderr)
return
columns = [
@@ -316,7 +316,7 @@ def evaluate(index_base,
os.mkdir(index_path)
index_fnames = ["%s/%s.%d.cf" % (index_path, index_base, i+1) for i in range(3)]
if not check_files(index_fnames):
- print >> sys.stderr, "Downloading indexes: %s" % ("index")
+ print("Downloading indexes: %s" % ("index"), file=sys.stderr)
os.system("cd %s; wget ftp://ftp.ccb.jhu.edu/pub/infphilo/centrifuge/data/%s.tar.gz; tar xvzf %s.tar.gz; rm %s.tar.gz; ln -s %s/%s* .; cd -" % \
(index_path, index_base, index_base, index_base, index_base, index_base))
assert check_files(index_fnames)
@@ -356,7 +356,7 @@ def evaluate(index_base,
scm_fname = "%s/%s.scm" % (read_path, read_base)
read_fnames = [read1_fname, read2_fname, truth_fname, scm_fname]
if not check_files(read_fnames):
- print >> sys.stderr, "Simulating reads %s_1.fq %s_2.fq ..." % (read_base, read_base)
+ print("Simulating reads %s_1.fq %s_2.fq ..." % (read_base, read_base), file=sys.stderr)
centrifuge_simulate = os.path.join(path_base, "centrifuge_simulate_reads.py")
simulate_cmd = [centrifuge_simulate,
"--num-fragment", str(num_fragment)]
@@ -377,11 +377,11 @@ def evaluate(index_base,
else:
base_fname = read_base + "_single"
- print >> sys.stderr, "Database: %s" % (index_base)
+ print("Database: %s" % (index_base), file=sys.stderr)
if paired:
- print >> sys.stderr, "\t%d million pairs" % (num_fragment / 1000000)
+ print("\t%d million pairs" % (num_fragment / 1000000), file=sys.stderr)
else:
- print >> sys.stderr, "\t%d million reads" % (num_fragment / 1000000)
+ print("\t%d million reads" % (num_fragment / 1000000), file=sys.stderr)
program_bin_base = "%s/.." % path_base
def get_program_version(program, version):
@@ -428,7 +428,7 @@ def evaluate(index_base,
if version:
program_name += ("_%s" % version)
- print >> sys.stderr, "\t%s\t%s" % (program_name, str(datetime.now()))
+ print("\t%s\t%s" % (program_name, str(datetime.now())), file=sys.stderr)
if paired:
program_dir = program_name + "_paired"
else:
@@ -449,7 +449,7 @@ def evaluate(index_base,
program_cmd = get_program_cmd(program, version, read1_fname, read2_fname, out_fname)
start_time = datetime.now()
if verbose:
- print >> sys.stderr, "\t", start_time, " ".join(program_cmd)
+ print("\t", start_time, " ".join(program_cmd), file=sys.stderr)
if program in ["centrifuge"]:
proc = subprocess.Popen(program_cmd, stdout=open(out_fname, "w"), stderr=subprocess.PIPE)
else:
@@ -462,7 +462,7 @@ def evaluate(index_base,
if duration < 0.1:
duration = 0.1
if verbose:
- print >> sys.stderr, "\t", finish_time, "finished:", duration
+ print("\t", finish_time, "finished:", duration, file=sys.stderr)
results = {"strain" : [0, 0, 0],
"species" : [0, 0, 0],
@@ -484,21 +484,21 @@ def evaluate(index_base,
# if rank == "strain":
# assert num_cases == num_fragment
- print >> sys.stderr, "\t\t%s" % rank
- print >> sys.stderr, "\t\t\tsensitivity: {:,} / {:,} ({:.2%})".format(classified, num_cases, float(classified) / num_cases)
- print >> sys.stderr, "\t\t\tprecision : {:,} / {:,} ({:.2%})".format(classified, raw_classified, float(classified) / raw_classified)
- print >> sys.stderr, "\n\t\t\tfor uniquely classified ",
+ print("\t\t%s" % rank, file=sys.stderr)
+ print("\t\t\tsensitivity: {:,} / {:,} ({:.2%})".format(classified, num_cases, float(classified) / num_cases), file=sys.stderr)
+ print("\t\t\tprecision : {:,} / {:,} ({:.2%})".format(classified, raw_classified, float(classified) / raw_classified), file=sys.stderr)
+ print("\n\t\t\tfor uniquely classified ", end=' ', file=sys.stderr)
if paired:
- print >> sys.stderr, "pairs"
+ print("pairs", file=sys.stderr)
else:
- print >> sys.stderr, "reads"
- print >> sys.stderr, "\t\t\t\t\tsensitivity: {:,} / {:,} ({:.2%})".format(unique_classified, num_cases, float(unique_classified) / num_cases)
- print >> sys.stderr, "\t\t\t\t\tprecision : {:,} / {:,} ({:.2%})".format(unique_classified, raw_unique_classified, float(unique_classified) / raw_unique_classified)
+ print("reads", file=sys.stderr)
+ print("\t\t\t\t\tsensitivity: {:,} / {:,} ({:.2%})".format(unique_classified, num_cases, float(unique_classified) / num_cases), file=sys.stderr)
+ print("\t\t\t\t\tprecision : {:,} / {:,} ({:.2%})".format(unique_classified, raw_unique_classified, float(unique_classified) / raw_unique_classified), file=sys.stderr)
# Calculate sum of squared residuals in abundance
if rank == "strain":
abundance_SSR = compare_abundance("centrifuge_report.tsv", truth_fname, taxonomy_tree, debug)
- print >> sys.stderr, "\t\t\tsum of squared residuals in abundance: {}".format(abundance_SSR)
+ print("\t\t\tsum of squared residuals in abundance: {}".format(abundance_SSR), file=sys.stderr)
if runtime_only:
os.chdir("..")
--- a/evaluation/centrifuge_simulate_reads.py
+++ b/evaluation/centrifuge_simulate_reads.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/python3
#
# Copyright 2015, Daehwan Kim <infphilo@gmail.com>
@@ -156,7 +156,7 @@ def read_transcript(genomes_seq, gtf_fil
transcripts[transcript_id][2].append([left, right])
# Sort exons and merge where separating introns are <=5 bps
- for tran, [chr, strand, exons] in transcripts.items():
+ for tran, [chr, strand, exons] in list(transcripts.items()):
exons.sort()
tmp_exons = [exons[0]]
for i in range(1, len(exons)):
@@ -167,7 +167,7 @@ def read_transcript(genomes_seq, gtf_fil
transcripts[tran] = [chr, strand, tmp_exons]
tmp_transcripts = {}
- for tran, [chr, strand, exons] in transcripts.items():
+ for tran, [chr, strand, exons] in list(transcripts.items()):
exon_lens = [e[1] - e[0] + 1 for e in exons]
transcript_len = sum(exon_lens)
if transcript_len >= frag_len:
@@ -444,8 +444,8 @@ def getSamAlignment(dna, exons, genome_s
MD += ("{}".format(MD_match_len))
if len(read_seq) != read_len:
- print >> sys.stderr, "read length differs:", len(read_seq), "vs.", read_len
- print >> sys.stderr, pos, "".join(cigars), cigar_descs, MD, XM, NM, Zs
+ print("read length differs:", len(read_seq), "vs.", read_len, file=sys.stderr)
+ print(pos, "".join(cigars), cigar_descs, MD, XM, NM, Zs, file=sys.stderr)
assert False
return pos, cigars, cigar_descs, MD, XM, NM, Zs, read_seq
@@ -575,8 +575,8 @@ def samRepOk(genome_seq, read_seq, chr,
tMD += ("{}".format(match_len))
if tMD != MD or tXM != XM or tNM != NM or XM > max_mismatch or XM != NM:
- print >> sys.stderr, chr, pos, cigar, MD, XM, NM, Zs
- print >> sys.stderr, tMD, tXM, tNM
+ print(chr, pos, cigar, MD, XM, NM, Zs, file=sys.stderr)
+ print(tMD, tXM, tNM, file=sys.stderr)
assert False
@@ -631,7 +631,7 @@ def simulate_reads(index_fname, base_fna
# Read genome sequences into memory
genomes_fname = index_fname + ".fa"
if not os.path.exists(genomes_fname):
- print >> sys.stderr, "Extracting genomes from Centrifuge index to %s, which may take a few hours ..." % (genomes_fname)
+ print("Extracting genomes from Centrifuge index to %s, which may take a few hours ..." % (genomes_fname), file=sys.stderr)
extract_cmd = [centrifuge_inspect,
index_fname]
extract_proc = subprocess.Popen(extract_cmd, stdout=open(genomes_fname, 'w'))
@@ -660,15 +660,15 @@ def simulate_reads(index_fname, base_fna
assert num_frag == sum(expr_profile)
if dna:
- genome_ids = genome_seqs.keys()
+ genome_ids = list(genome_seqs.keys())
else:
- transcript_ids = transcripts.keys()
+ transcript_ids = list(transcripts.keys())
random.shuffle(transcript_ids)
assert len(transcript_ids) >= len(expr_profile)
# Truth table
truth_file = open(base_fname + ".truth", "w")
- print >> truth_file, "taxID\tgenomeLen\tnumReads\tabundance\tname"
+ print("taxID\tgenomeLen\tnumReads\tabundance\tname", file=truth_file)
truth_list = []
normalized_sum = 0.0
debug_num_frag = 0
@@ -695,19 +695,19 @@ def simulate_reads(index_fname, base_fna
if can_tax_id in names:
name = names[can_tax_id]
abundance = raw_abundance / genome_len / normalized_sum
- print >> truth_file, "{}\t{}\t{}\t{:.6}\t{}".format(tax_id, genome_len, t_num_frags, abundance, name)
+ print("{}\t{}\t{}\t{:.6}\t{}".format(tax_id, genome_len, t_num_frags, abundance, name), file=truth_file)
truth_file.close()
# Sequence Classification Map (SCM) - something I made up ;-)
scm_file = open(base_fname + ".scm", "w")
# Write SCM header
- print >> scm_file, "@HD\tVN:1.0\tSO:unsorted"
- for tax_id in genome_seqs.keys():
+ print("@HD\tVN:1.0\tSO:unsorted", file=scm_file)
+ for tax_id in list(genome_seqs.keys()):
name = ""
if tax_id in names:
name = names[tax_id]
- print >> scm_file, "@SQ\tTID:%s\tSN:%s\tLN:%d" % (tax_id, name, len(genome_seqs[tax_id]))
+ print("@SQ\tTID:%s\tSN:%s\tLN:%d" % (tax_id, name, len(genome_seqs[tax_id])), file=scm_file)
read_file = open(base_fname + "_1.fa", "w")
if paired_end:
@@ -718,11 +718,11 @@ def simulate_reads(index_fname, base_fna
t_num_frags = expr_profile[t]
if dna:
tax_id = genome_ids[t]
- print >> sys.stderr, "TaxID: %s, num fragments: %d" % (tax_id, t_num_frags)
+ print("TaxID: %s, num fragments: %d" % (tax_id, t_num_frags), file=sys.stderr)
else:
transcript_id = transcript_ids[t]
chr, strand, transcript_len, exons = transcripts[transcript_id]
- print >> sys.stderr, transcript_id, t_num_frags
+ print(transcript_id, t_num_frags, file=sys.stderr)
genome_seq = genome_seqs[tax_id]
genome_len = len(genome_seq)
@@ -763,14 +763,14 @@ def simulate_reads(index_fname, base_fna
XS = "\tXS:A:{}".format(strand)
TI = "\tTI:Z:{}".format(transcript_id)
- print >> read_file, ">{}".format(cur_read_id)
- print >> read_file, read_seq
+ print(">{}".format(cur_read_id), file=read_file)
+ print(read_seq, file=read_file)
output = "{}\t{}\t{}\t{}\tNM:i:{}\tMD:Z:{}".format(cur_read_id, tax_id, pos + 1, cigar_str, NM, MD)
if paired_end:
- print >> read2_file, ">{}".format(cur_read_id)
- print >> read2_file, reverse_complement(read2_seq)
+ print(">{}".format(cur_read_id), file=read2_file)
+ print(reverse_complement(read2_seq), file=read2_file)
output += "\t{}\t{}\tNM2:i:{}\tMD2:Z:{}".format(pos2 + 1, cigar2_str, NM2, MD2)
- print >> scm_file, output
+ print(output, file=scm_file)
cur_read_id += 1
@@ -865,7 +865,7 @@ if __name__ == '__main__':
parser.print_help()
exit(1)
if not args.dna:
- print >> sys.stderr, "Error: --rna is not implemented."
+ print("Error: --rna is not implemented.", file=sys.stderr)
exit(1)
# if args.dna:
# args.expr_profile = "constant"
--- a/evaluation/test/centrifuge_evaluate_mason.py
+++ b/evaluation/test/centrifuge_evaluate_mason.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/python3
import sys, os, subprocess, inspect
import platform, multiprocessing
@@ -27,7 +27,7 @@ def compare_scm(centrifuge_out, true_out
higher_ranked = {}
ancestors = set()
- for tax_id in taxonomy_tree.keys():
+ for tax_id in list(taxonomy_tree.keys()):
if tax_id in ancestors:
continue
while True:
@@ -82,7 +82,7 @@ def compare_scm(centrifuge_out, true_out
fields = line.strip().split('\t')
if len(fields) != 3:
- print >> sys.stderr, "Warning: %s missing" % (line.strip())
+ print("Warning: %s missing" % (line.strip()), file=sys.stderr)
continue
read_name, tax_id = fields[1:3]
# Traverse up taxonomy tree to match the given rank parameter
@@ -117,7 +117,7 @@ def compare_scm(centrifuge_out, true_out
# print read_name
raw_unique_classified = 0
- for read_name, maps in db_dic.items():
+ for read_name, maps in list(db_dic.items()):
if len(maps) == 1 and read_name not in higher_ranked:
raw_unique_classified += 1
return classified, unique_classified, unclassified, len(db_dic), raw_unique_classified
@@ -184,7 +184,7 @@ def evaluate(index_base,
read_fname]
if verbose:
- print >> sys.stderr, ' '.join(centrifuge_cmd)
+ print(' '.join(centrifuge_cmd), file=sys.stderr)
out_fname = "centrifuge.output"
proc = subprocess.Popen(centrifuge_cmd, stdout=open(out_fname, "w"), stderr=subprocess.PIPE)
@@ -208,12 +208,12 @@ def evaluate(index_base,
# if rank == "strain":
# assert num_cases == num_fragment
- print >> sys.stderr, "\t\t%s" % rank
- print >> sys.stderr, "\t\t\tsensitivity: {:,} / {:,} ({:.2%})".format(classified, num_cases, float(classified) / num_cases)
- print >> sys.stderr, "\t\t\tprecision : {:,} / {:,} ({:.2%})".format(classified, raw_classified, float(classified) / raw_classified)
- print >> sys.stderr, "\n\t\t\tfor uniquely classified "
- print >> sys.stderr, "\t\t\t\t\tsensitivity: {:,} / {:,} ({:.2%})".format(unique_classified, num_cases, float(unique_classified) / num_cases)
- print >> sys.stderr, "\t\t\t\t\tprecision : {:,} / {:,} ({:.2%})".format(unique_classified, raw_unique_classified, float(unique_classified) / raw_unique_classified)
+ print("\t\t%s" % rank, file=sys.stderr)
+ print("\t\t\tsensitivity: {:,} / {:,} ({:.2%})".format(classified, num_cases, float(classified) / num_cases), file=sys.stderr)
+ print("\t\t\tprecision : {:,} / {:,} ({:.2%})".format(classified, raw_classified, float(classified) / raw_classified), file=sys.stderr)
+ print("\n\t\t\tfor uniquely classified ", file=sys.stderr)
+ print("\t\t\t\t\tsensitivity: {:,} / {:,} ({:.2%})".format(unique_classified, num_cases, float(unique_classified) / num_cases), file=sys.stderr)
+ print("\t\t\t\t\tprecision : {:,} / {:,} ({:.2%})".format(unique_classified, raw_unique_classified, float(unique_classified) / raw_unique_classified), file=sys.stderr)
# Calculate sum of squared residuals in abundance
"""
@@ -252,12 +252,12 @@ def evaluate(index_base,
if rank_taxID not in true_abundance:
true_abundance[rank_taxID] = 0.0
true_abundance[rank_taxID] += (reads / float(genomeSize))
- for taxID, reads in true_abundance.items():
+ for taxID, reads in list(true_abundance.items()):
true_abundance[taxID] /= total_sum
- print >> sys.stderr, "number of genomes:", num_genomes
- print >> sys.stderr, "number of species:", num_species
- print >> sys.stderr, "number of uniq species:", len(true_abundance)
+ print("number of genomes:", num_genomes, file=sys.stderr)
+ print("number of species:", num_species, file=sys.stderr)
+ print("number of uniq species:", len(true_abundance), file=sys.stderr)
read_fname = "centrifuge_data/bacteria_sim10M/bacteria_sim10M.fa"
summary_fname = "centrifuge.summary"
@@ -271,14 +271,14 @@ def evaluate(index_base,
read_fname]
if verbose:
- print >> sys.stderr, ' '.join(centrifuge_cmd)
+ print(' '.join(centrifuge_cmd), file=sys.stderr)
out_fname = "centrifuge.output"
proc = subprocess.Popen(centrifuge_cmd, stdout=open(out_fname, "w"), stderr=subprocess.PIPE)
proc.communicate()
calc_abundance = {}
- for taxID in true_abundance.keys():
+ for taxID in list(true_abundance.keys()):
calc_abundance[taxID] = 0.0
first = True
for line in open(summary_fname):
@@ -296,12 +296,12 @@ def evaluate(index_base,
"""
abundance_file = open("abundance.cmp", 'w')
- print >> abundance_file, "taxID\ttrue\tcalc\trank"
+ print("taxID\ttrue\tcalc\trank", file=abundance_file)
for rank in ranks:
if rank == "strain":
continue
true_abundance_rank, calc_abundance_rank = {}, {}
- for taxID in true_abundance.keys():
+ for taxID in list(true_abundance.keys()):
assert taxID in calc_abundance
rank_taxID = taxID
while True:
@@ -322,11 +322,11 @@ def evaluate(index_base,
calc_abundance_rank[rank_taxID] += calc_abundance[taxID]
ssr = 0.0 # Sum of Squared Residuals
- for taxID in true_abundance_rank.keys():
+ for taxID in list(true_abundance_rank.keys()):
assert taxID in calc_abundance_rank
ssr += (true_abundance_rank[taxID] - calc_abundance_rank[taxID]) ** 2
- print >> abundance_file, "%s\t%.6f\t%.6f\t%s" % (taxID, true_abundance_rank[taxID], calc_abundance_rank[taxID], rank)
- print >> sys.stderr, "%s) Sum of squared residuals: %.6f" % (rank, ssr)
+ print("%s\t%.6f\t%.6f\t%s" % (taxID, true_abundance_rank[taxID], calc_abundance_rank[taxID], rank), file=abundance_file)
+ print("%s) Sum of squared residuals: %.6f" % (rank, ssr), file=sys.stderr)
abundance_file.close()
|