-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAllnutt_macros.txt
426 lines (327 loc) · 8.46 KB
/
Allnutt_macros.txt
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
Attribute VB_Name = "Module1"
Function splitit(mystring, delim, pos)
Dim wrd() As String
wrd() = Split(mystring, delim)
splitit = wrd(pos)
End Function
Function splitit2(mystring, delim, stpos, enpos)
Dim wrd() As String
wrd() = Split(mystring, delim)
For x = stpos To enpos
splitit2 = splitit2 & delim & wrd(x)
Next x
End Function
Public Function shannon1(x As Range, n)
'calculate shannon diversity for a range of frequency values
'=-1*(((B$1*LOG(B$1,2))+(((1-B$1)*LOG(1-B$1,2)))))
'logprop = Math.Log(prop) / Math.Log(2)
'n = base n
For i = 1 To x.Count
a = x.Item(i)
If a <> 0 Then
log2a = Math.Log(a) / Math.Log(n)
plogp = a * log2a
Else
plogp = 0
End If
sumplogp = sumplogp + plogp
Next i
shannon1 = -1 * sumplogp
End Function
Public Function revcomp(x$)
'make reverse compliment
'test number of entries
Dim t$, a, test, length, change, out$, c, G, tm
'a = 0
'For test = 1 To 5001
't$ = ActiveSheet.Cells(test, 1)
'If t$ <> "" Then
'a = a + 1
'End If
'Next test
'change and output to next column
'For work = 2 To a
'x$ = ActiveSheet.Cells(1, 1)
length = Len(x$)
out$ = ""
c = 0
G = 0
For change = 0 To length - 1
'ActiveSheet.Cells(work, 5) = change + 1
'ActiveSheet.Cells(work, 6) = Mid(x$, length - change, 1)
If Mid(x$, length - change, 1) = "A" Then
out$ = out$ + "T"
End If
If Mid(x$, length - change, 1) = "T" Then
out$ = out$ + "A"
End If
If Mid(x$, length - change, 1) = "C" Then
out$ = out$ + "G"
c = c + 1
End If
If Mid(x$, length - change, 1) = "G" Then
out$ = out$ + "C"
G = G + 1
End If
If Mid(x$, length - change, 1) = "R" Then
out$ = out$ + "Y"
G = G + 0.5
End If
If Mid(x$, length - change, 1) = "Y" Then
out$ = out$ + "R"
G = G + 0.5
End If
If Mid(x$, length - change, 1) = "M" Then
out$ = out$ + "K"
G = G + 0.5
End If
If Mid(x$, length - change, 1) = "K" Then
out$ = out$ + "M"
G = G + 0.5
End If
If Mid(x$, length - change, 1) = "S" Then
out$ = out$ + "S"
G = G + 1
End If
If Mid(x$, length - change, 1) = "W" Then
out$ = out$ + "W"
End If
If Mid(x$, length - change, 1) = "H" Then
out$ = out$ + "D"
G = G + 0.33
End If
If Mid(x$, length - change, 1) = "B" Then
out$ = out$ + "V"
G = G + 0.66
End If
If Mid(x$, length - change, 1) = "D" Then
out$ = out$ + "H"
G = G + 0.33
End If
If Mid(x$, length - change, 1) = "N" Then
out$ = out$ + "N"
G = G + 0.5
End If
If Mid(x$, length - change, 1) = "V" Then
out$ = out$ + "B"
G = G + 0.66
End If
tm = (59.9 + (41 * ((c + G) / length))) - (500 / length)
'ActiveSheet.Cells(work, 7) = (change + 1) * 0.27
'nb decomment next line to print reverse complement of sequence
revcomp = out$
Next change
'GIVE NEW NAME TO REV COMP
'ActiveSheet.Cells(work, 8) = Left(ActiveSheet.Cells(work, 6), Len(ActiveSheet.Cells(work, 6)) - 2) & "out"
'ActiveSheet.Cells(work, 6) = tm
'ActiveSheet.Cells(work, 5) = change
'melting temp
'Tm = 81.5 + 16.6 log [Na+] + 41(G + C)/length -500/length
'Next work
End Function
Public Function Sort(ArrayIn, Ascending As Boolean)
Dim SrtTemp As Variant
Dim i As Long
Dim j As Long
If Ascending = True Then
For i = LBound(ArrayIn) To UBound(ArrayIn)
For j = i + 1 To UBound(ArrayIn)
If ArrayIn(i) > ArrayIn(j) Then
SrtTemp = ArrayIn(j)
ArrayIn(j) = ArrayIn(i)
ArrayIn(i) = SrtTemp
End If
Next j
Next i
Else
For i = LBound(ArrayIn) To UBound(ArrayIn)
For j = i + 1 To UBound(ArrayIn)
If ArrayIn(i) < ArrayIn(j) Then
SrtTemp = ArrayIn(j)
ArrayIn(j) = ArrayIn(i)
ArrayIn(i) = SrtTemp
End If
Next j
Next i
End If
Sort = ArrayIn
End Function
Sub make_pop_graph()
'
'
Dim popstart(1000)
Dim popend(1000)
Dim r1 As Range
Dim group_address As String
Dim r1_address As String
Set G = Application.InputBox("select grouping column first cell", "Get Group Colum", Type:=8)
Set r1 = Application.InputBox("select PCA1 column first cell", "Get PCA1 Column", Type:=8)
group_address = G.Address
r1_address = r1.Address
m = splitit(group_address, "$", 1) ' Mid(group_address, 2, 1)
p = splitit(r1.Address, "$", 1) 'Mid(r1.Address, 2, 1)
group_col = Range(m & 1).Column
pca1 = Range(p & 1).Column
pca2 = pca1 + 1
'group_col = 27
num_pops = 0
t = 1
For x = 2 To 10000
a = Cells(x, group_col)
b = Cells(x - 1, group_col)
If a = "" Then GoTo 10
t = t + 1
If a <> b Then
num_pops = num_pops + 1
popstart(num_pops) = t
' Cells(num_pops, 33) = popstart(num_pops)
End If
't = t + 1
popend(num_pops) = t
' Cells(num_pops, 34) = popend(num_pops)
Next x
10
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlXYScatter
Do Until ActiveChart.SeriesCollection.Count = 0
ActiveChart.SeriesCollection(1).Delete
Loop
For p = 1 To num_pops
Randomize
red1 = Int(Rnd() * 255)
green1 = Int(Rnd() * 255)
blue1 = Int(Rnd() * 255)
'Cells(1, 15) = red1
'Cells(1, 16) = green1
'Cells(1, 17) = blue1
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(p).Name = Cells(popstart(p), group_col)
ActiveChart.SeriesCollection(p).XValues = Range(Cells(popstart(p), pca1), Cells(popend(p), pca1))
ActiveChart.SeriesCollection(p).Values = Range(Cells(popstart(p), pca2), Cells(popend(p), pca2))
ActiveChart.SeriesCollection(p).MarkerStyle = 8
ActiveChart.SeriesCollection(p).MarkerSize = 5
ActiveChart.SeriesCollection(p).Select
ActiveChart.SeriesCollection(p).MarkerBackgroundColor = RGB(red1, green1, blue1)
ActiveChart.SeriesCollection(p).MarkerForegroundColor = RGB(red1, green1, blue1)
'With Selection.Format.Fill.ForeColor
'.Visible = msoTrue
'.RGB = RGB(red1, green1, blue1)
'.Solid
'.Transparency = 0.2
'End With
'ActiveChart.SeriesCollection(p).Select
'With Selection.Format.Fill.BackgroundColor
'.Visible = msoTrue
'.RGB = RGB(red1, green1, blue1)
'.Solid
'.Transparency = 0.2
'End With
Selection.Format.Line.Visible = msoFalse
ActiveChart.SetElement (ElementLegendRight)
Next p
'ActiveChart.Axes(xlValue).MinimumScaleIsAuto = True
'ActiveChart.Axes(xlValue).MaximumScaleIsAuto = True
End Sub
Sub findbinary()
Dim c
Dim t
t = 1
input_col = 14
output_col = 2
end_genes = 15963
end_blast = 14159
ReDim genes(end_blast, 2)
ReDim cds(end_genes)
'MUST PUT HITS AND CDS IN SAME ORDER
Worksheets("genes").Select
c = 0
For x = 2 To end_genes
c = c + 1
cds(c) = Cells(x, 1)
Next x
Worksheets("blast_hits").Select
c = 0
For y = 1 To end_blast
c = c + 1
genes(c, 2) = Cells(y, input_col) 'gene name
genes(c, 1) = Cells(y, 1) 'cds id
Next y
Worksheets("genes").Select
c = 0
For i = 2 To end_genes
c = c + 1
t = 0
d = 0
For j = 1 To end_blast
d = d + 1
If cds(c) = genes(d, 1) Then
Cells(i, output_col) = genes(j, 2)
Cells(i, output_col).Select
t = 1
GoTo 10
End If
Next j
10
If t = 0 Then
Cells(c + 1, output_col) = "unknown cds"
End If
Next i
End Sub
Sub everyother()
c = 0
For x = 1 To 80 Step 2
c = c + 1
Cells(c, 3) = Cells(x, 1)
Cells(c, 4) = Cells(x + 1, 1)
'Cells(c, 8) = Cells(x + 1, 3)
Next x
End Sub
Sub everyother2()
c = 0
For x = 1 To 120 Step 2
c = c + 1
Cells(c, 5) = Cells(x, 2)
Cells(c, 6) = Cells(x + 1, 3) + Cells(x, 3)
Next x
End Sub
Sub delrows()
'delete identical rows when they have been sorted
c = 2
col = 3
Do
If Cells(c, col) = "" Then GoTo 10
If Cells(c, col) = Cells(c - 1, col) Then
Rows(c).Select
Selection.Delete Shift:=xlUp
Else: c = c + 1
End If
Loop
10
End Sub
Sub getname_fromlist()
For x = 2 To 107
a = Cells(x, 2)
For y = 2 To 288
b = Cells(y, 8)
If InStr(b, a) Then
Cells(x, 4) = b
Exit For
End If
Next y
Next x
End Sub
Sub sum_groups()
Dim data(1000, 1)
Dim keys(1000, 1)
For x = 4 To 133
If Cells(x, 1) <> Cells(x - 1, 1) Then
c = c + 1
keys(c, 1) = Cells(x, 1)
End If
data(Cells(x, 1), 1) = data(Cells(x, 1), 1) + Cells(x, 3)
Next x
For out = 1 To c:
Cells(out, 5) = keys(out, 1)
Cells(out, 6) = data(keys(out, 1), 1)
Next out
End Sub