-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
AlignDNA.frm
454 lines (390 loc) · 14.5 KB
/
AlignDNA.frm
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
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
VERSION 5.00
Begin VB.Form Form1
Caption = "Demo - Global sequence alignment in VB6"
ClientHeight = 12360
ClientLeft = 120
ClientTop = 450
ClientWidth = 12285
LinkTopic = "Form1"
ScaleHeight = 12360
ScaleWidth = 12285
StartUpPosition = 2 'CenterScreen
Begin VB.HScrollBar HScroll_mma
Height = 255
Left = 7920
Max = 20
Min = -20
TabIndex = 13
Top = 960
Value = -1
Width = 3015
End
Begin VB.HScrollBar HScroll_ma
Height = 255
Left = 7920
Max = 20
Min = -20
TabIndex = 12
Top = 600
Value = 6
Width = 3015
End
Begin VB.HScrollBar HScroll_Tgap
Height = 255
Left = 7920
Max = 20
Min = -20
TabIndex = 11
Top = 240
Value = -6
Width = 3015
End
Begin VB.TextBox mma
Alignment = 2 'Center
Height = 285
Left = 11040
TabIndex = 7
Text = "-1"
Top = 960
Width = 975
End
Begin VB.TextBox ma
Alignment = 2 'Center
Height = 285
Left = 11040
TabIndex = 5
Text = "6"
Top = 600
Width = 975
End
Begin VB.TextBox Tgap
Alignment = 2 'Center
Height = 285
Left = 11040
TabIndex = 3
Text = "-6"
Top = 240
Width = 975
End
Begin VB.TextBox result
BeginProperty Font
Name = "Lucida Console"
Size = 9
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 10095
Left = 240
MultiLine = -1 'True
ScrollBars = 3 'Both
TabIndex = 2
Top = 1440
Width = 11895
End
Begin VB.TextBox s2
BeginProperty Font
Name = "Lucida Console"
Size = 12
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 840
TabIndex = 1
Text = "GTTATTACCATTGA"
Top = 840
Width = 6015
End
Begin VB.TextBox s1
BeginProperty Font
Name = "Lucida Console"
Size = 12
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 840
TabIndex = 0
Text = "GTTTGCATGCTTG"
Top = 240
Width = 6015
End
Begin VB.Image Image1
Height = 720
Left = -12960
Picture = "AlignDNA.frx":0000
Top = 11640
Width = 25290
End
Begin VB.Label Label5
Caption = "Sq 2 ="
BeginProperty Font
Name = "MS Sans Serif"
Size = 9.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 240
TabIndex = 10
Top = 840
Width = 615
End
Begin VB.Label Label4
Caption = "Sq 1 ="
BeginProperty Font
Name = "MS Sans Serif"
Size = 9.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 240
TabIndex = 9
Top = 240
Width = 615
End
Begin VB.Label Label3
Caption = "MMatch ="
Height = 255
Left = 7080
TabIndex = 8
Top = 960
Width = 735
End
Begin VB.Label Label2
Caption = "Match ="
Height = 255
Left = 7080
TabIndex = 6
Top = 600
Width = 735
End
Begin VB.Label Label1
Caption = "Gap ="
Height = 255
Left = 7080
TabIndex = 4
Top = 240
Width = 735
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
' ________________________________ ____________________
' / Global sequence alignment \________________________/ v1.00 |
' | |
' | Name: Demo - Global sequence alignment V1.0 |
' | Category: Open source software |
' | Author: Paul A. Gagniuc |
' | Book: Algorithms in Bioinformatics: Theory and Implementation |
' | Email: paul_gagniuc@acad.ro |
' | ____________________________________________________________________________ |
' | |
' | Date Created: January 2014 |
' | Update: January 2021 |
' | Tested On: WinXP, WinVista, Win7, Win8, Win10 |
' | Use: sequence alignment |
' | |
' | _____________________________ |
' |_________________/ \_______________________________|
'
Dim Matrix() As Variant 'matrix of nucleotides
Dim MatrixTrace() As Variant 'matrix of path
Private Sub Align_Click()
result.Text = ""
gap = Val(Tgap.Text)
'------ Matrix(n,n) umplut cu caractere -----------------------------------
sq1 = Len(s1.Text)
sq2 = Len(s2.Text)
sp = 2
ReDim Matrix(0 To sq1 + sp, 0 To sq2 + sp) As Variant
ReDim MatrixTrace(0 To sq1 + sp, 0 To sq2 + sp) As Variant
Matrix(0, 0) = " "
Matrix(1, 0) = " "
Matrix(0, 1) = " "
MatrixTrace(0, 0) = " "
MatrixTrace(1, 0) = " "
MatrixTrace(0, 1) = " "
'------ Matrix(i,0) umplut cu s2 pe Row -----------------------------------
For i = 2 To sq1 + sp 'Rows
letter2 = Mid(s1.Text, i - 1, 1)
Matrix(i, 0) = letter2
MatrixTrace(i, 0) = letter2
Next i
'--------------------------------------------------------------------------
'------ Matrix(0,j) umplut cu s1 pe Col -----------------------------------
For j = 2 To sq2 + sp 'cols
letter1 = Mid(s2.Text, j - 1, 1)
Matrix(0, j) = letter1
MatrixTrace(0, j) = letter1
Next j
'--------------------------------------------------------------------------
'---- Fill Matrix Zero ----------------------------------------------------
For i = 1 To sq1 + 1
For j = 1 To sq2 + 1
Matrix(i, j) = 0
Next j
Next i
'--------------------------------------------------------------------------
'---- Fill Matrix Extremis ------------------------------------------------
For i = 1 To sq1
Matrix(i + 1, 1) = Matrix(i, 1) - 1
Next i
'--------------------------------------------------------------------------
'---- Fill Matrix Extremis ------------------------------------------------
For j = 1 To sq2
Matrix(1, j + 1) = Matrix(1, j) - 1
Next j
'--------------------------------------------------------------------------
'---- Fill Matrix ---------------------------------------------------------
For i = 2 To sq1 + 1 'Rows
letter2 = Mid(s2.Text, i - 1, 1)
For j = 2 To sq2 + 1 'Cols
If i > 1 And j > 1 Then
letter1 = Mid(s1.Text, j - 1, 1)
A = Val(Matrix(i - 1, j - 1)) + S(letter1, letter2) '\
B = Val(Matrix(i - 1, j)) + gap '-
C = Val(Matrix(i, j - 1)) + gap '|
Matrix(i, j) = VMAX(A, B, C)
End If
Next j
Next i
'--------------------------------------------------------------------------
'---- Read Path Matrix ---------------------------------------------------------
On Error GoTo 1
'On Error Resume Next
AlignmentA = ""
AlignmentM = ""
AlignmentB = ""
i = sq1 + 1 'Rows
j = sq2 + 1 'Cols
Do While (i >= 2 Or j >= 2)
Ai = Matrix(i, 0) 'Cols
Bj = Matrix(0, j) 'Rows
If (i >= 2 And j >= 2 And Matrix(i, j) = Val(Matrix(i - 1, j - 1)) + S(Ai, Bj)) Then
MatrixTrace(i, j) = Matrix(i - 1, j - 1) + S(Ai, Bj)
AlignmentA = Ai + AlignmentA
AlignmentB = Bj + AlignmentB
i = i - 1
j = j - 1
ElseIf (i >= 2 And Matrix(i, j) = Val(Matrix(i - 1, j)) + gap) Then
MatrixTrace(i, j) = Val(Matrix(i - 1, j)) + gap
AlignmentA = Ai + AlignmentA
AlignmentB = "-" + AlignmentB
i = i - 1
ElseIf (j >= 2) Then
MatrixTrace(i, j) = Val(Matrix(i, j - 1)) + gap
AlignmentA = "-" + AlignmentA
AlignmentB = Bj + AlignmentB
j = j - 1
Else
MatrixTrace(i, j) = Val(Matrix(i - 1, j)) + gap
AlignmentA = Ai + AlignmentA
AlignmentB = "-" + AlignmentB
i = i - 1
End If
If i <= 2 And j <= 2 Then MatrixTrace(i, j) = 0
Loop
'--------------------------------------------------------------------------
If sq1 > sq2 Then k = sq1 Else k = sq2
For i = 1 To k '- 1
l1 = Mid(AlignmentA, i, 1)
l2 = Mid(AlignmentB, i, 1)
If l1 = l2 Then AlignmentM = AlignmentM & "|" Else AlignmentM = AlignmentM & " "
Next i
'--------------------------------------------------------------------------
result.Text = result.Text & "Show alignment:" & vbCrLf & vbCrLf & AlignmentA & vbCrLf & AlignmentM & vbCrLf & AlignmentB & vbCrLf & vbCrLf
'------ Show TraceMatrix in Text OBJ --------------------------------------
Call DrowMatrix(sq1 + 1, sq2 + 1, MatrixTrace, "Plot Trace:")
'--------------------------------------------------------------------------
'------ Show Matrix in Text OBJ -------------------------------------------
Call DrowMatrix(sq1 + 1, sq2 + 1, Matrix, "Plot Matrix:")
'--------------------------------------------------------------------------
result.Text = result.Text & ct & vbCrLf
'--------------------------------------------------------------------------
Exit Sub
1:
MsgBox "Error!" & vbCrLf & "One of the parameters is inadequate for the given conditions !"
End Sub
Function S(a1, a2) As Variant
If a1 = a2 Then S = Val(ma.Text) Else S = Val(mma.Text)
End Function
Function VMAX(a1, a2, a3) As Variant
If a1 > a2 Then ctmp = a1 Else ctmp = a2
If ctmp > a3 Then VMAX = ctmp Else VMAX = a3
End Function
Function DrowMatrix(ib, jb, ByVal M As Variant, ByVal msg As String) As Variant
'------ Show Matrix in Text OBJ -------------------------------------------
For i = 0 To jb 'Cols
x = x & "_____"
Next i
ct = ct & vbCrLf & " " & x & vbCrLf
For i = 0 To ib 'Rows
For j = 0 To jb 'cols
If Len(M(i, j)) = 0 Then u = "| "
If Len(M(i, j)) = 1 Then u = "| "
If Len(M(i, j)) = 2 Then u = "| "
If Len(M(i, j)) = 3 Then u = "| "
If Len(M(i, j)) = 4 Then u = "|"
If j = jb Then o = "|" Else o = ""
ct = ct & u & M(i, j) & o
If i = 0 Then y = y & "|____" & o
Next j
ct = ct & vbCrLf & y & vbCrLf
Next i
'--------------------------------------------------------------------------
result.Text = result.Text & msg & vbCrLf & ct & vbCrLf
'--------------------------------------------------------------------------
End Function
Private Sub Form_Load()
Align_Click
End Sub
Private Sub HScroll_ma_Change()
ma.Text = HScroll_ma.Value
Align_Click
End Sub
Private Sub HScroll_ma_Scroll()
ma.Text = HScroll_ma.Value
Align_Click
End Sub
Private Sub HScroll_mma_Change()
mma.Text = HScroll_mma.Value
Align_Click
End Sub
Private Sub HScroll_mma_Scroll()
mma.Text = HScroll_mma.Value
Align_Click
End Sub
Private Sub HScroll_Tgap_Change()
Tgap.Text = HScroll_Tgap.Value
Align_Click
End Sub
Private Sub HScroll_Tgap_Scroll()
Tgap.Text = HScroll_Tgap.Value
Align_Click
End Sub
Private Sub s1_Change()
Align_Click
End Sub
Private Sub s2_Change()
Align_Click
End Sub