-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautostaple-test.lisp
357 lines (256 loc) · 11.2 KB
/
autostaple-test.lisp
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
(in-package :small)
;; ==========================Helper functions =====================================
(defparameter *antiparallel-angle* pi "Variable that defines the minimum angle in radians for two helices to be considered antiparallel")
(defparameter *antiparallel-dotproduct* -0.99 "Variable that defines a number that the dot product between two vectors should be LESS THAN OR EQUAL TO to be considered antiparallel")
(defparameter *cutoff-dist* 2.0 "Distance in nm that nts must be within to be considered as a crossover point")
(defun antiparallelp (strand1 strand2)
"Returns t if strands are antiparallel. Antiparallel means dot-product between the first nts vn <= *antiparallel-dotproduct*"
(<= (dotproduct (vn (5nt strand1))
(vn (5nt strand2)))
*antiparallel-dotproduct*))
;; ==============================================================================
(defun get-antiparallel-strands (strand others)
"strand: DNA-HELIX-STRAND
others: (list DNA-HELIX-STRAND)
Returns a list of all DNA strands in others that are antiparallel to strand by antiparallelp
"
(remove nil
(mapcar #'(lambda (x)
(when (antiparallelp strand x)
x))
others)))
(defun unique-antiparallel-partners (strands)
"Recursively looks through strands to find and group all antiparallel strands
Returns: (list DNA-HELIX-STRAND (list antiparallel-parter[DNA-HELIX-STRAND] ...))n
Importantly nth strand in strands partner strands will not include DNA-HELIX-STRAND [0,(n-1)] in strands. This allows us not to generate double crossovers when traversing this list"
(when (cdr strands)
(cons (list (car strands)
(get-antiparallel-strands (car strands)
(cdr strands)))
(unique-antiparallel-partners (cdr strands)))))
;; (defun staple-crossovers (strand strands)
;; "Returns all the crossovers between helices TODO as what?"
;; (mapcar #'(lambda (s)
;; )
;; )
;; (defun all-potential-crossovers (strands &key (cutoff-dist *cutoff-dist*))
;; "strands is a list of DNA-HELIX-STRANDS
;; Returns a list of CROSSOVERs will have distances between them <= cutoff-dist"
;; ;; 3: remove crossovers if > cutoff-dist
;; ;; 1: Recurse through strands to get all potential antiparallel partners (list (list hel-in-1-dir all-antiparallel-helices))
;; (let* ((antiparallel-groups (unique-antiparallel-partners strands))
;; ;; 2: double mapcar (over cdrs for second) for each car of potential antiparallel and create all possible crossovers
;; (crossovers (mapcar #'(lambda (antiparallel-group)
;; ;; First entry of the nested list returned by unique-antiparallel-partners is the strand and the second is a nested list of partner strands"
;; (mapcar #'(lambda (partner-strand)
;; (strand-crossovers (car antiparallel-group)
;; partner-strand
;; :cutoff-dist cutoff-dist)
;; ;; (break partner-strand)
;; )
;; (second antiparallel-group)))
;; antiparallel-groups)))
;; crossovers))
(defun all-potential-crossovers (strands &key (cutoff-dist *cutoff-dist*))
"strands is a list of DNA-HELIX-STRANDS
Returns : (list (list CROSSOVER [1,n]) will have distances between them <= cutoff-dist. If one nt has more potential crossovers the returned as a list includes all af them"
;; 3: remove crossovers if > cutoff-dist
;; 1: Recurse through strands to get all potential antiparallel partners (list (list hel-in-1-dir all-antiparallel-helices))
(let* ((antiparallel-groups (unique-antiparallel-partners strands))
;; 2: double mapcar (over cdrs for second) for each car of potential antiparallel and create all possible crossovers
(crossovers (mapcar #'(lambda (antiparallel-group)
;; First entry of the nested list returned by unique-antiparallel-partners is the strand and the second is a nested list of partner strands"
(make-crossovers (first antiparallel-group)
(second antiparallel-group)))
antiparallel-groups)))
(reduce #'append crossovers)))
pc
(all-potential-crossovers s)
(mapcar #'find-best-crossover
(reduce #'append pc))
(length
(mapcar #'find-best-crossover
(reduce #'append pc)))
(length (resolve-conflicting-crossovers
(mapcar #'find-best-crossover
(reduce #'append pc))
(all-conflicting-crossovers
(mapcar #'find-best-crossover
(reduce #'append pc)))))
(wmdna "all-crossovers" s
(mapcar #'(lambda (c)
(list (make-partner (nt1 c))
(make-partner (nt2 c))))
(resolve-conflicting-crossovers
(mapcar #'find-best-crossover
(reduce #'append pc))
(all-conflicting-crossovers
(mapcar #'find-best-crossover
(reduce #'append pc))))))
(resolve-conflicting-crossovers
(mapcar #'find-best-crossover
(reduce #'append pc))
(all-conflicting-crossovers
(mapcar #'find-best-crossover
(reduce #'append pc))))
(unique-antiparallel-partners s)
(reduce #'append (remove-all-nils pc))
(flatten (remove-all-nils pc))
(remove-all-nils
(map nil #'(lambda (pt)
(strand-crossovers (first (first (unique-antiparallel-partners s)))
pt))
(second (first (unique-antiparallel-partners s)))))
(make-crossovers (first (first (unique-antiparallel-partners s)))
(second (first (unique-antiparallel-partners s))))
(reduce #'append
(mapcar #'(lambda (pt)
(strand-crossovers (first (first (unique-antiparallel-partners s)))
pt))
(second (first (unique-antiparallel-partners s)))))
(append '(1) '(2) nil '(3))
(mapcar #'(lambda (partner-strand)
(strand-crossovers (first (first (unique-antiparallel-partners s)))
partner-strand
:cutoff-dist *cutoff-dist*))
(second (first (unique-antiparallel-partners s))))
(mapcar #'(lambda ()
)
(second (unique-antiparallel-partners s)))
)
(second (first (unique-antiparallel-partners s)))
(all-conflicting (remove-all-nils pc))
;;;; ==========================Scratch Area========================
;; Testing antiparallel
;; 1
(progn
(setf l (make-instance 'dna-square-lattice)
s (scaffold l)
cross (remove-nilr (strand-crossovers (first s) (second s)))
fc (flatten cross)
bc (mapcar #'find-best-crossover
(remove-nilr cross))
pc (all-potential-crossovers s)))
(remove-all-nils pc)
(length s)
(length (antiparallel-strands (car s) (cdr s)))
(wmdna "antiparallel" (first s) (get-antiparallel-strands (car (scaffold l)) (cdr (scaffold l))))
;; 2
(dolist (x (unique-antiparallel-partners s) )
(format t "~& ~A ~%" (length (second x))))
;;; Testing crossover creation
(1Dp (planarp (caar (remove-nilr (strand-crossovers
(first s)
(second s)
:cutoff-dist 2)))))
(mapcar #'(lambda (x)
(planarp x)
)
(flatten (remove-nilr (strand-crossovers (first s) (second s)))))
(mapcar #'(lambda (x)
(1Dp (planarp x))
)
(flatten (remove-nilr (strand-crossovers (first s) (second s)))))
(remove-nilr (strand-crossovers
(first s)
(second s)
:cutoff-dist 2))
(mapcar #'(lambda (x)
(bbdot x)
)
(flatten (remove-nilr (strand-crossovers (first s) (second s)))))
(mapcar #'(lambda (x)
(rad->deg (bbangle x))
)
(flatten (remove-nilr (strand-crossovers
(first s)
(second s)
:cutoff-dist 2))))
(remove-nilr (strand-crossovers (first s) (second s)))
(wmdna "crossovers" (first s) (second s)
(mapcar #'(lambda (c)
(list (make-partner (nt1 c))
(make-partner (nt2 c)))
)
(alexandria:flatten (remove-nilr (strand-crossovers
(first s)
(second s)
:cutoff-dist 1.9)))))
(wmdna "crossovers-best" (first s) (second s)
(mapcar #'(lambda (c)
(list (make-partner (nt1 c))
(make-partner (nt2 c)))
)
(mapcar #'find-best-crossover
(remove-nilr (strand-crossovers (first s) (second s))))))
;; Check best crossover
(mapcar #'find-best-crossover
(remove-nilr (strand-crossovers (first s) (second s))))
;; check conflicting
(conflictingp (third (mapcar #'find-best-crossover
(remove-nilr (strand-crossovers (first s) (second s)))))
(second (mapcar #'find-best-crossover
(remove-nilr (strand-crossovers (first s) (second s))))))
(conflictingp (first (mapcar #'find-best-crossover
(remove-nilr (strand-crossovers (first s) (second s)))))
(second (mapcar #'find-best-crossover
(remove-nilr (strand-crossovers (first s) (second s))))))
(set-difference bc (flatten (mapcar #'worst-crossovers (all-conflicting-crossovers bc))))
(flatten (mapcar #'worst-crossovers (all-conflicting-crossovers bc)))
(flatten (mapcar #'find-best-crossover (all-conflicting-crossovers bc)))
(intersection bc (flatten (mapcar #'worst-crossovers (all-conflicting-crossovers bc)))
(remove-nilr (all-conflicting-crossovers bc))
(find-best-crossover (second cross))
(worst-crossovers (second cross))
(length fc)
;; We run into issues with double crossover generation both when the scaffold strand has two potential targets (here we select the best) or when the scaffold strand has a potetial target DNA-NT for the CORRECT staple that +1 or -1 from the correct target DNA-NT on the scaffold strand.
(wmdna "conflict-1" (first s) (second s)
(mapcar #'(lambda (c)
(list (make-partner (nt1 c))
(make-partner (nt2 c)))
)
(list (first (second cross)))))
(wmdna "conflict-solved" (first s) (second s)
(mapcar #'(lambda (c)
(list (make-partner (nt1 c))
(make-partner (nt2 c)))
)
(set-difference bc (flatten (mapcar #'worst-crossovers (all-conflicting-crossovers bc))))))
(wmdna "conflicts-worst" (first s) (second s)
(mapcar #'(lambda (c)
(list (make-partner (nt1 c))
(make-partner (nt2 c)))
)
(intersection bc
(flatten
(mapcar #'worst-crossovers (all-conflicting-crossovers bc))))))
(find-best-crossover (second cross))
(length (mapcar #'(lambda (c)
(list (make-partner (nt1 c))
(make-partner (nt2 c)))
)
(alexandria:flatten (remove-nilr (strand-crossovers (first s) (second s) :cutoff-dist 1.9)))))
(mapcar #'find-best-crossovernnn
(remove-nilr (strand-crossovers (first s) (second s))))
(length (remove-nilr (strand-crossovers (first s) (second s))))
(wmdna "conflicts-resolved" (first s) (second s)
(mapcar #'(lambda (c)
(list (make-partner (nt1 c))
(make-partner (nt2 c))))
(resolve-conflicting-crossovers
cross
(all-conflicting-crossovers bc))))
;;=========================== Unimplemented ===========================================================
(defun within-x (x crossover nts)
"Returns t if crossover is within x nts from any nt in nts")
(defun filter-crossovers (nts crossovers &key pts)
"nts: (list DNA-NT)
crossovers: (list CROSSOVER)
Take a list of crossovers and nts and returns a new list without any crossover that have a nt in nts as one of their nt slot. if :pts=t only if the nt in nts are in the CROSSOVERs pt1/2 slot are they removed")
(defun make-staples (scaffold-nts crossovers)
;; 1: Get all applicable crossovers
;; 2: traverse by atleast min-helix-length then choose next pt-pair branch if we cross a disallowed nt, stop strand creation, return whole strand if >= min-length, else error
;; keep track of crossed pt-pairs
; 3: if (intersection crossed-pt-pairs all-pt-pairs) is the empty set continue else repeat the process for next nt from 3' end of the scaffold that doesnt have a partner and isnt disallowed
n
)