Description: Use 2to3 to port to Python3
Bug-Debian: https://bugs.debian.org/938565
Author: Andreas Tille <tille@debian.org>
Last-Update: Wed, 04 Sep 2019 16:44:45 +0200

--- a/tools/TQS.py
+++ b/tools/TQS.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/python3
 
 __doc__ = """
 TQS
@@ -53,18 +53,18 @@ def main():
 		f = open(opts.seqfile)
 		seq = f.readlines()
 		f.close()
-	except Exception, e:
-		print "ERROR: Could not read from %s: %s" % (opts.seqfile, e)
-		print usage % (sys.argv[0:])
+	except Exception as e:
+		print("ERROR: Could not read from %s: %s" % (opts.seqfile, e))
+		print(usage % (sys.argv[0:]))
 		sys.exit()
 
         try:
                 f = open(opts.qualfile)
                 qual = f.readlines()
                 f.close()
-        except Exception, e:
-                print "ERROR: Could not read from %s: %s" % (opts.qualfile, e)
-                print usage % (sys.argv[0:])
+        except Exception as e:
+                print("ERROR: Could not read from %s: %s" % (opts.qualfile, e))
+                print(usage % (sys.argv[0:]))
                 sys.exit()
 	
 
@@ -75,22 +75,22 @@ def main():
         try:
                 FASTA = open(fasta, 'w')
         except:
-                print "ERROR: Can not write to %s" % fasta
+                print("ERROR: Can not write to %s" % fasta)
                 sys.exit()
 
 	try:
 		LOG = open(log, 'w')
 	except:
-		print "ERROR: Can not write to %s" % log
+		print("ERROR: Can not write to %s" % log)
 		sys.exit()
 	
 
 	if opts.mer < 15 or opts.mer > 200:
-		print "ERROR: -l must be a number between 15 and 200."
+		print("ERROR: -l must be a number between 15 and 200.")
 		sys.exit()
 	
 	if opts.consec < 16 or opts.consec > opts.mer:
-		print "ERROR: -c must be a number between 16 and -l."
+		print("ERROR: -c must be a number between 16 and -l.")
 		sys.exit()
 
 	LOG.write("""
