-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathmutate.f90
280 lines (206 loc) · 7.13 KB
/
mutate.f90
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
SUBROUTINE Find_Mut_Pot_Misprimes()
!
! This is a position dependent replacement for Find_Potential_Misprimes.
USE dnaworks_data
USE dnaworks_test
IMPLICIT NONE
INTEGER :: i,j,start,finish
LOGICAL,EXTERNAL :: HMatchNum
IF (TEST2) PRINT *,"Find_Mut_Pot_Misprimes" !TEST2
! Get rid of potential misprimes in the current mutant range
CALL Decrement_Misprime_Arrays
! Make sure the search doesn't go beyond the possible ranges
start=MAX(1,MutNtPos(1)-MPLn)
finish=MIN((MutNtPos(MutNtNum)+1),(DNAlen-MPLn+1))
! If MutNtPos(1) <= MPLn+1, only run the second half-search
IF (MutNtPos(1).gt.(MPLn+1)) THEN
! First half-search
DO i=1,MutNtPos(1)-MPLn-1
DO j=MutNtPos(1)-MPLn,finish
IF (HMatchNum(i,j,1)) THEN
IF (CurrDNA%ntID_Tip(i+MPLn-MPTip).eq.CurrDNA%ntID_Tip(j+MPLn-MPTip)) &
CALL Increment_Misprime_Arrays(i,j,1)
IF (CurrDNA%ntID_Tip(i).eq.CurrDNA%ntID_Tip(j)) &
CALL Increment_Misprime_Arrays(i,j,4)
END IF
IF (HMatchNum(i,j,-1)) THEN
IF (CurrDNA%ntID_Tip(i).eq.CurrDNA%ntID_TipRC(j+MPLn-MPTip)) &
CALL Increment_Misprime_Arrays(i,j,2)
IF (CurrDNA%ntID_Tip(i+MPLn-MPTip).eq.CurrDNA%ntID_TipRC(j)) &
CALL Increment_Misprime_Arrays(i,j,3)
END IF
END DO
END DO
END IF
! Second half-search
DO i=start,finish
DO j=i,DNAlen-MPLn+1
IF (HMatchNum(i,j,1)) THEN
IF (CurrDNA%ntID_Tip(i+MPLn-MPTip).eq.CurrDNA%ntID_Tip(j+MPLn-MPTip)) &
CALL Increment_Misprime_Arrays(i,j,1)
IF (CurrDNA%ntID_Tip(i).eq.CurrDNA%ntID_Tip(j)) &
CALL Increment_Misprime_Arrays(i,j,4)
END IF
IF (HMatchNum(i,j,-1)) THEN
IF (CurrDNA%ntID_Tip(i).eq.CurrDNA%ntID_TipRC(j+MPLn-MPTip)) &
CALL Increment_Misprime_Arrays(i,j,2)
IF (CurrDNA%ntID_Tip(i+MPLn-MPTip).eq.CurrDNA%ntID_TipRC(j)) &
CALL Increment_Misprime_Arrays(i,j,3)
END IF
END DO
END DO
CALL Sort_Misprime_Arrays
END SUBROUTINE Find_Mut_Pot_Misprimes
SUBROUTINE Find_Mutated_Repeats()
USE dnaworks_data
USE dnaworks_test
IMPLICIT NONE
INTEGER :: i,j,start,finish
LOGICAL,EXTERNAL :: PairWithinKnownRepeat
IF (TEST2) PRINT *,"Find_Mutated_Repeats" !TEST2
CALL Decrement_Repeat_Arrays
! Make sure the search doesn't go beyond the possible ranges
start=MAX(1,MutNtPos(1)-RepLen)
finish=MIN((MutNtPos(MutNtNum)+1),(DNAlen-RepLen+1))
! If MutNtPos(1) <= RepLen+1, only run the second half-search
IF (MutNtPos(1).gt.(RepLen+1)) THEN
! First half-search
DO i=1,(MutNtPos(1)-RepLen-1)
DO j=(MutNtPos(1)-RepLen),finish
! Direct repeat search
IF (i.ne.j) THEN
IF (.not.PairWithinKnownRepeat(i,j,1)) THEN
IF (CurrDNA%ntID_Rep(i).eq.CurrDNA%ntID_Rep(j)) &
CALL Increment_Repeat_Arrays(i,j,1)
END IF
END IF
! Inverse repeat search
IF (.not.PairWithinKnownRepeat(i,j,-1)) THEN
IF (CurrDNA%ntID_Rep(i).eq.CurrDNA%ntID_RepRC(j)) &
CALL Increment_Repeat_Arrays(i,j,-1)
END IF
END DO
END DO
END IF
! Second half-search
DO i=start,finish
DO j=i,DNAlen-RepLen+1
! Direct repeat search
IF (i.ne.j) THEN
IF (.not.PairWithinKnownRepeat(i,j,1)) THEN
IF (CurrDNA%ntID_Rep(i).eq.CurrDNA%ntID_Rep(j)) &
CALL Increment_Repeat_Arrays(i,j,1)
END IF
END IF
! Inverse repeat search
IF (.not.PairWithinKnownRepeat(i,j,-1)) THEN
IF (CurrDNA%ntID_Rep(i).eq.CurrDNA%ntID_RepRC(j)) &
CALL Increment_Repeat_Arrays(i,j,-1)
END IF
END DO
END DO
CALL Sort_Repeat_Arrays
END SUBROUTINE Find_Mutated_Repeats
SUBROUTINE Mutate_Sequence
!
! Mutate a single codon to an alternate codon. The residue choice is
! determined in Mutate_Wheel, and the codon choice is made here.
USE dnaworks_data
USE dnaworks_test
IMPLICIT NONE
INTEGER :: i,j,choice
INTEGER :: AAN ! amino acid choice (1-21)
! INTEGER :: refCN ! old codon number (1-64)
INTEGER :: i1,i2,i3 ! nt positions of choice
REAL :: rand
! CHARACTER(LEN=3) :: refCOD ! old codon sequence
IF (TEST1) PRINT *,"Mutate_Sequence"
! Generate XScores
CALL Equalize_Scores
! Determine position to mutate
CALL Mutate_Wheel
! Determine what amino acid exists at the selected residue MutProtPos.
! AAN is a number between 1 and 21, corresponding to a specific amino acid
AAN=prot2aa(MutProtPos)
! Determine the nt positions and the actual codon sequence for that residue
i1=prot2nt(MutProtPos)-1
i2=prot2nt(MutProtPos)
i3=prot2nt(MutProtPos)+1
!
! randomly choose codon and make sure it's different and available for that AAN
IF (AAT(AAN)%NumOfActiveCodons.eq.2) THEN
choice=1
IF (AAT(AAN)%Codon(choice).eq.CurrDNA%prot2cod(MutProtPos)) choice=2
ELSE
choose: DO i=1,1000
CALL RANDOM_NUMBER(rand)
choice=(INT(rand*(AAT(AAN)%NumOfActiveCodons)))+1
IF (AAT(AAN)%Codon(choice).ne.CurrDNA%prot2cod(MutProtPos)) EXIT choose
END DO choose
END IF
! update the arrays and change the DNA sequence, then quit
CurrDNA%prot2cod(MutProtPos)=AAT(AAN)%Codon(choice)
CurrDNA%nt2cod(i2) = AAT(AAN)%Codon(choice)
IF (ChainReverse(prot2chain(MutProtPos))) THEN
CurrDNA%DNAseq(i1:i3)=CFT(AAT(AAN)%Codon(choice))%SeqRC
CurrDNA%NUMseq(i1)=CFT(AAT(AAN)%Codon(choice))%numRC(1)
CurrDNA%NUMseq(i2)=CFT(AAT(AAN)%Codon(choice))%numRC(2)
CurrDNA%NUMseq(i3)=CFT(AAT(AAN)%Codon(choice))%numRC(3)
ELSE
CurrDNA%DNAseq(i1:i3)=CFT(AAT(AAN)%Codon(choice))%Seq
CurrDNA%NUMseq(i1)=CFT(AAT(AAN)%Codon(choice))%num(1)
CurrDNA%NUMseq(i2)=CFT(AAT(AAN)%Codon(choice))%num(2)
CurrDNA%NUMseq(i3)=CFT(AAT(AAN)%Codon(choice))%num(3)
END IF
! Set the MutNtPos values
MutNtNum=0
MutNtPos(1)=0
MutNtPos(2)=0
MutNtPos(3)=0
IF (CurrDNA%NUMseq(i1).ne.StoreDNA%NUMseq(i1)) THEN
MutNtNum=MutNtNum+1
MutNtPos(MutNtNum)=i1
END IF
IF (CurrDNA%NUMseq(i2).ne.StoreDNA%NUMseq(i2)) THEN
MutNtNum=MutNtNum+1
MutNtPos(MutNtNum)=i2
END IF
IF (CurrDNA%NUMseq(i3).ne.StoreDNA%NUMseq(i3)) THEN
MutNtNum=MutNtNum+1
MutNtPos(MutNtNum)=i3
END IF
SequenceTranslated=.TRUE.
END SUBROUTINE Mutate_Sequence
SUBROUTINE Mutate_Wheel
!
! Choose a position to mutate based on the score of mutatable codons
USE dnaworks_data
USE dnaworks_test
IMPLICIT NONE
INTEGER :: i,j,k
REAL :: rand
REAL :: ZScore(3333) ! an accumulated codon-based overall score
REAL :: choice
IF (TEST1) PRINT *,"Mutate_Wheel"
! Generate ZScore array
ZScore(1)=XScore(1)
! If there are more than one codon to be mutated,
IF (mutPROTnum.gt.1) THEN
DO i=2,mutPROTnum
ZScore(i)=ZScore(i-1)+XScore(i)
END DO
! Pick a random number between 0 and the sum of all the xScore values.
CALL RANDOM_NUMBER(rand)
choice=rand*ZScore(mutPROTnum)
! Find the codon that corresponds to this number, assign to MutProtPos
inner: DO j=1,mutPROTnum
IF (ZScore(j).ge.choice) THEN
MutProtPos=mutPROT2prot(j)
EXIT inner
END IF
END DO inner
ELSE
! Otherwise, just choose the first codon
MutProtPos=mutPROT2prot(1)
END IF
END SUBROUTINE Mutate_Wheel