Skip to content

Commit 50f6717

Browse files
committed
Merge pull request #1 from scholer/master
Small fixes.
2 parents 1048b86 + 63a7db8 commit 50f6717

File tree

2 files changed

+104
-113
lines changed

2 files changed

+104
-113
lines changed

assign_sequences.py

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77

88
import sys
99
import pickle
10-
import copy
10+
import copy # !! Not used
1111
import json
1212

13+
## !! DEFINE MODULE LEVEL CONSTANTS AT THE TOP.
14+
1315
def load_json(file_name, period=32):
1416
"""
1517
Loads a .json file in the correct way, so it can still be read by cadnano2.
@@ -20,7 +22,7 @@ def load_json(file_name, period=32):
2022
The name and location of the *.json file
2123
period : int
2224
The period of repeating segments of the staples, in the square lattice this is by default 32.
23-
25+
2426
Returns
2527
-------
2628
data : list
@@ -34,15 +36,15 @@ def load_json(file_name, period=32):
3436
idx : dict
3537
polarity
3638
period
37-
39+
3840
Example
3941
-------
4042
data, vstrands, num_helices, num_bases, idx, polarity, per = load_json('ruler_design_12nov_1353.json')
4143
"""
4244
with open(file_name) as f:
4345
data = json.load(f)
44-
45-
vstrands = data['vstrands']
46+
47+
vstrands = data['vstrands'] # !! vstrands also in outer script.
4648
num_helices = len(vstrands)
4749
num_bases = len(vstrands[0]['scaf'])
4850
idx = {} #Generate dictionary for translating helix_num to vstrand_num
@@ -61,7 +63,7 @@ def save_json(file_name):
6163
file_name : str
6264
The name and location of the *.json file
6365
"""
64-
data['vstrands'] = vstrands
66+
data['vstrands'] = vstrands # !! Accessing global variables
6567
with open(file_name, 'wb') as outfile:
6668
json.dump(data, outfile)
6769

@@ -79,17 +81,18 @@ def comp_seq_FN(raw_sequence):
7981
return antisense_seq
8082

8183
def stap_color_string_FN(stap_color_int):
82-
return color_dc[stap_color_int]
84+
return color_dc[stap_color_int] # !! Accessing global variables
8385

8486
def initVars():
8587
"""
8688
Initialization of variables, gives the colors a name and initiates the null_bp
87-
89+
8890
Example
8991
-------
9092
stap_color_dc, null_bp = initVars()
9193
"""
92-
null_bp = [-1, -1]
94+
null_bp = [-1, -1] # !! Redefining global variables
95+
# Do this in a single statement:
9396
stap_color_dc = {}
9497
stap_color_dc[13369344] = 'red'
9598
stap_color_dc[16204552] = 'red orange'
@@ -107,14 +110,14 @@ def initVars():
107110

108111
def openPickledFile(f):
109112
""" Loads a pickled file """
110-
input_file = file(f, 'r')
113+
input_file = file(f, 'r') # DONT USE file() !!
111114
loaded_txt = pickle.load(input_file)
112115
input_file.close()
113116
return loaded_txt
114117

115118
def openFile(f):
116119
"""" Opens a txt file in standard format. """
117-
input_file = file(f, 'r')
120+
input_file = file(f, 'r') # DONT USE file() !!
118121
loaded_txt = input_file.read()
119122
input_file.close()
120123
return loaded_txt
@@ -240,7 +243,7 @@ def give_sequences(cadnano_file):
240243
return scaf_output_ra, sorted_stap_output_ra, vstrands
241244

242245
def print_sequences():
243-
print
246+
print
244247
print
245248
#Print sorted staple strand sequences with annotations
246249
for sub_ra in sorted_stap_output_ra:
@@ -256,7 +259,7 @@ def print_sequences():
256259
note = ' short scaf strand\t' + str(sub_ra[0]) + 'mer\t' + str(sub_ra[1]) + '\t' + 'start\t' + str(sub_ra[2]) + '\t' + 'end'
257260
seq_note = seq + '\t' + note
258261
print seq_note
259-
262+
260263
#Print additional miscellaneous information
261264
num_stap_bases = 0
262265
for sub_ra in sorted_stap_output_ra:
@@ -303,13 +306,12 @@ def print_sequences():
303306
eight_mers = openPickledFile('141110_1628_ortho_8mers_2303.txt')
304307
handle_color = {'cyan' : [0, 5], 'blue' : [1, 6], 'red orange' : [2, 7], 'light gray' : [3, 8], 'magenta' : [4, 9]}
305308

306-
for color in handle_color:
307-
for i in range(len(sorted_stap_output_ra)):
308-
if sorted_stap_output_ra[i][0] == color:
309-
if sorted_stap_output_ra[i][3][0] == 0:
310-
sorted_stap_output_ra[i][-1] += 'TT' + eight_mers[handle_color[color][0]]
311-
if sorted_stap_output_ra[i][3][0] == 1:
312-
sorted_stap_output_ra[i][-1] += 'TT' + eight_mers[handle_color[color][1]]
309+
for color, seqidx in handle_color.items():
310+
for row in sorted_stap_output_ra:
311+
if row[0] == color and row[3][0] in (0, 1):
312+
# Add 'TT' to staple seq:
313+
row[-1] += 'TT' + eight_mers[seqidx[row[3][0]]]
314+
313315
print_sequences()
314316

315317

@@ -323,15 +325,12 @@ def print_sequences():
323325

324326
print "before adding handles"
325327
# print_sequences()
328+
helix_to_handle_seq_idx = {16: 0, 18: 1}
329+
for end_num, seqidx in handle_color.items():
330+
for row in sorted_stap_output_ra:
331+
# row[3] is cadnano_start coordinate (helix, basenum), e.g. [2, 200]
332+
if row[3][1] == end_num and row[3][0] in (16, 18):
333+
row[-1] += 'TTTT' + comp_seq_FN(eight_mers[seqidx[0 if row[3][0] == 16 else 1]])
326334

327-
for end_num in handle_color:
328-
for i in range(len(sorted_stap_output_ra)):
329-
if sorted_stap_output_ra[i][3][1] == end_num:
330-
if sorted_stap_output_ra[i][3][0] == 16:
331-
sorted_stap_output_ra[i][-1] += 'TTTT' + comp_seq_FN(eight_mers[handle_color[end_num][0]])
332-
333-
if sorted_stap_output_ra[i][3][0] == 18:
334-
sorted_stap_output_ra[i][-1] += 'TTTT' + comp_seq_FN(eight_mers[handle_color[end_num][1]])
335335
print "after adding handles"
336336
print_sequences()
337-

0 commit comments

Comments
 (0)