Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a bug in lookup #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 17 additions & 19 deletions decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: <sequence> <building-block-id> <cycle-number>"
print "[Error] line %d: %s" % (linenumber, line)
print("[Error] expecting 3 columns for each line: <sequence> <building-block-id> <cycle-number>")
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
Expand Down Expand Up @@ -102,7 +102,7 @@ def lookup(seq):
if numrs > 0:
blockId.append(m.group('rnd'))
except:
return []
blockId = []
return blockId


Expand Down Expand Up @@ -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")


Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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,
Expand Down Expand Up @@ -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='"', )

Expand All @@ -320,4 +318,4 @@ def lookup(seq):
row.extend([unique, total, float(unique) / float(total)])
else:
row.extend([0, 0, 0])
csvout.writerow(row)
csvout.writerow(row)