@@ -130,7 +130,7 @@ def parseQualFile(threshold, difference,
 	read_number = 0
 
 	if verbose:
-		print "Printing trimming pattern for all reads passing the set threshold values...\n"
+		print("Printing trimming pattern for all reads passing the set threshold values...\n")
 	
 	for line in qual:
 		read_number += 1                ### this keeps track of the read order, respected between the prb and seq files
@@ -156,7 +156,7 @@ def parseQualFile(threshold, difference,
  		if head_match != None:
 			ok_read += 1
 			col = head_match.span()
-                        if not trim_info.has_key(read_number):
+                        if read_number not in trim_info:
                                 trim_info[read_number] = {}
 
 			start = int(col[0])	
@@ -167,7 +167,7 @@ def parseQualFile(threshold, difference,
 
 			if verbose:
 				sub = concat[trim_info[read_number]['start']:trim_info[read_number]['end']]
-				print "passed seqs:%i line#%i %s (start trim:%i,length:%i) %s\n" % (ok_read, read_number, concat, start, end, sub)
+				print("passed seqs:%i line#%i %s (start trim:%i,length:%i) %s\n" % (ok_read, read_number, concat, start, end, sub))
 
 	LOG.write("%i out of %i sequences passed your filter (I >= %i and D >= %i and L >= %i)\n" % (ok_read, read_number, threshold, difference, consecutive))
 
@@ -191,7 +191,7 @@ def readNTrim(trim_info, seq, verbose, F
 	gDNAlinker2_field = re.compile('^ATCTAACAG')	
 
 	if verbose:
-		print "Printing trimmed sequences for all reads passing the set threshold values minus, excluding sequence containing linkers...\n"
+		print("Printing trimmed sequences for all reads passing the set threshold values minus, excluding sequence containing linkers...\n")
 
         for line in seq:
 		read_number += 1            ### tracks read number / will match order in prb file
@@ -199,7 +199,7 @@ def readNTrim(trim_info, seq, verbose, F
 		info = line.split("\t")     ### split line, the seq file lists: lane tile xcoord y coord DNAseq 
 		dna_string = info[4]
 	
-		if trim_info.has_key(read_number):
+		if read_number in trim_info:
 			trim_seq = dna_string[trim_info[read_number]['start']:trim_info[read_number]['end']]
 			if re.match(dna_sequence_field, trim_seq):		### no ambiguous bases?
 				if re.match(gDNAlinker1_field, trim_seq) or re.match(gDNAlinker2_field,trim_seq):	### matches gDNA linker?
@@ -208,7 +208,7 @@ def readNTrim(trim_info, seq, verbose, F
 					usable_reads += 1
 					FASTA.write(">%s-%s-%s-%s\n%s\n" % (info[0],info[1],info[2],info[3],trim_seq))
 					if verbose:
-						print "line#%i %s (start trim:%i,length:%i) %s" % (read_number,info[4],trim_info[read_number]['start'],trim_info[read_number]['end'],trim_seq)
+						print("line#%i %s (start trim:%i,length:%i) %s" % (read_number,info[4],trim_info[read_number]['start'],trim_info[read_number]['end'],trim_seq))
 	LOG.write("%i out of %i sequences appear to be usable, after filtering out sequences hard-coded in this program * %i gDNA linker sequences*\n" % (usable_reads, read_number,gDNAlinker_count))
 	return
 
--- a/tools/TQS.readme
+++ b/tools/TQS.readme
@@ -24,12 +24,12 @@ __version__ = '1.0'
 
 Execution example
 ==================
-python TQS.py -f test_seq.txt -q test_prb.txt -l 36 -t 5 -d 5 -c 20
+python3 TQS.py -f test_seq.txt -q test_prb.txt -l 36 -t 5 -d 5 -c 20
 
 
 Options
 =======
-python TQS.py --help
+python3 TQS.py --help
 
 Usage: TQS.py [options]
 
--- a/tools/TQSexport.py
+++ b/tools/TQSexport.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/python3
 
 __doc__ = """
 TQS
@@ -47,9 +47,9 @@ def main():
 		f = open(opts.exportfile)
 		seq = f.readlines()
 		f.close()
-	except Exception, e:
-		print "ERROR: Could not read from %s: %s" % (opts.exportfile, e)
-		print usage % (sys.argv[0:])
+	except Exception as e:
+		print("ERROR: Could not read from %s: %s" % (opts.exportfile, e))
+		print(usage % (sys.argv[0:]))
 		sys.exit()
 
 
@@ -61,17 +61,17 @@ def main():
         try:
                 FASTA = open(fasta, 'w')
         except:
-                print "ERROR: Can not write to %s" % fasta
+                print("ERROR: Can not write to %s" % fasta)
                 sys.exit()
 
 	try:
 		LOG = open(log, 'w')
 	except:
-		print "ERROR: Can not write to %s" % log
+		print("ERROR: Can not write to %s" % log)
 		sys.exit()
 	
 	if opts.consec < minimum_length:
-		print "ERROR: -c must be a number larger than %i." % (minimum_length)
+		print("ERROR: -c must be a number larger than %i." % (minimum_length))
 		sys.exit()
 
 	LOG.write("""
@@ -106,7 +106,7 @@ YYYYRYYYYYYYYYYYTTTTTOOOMOOOMMOOOOOG	chr
 	read_number = 0
 
 	if verbose:
-		print "Printing trimming pattern for all reads passing the set threshold values...\n"
+		print("Printing trimming pattern for all reads passing the set threshold values...\n")
 	
 	for line in export:
 		read_number += 1
@@ -134,7 +134,7 @@ YYYYRYYYYYYYYYYYTTTTTOOOMOOOMMOOOOOG	chr
  		if head_match != None:
 			ok_read += 1
 			col = head_match.span()
-                        if not trim_info.has_key(read_number):
+                        if read_number not in trim_info:
                                 trim_info[read_number] = {}
 
 			start = int(col[0])	
@@ -150,7 +150,7 @@ YYYYRYYYYYYYYYYYTTTTTOOOMOOOMMOOOOOG	chr
                         FASTA.write(">%s-%s-%s-%s%s\n%s\n" % (info[1],info[2],info[3],info[4],pair,trim_seq))
 
 			if verbose:
-				print "passed seqs:%i line#%i %s (start trim:%i,end trim:%i) %s\n" % (ok_read, read_number, concat, start, end, trim_seq)
+				print("passed seqs:%i line#%i %s (start trim:%i,end trim:%i) %s\n" % (ok_read, read_number, concat, start, end, trim_seq))
 
 	LOG.write("%i out of %i sequences passed your filter (-t >= %i and -c >= %i)\n" % (ok_read, read_number, threshold, consecutive))
 
--- a/tools/TQSfastq.py
+++ b/tools/TQSfastq.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/python3
 
 __doc__ = """
 TQS
@@ -52,9 +52,9 @@ def main():
 		f = open(opts.fastqfile)
 		seq = f.readlines()
 		f.close()
-	except Exception, e:
-		print "ERROR: Could not read from %s: %s" % (opts.fastqfile, e)
-		print usage % (sys.argv[0:])
+	except Exception as e:
+		print("ERROR: Could not read from %s: %s" % (opts.fastqfile, e))
+		print(usage % (sys.argv[0:]))
 		sys.exit()
 
 
@@ -66,21 +66,21 @@ def main():
         try:
                 FASTA = open(fasta, 'w')
         except:
-                print "ERROR: Can not write to %s" % fasta
+                print("ERROR: Can not write to %s" % fasta)
                 sys.exit()
 
 	try:
 		LOG = open(log, 'w')
 	except:
-		print "ERROR: Can not write to %s" % log
+		print("ERROR: Can not write to %s" % log)
 		sys.exit()
 	
 	if opts.consec < minimum_length:
-		print "ERROR: -c must be a number larger than %i." % (minimum_length)
+		print("ERROR: -c must be a number larger than %i." % (minimum_length))
 		sys.exit()
 
         if opts.encoding != 33 and opts.encoding != 64:
-                print "ERROR: -e must be either 33 or 64."
+                print("ERROR: -e must be either 33 or 64.")
                 sys.exit()
 
 	LOG.write("""
@@ -114,7 +114,7 @@ def readNtrim(fastq, threshold, consecut
 	record_line = 0
 	
 	if verbose:
-		print "Printing trimming pattern for all reads passing the set threshold values...\n"
+		print("Printing trimming pattern for all reads passing the set threshold values...\n")
 	
 	for line in fastq:
 		record_line += 1
@@ -150,7 +150,7 @@ def readNtrim(fastq, threshold, consecut
 	 		if head_match != None:
 				ok_read += 1
 				col = head_match.span()
-	                        if not trim_info.has_key(read_number):
+	                        if read_number not in trim_info:
 	                                trim_info[read_number] = {}
 	
 				start = int(col[0])	
@@ -160,7 +160,7 @@ def readNtrim(fastq, threshold, consecut
 	                        FASTA.write(">%s\n%s\n" % (read_id, trim_seq))
 	
 				if verbose:
-					print "%s\n%s\n%s\n passed seqs:%i line#%i %s (start trim:%i,end trim:%i) %s\n" % (read_id,seq,qual,ok_read, read_number, concat, start, end, trim_seq)
+					print("%s\n%s\n%s\n passed seqs:%i line#%i %s (start trim:%i,end trim:%i) %s\n" % (read_id,seq,qual,ok_read, read_number, concat, start, end, trim_seq))
 
 	LOG.write("%i out of %i sequences passed your filter (-t >= %i and -c >= %i)\n" % (ok_read, read_number, threshold, consecutive))
 
