From c0fbe1f8b1ad14a33c59c3e943b7bb018eef0d2e Mon Sep 17 00:00:00 2001 From: hbyang Date: Fri, 11 May 2018 14:23:02 +0800 Subject: [PATCH] Fix a bug in lookup --- decode.py | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/decode.py b/decode.py index 91b0490..3a542d7 100644 --- a/decode.py +++ b/decode.py @@ -62,17 +62,17 @@ def read_building_block_sequence(filename): try: (seq, mol, cyc) = (col[0], col[1], col[2]) except: - print "[Error] expecting 3 columns for each line: " - print "[Error] line %d: %s" % (linenumber, line) + print("[Error] expecting 3 columns for each line: ") + print("[Error] line %d: %s" % (linenumber, line)) sys.exit(1) if not cyc in mapobj: mapobj[cyc] = {} if seq in mapobj[cyc]: - print "[Error] identical sequence already assigned to a building block %s for cycle %s" % ( - mapobj[cyc][seq], cyc) - print "[Error] line %d: %s" % (linenumber, line) + print("[Error] identical sequence already assigned to a building block %s for cycle %s" % ( + mapobj[cyc][seq], cyc)) + print("[Error] line %d: %s" % (linenumber, line)) sys.exit(2) else: mapobj[cyc][seq] = mol @@ -102,7 +102,7 @@ def lookup(seq): if numrs > 0: blockId.append(m.group('rnd')) except: - return [] + blockId = [] return blockId @@ -152,14 +152,14 @@ def lookup(seq): message += "regex= %s\n" % scheme message += "number of building blocks= %d\n" % numbb message += "number of random seq. blocks= %d\n" % numrs -print message +print(message) logfile.write(message + "\n") """ read building block sequence info. """ BBTag = read_building_block_sequence(options.bbseq) message = "Reading building blocks from '%s'\n" % options.bbseq -print message +print(message) logfile.write(message + "\n") @@ -171,7 +171,7 @@ def lookup(seq): for i in range(1, numbb + 1): Count[fileIdx][i]= {} CountSum[fileIdx][i]= {} - for j in combinations(range(1, numbb + 1), i): + for j in combinations(list(range(1, numbb + 1)), i): classId= ''.join(map(str, j)) Count[fileIdx][i][classId]= {} CountSum[fileIdx][i][classId]= 0 @@ -194,16 +194,14 @@ def lookup(seq): blockId = lookup(raw) if not blockId and options.revcomp : # try again blockId = lookup(revcomp(raw)) - if not blockId: - continue - else: + if not blockId: continue success += 1 # store blockId for i in range(1, numbb + 1): - for j in combinations(range(1, numbb + 1), i): + for j in combinations(list(range(1, numbb + 1)), i): classId = ''.join(map(str, j)) combiId = [] for k in j: @@ -227,20 +225,20 @@ def lookup(seq): Unique[fileIdx][combiId]['set'] = {randomSeq} message += "number of seq.= %d (success= %d)\n" % (reading, success) - print message + print(message) logfile.write(message + "\n") """ write out csv output """ message = "Writing sequence counts" -print message +print(message) logfile.write(message + "\n") for i in range(1, numbb + 1): - for j in combinations(range(1, numbb + 1), i): + for j in combinations(list(range(1, numbb + 1)), i): classId = ''.join(map(str, j)) filename = options.prefix + '_' + classId + '.csv' csvfile = open(filename, 'w') - print filename + print(filename) logfile.write(filename + "\n") # For a given classId, @@ -298,7 +296,7 @@ def lookup(seq): filename = options.prefix + '_unique.csv' csvfile = open(filename, 'w') message = "\nWriting sequence uniqueness to '%s'" % filename -print message +print(message) logfile.write(message + "\n") csvout = csv.writer(csvfile, delimiter=',', quotechar='"', ) @@ -320,4 +318,4 @@ def lookup(seq): row.extend([unique, total, float(unique) / float(total)]) else: row.extend([0, 0, 0]) - csvout.writerow(row) \ No newline at end of file + csvout.writerow(row)