-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAURichness.pl
executable file
·379 lines (320 loc) · 13.4 KB
/
AURichness.pl
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
#!/usr/bin/perl
#------------------------------------------------------------------------------
# Perl Data Analysis:
# Pisapia et al (2018)
# Tristetraprolin regulates the turnover of autoimmune-associated HLA-DQ mRNAs
#
# Link to publication
# TO ADD ONCE AVAILABLE
#
# Script available from:
# https://github.com/darogan/2018_Pisapia_DelPozzo
#
# Analysis Performed by Russell S. Hamilton
# CTR Bioinformatics,
# Centre for Trophoblast Reseach, University of Cambridge, UK
# Copyright Russell S. Hamilton ([email protected])
#
#------------------------------------------------------------------------------
# License Information
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#------------------------------------------------------------------------------
use strict;
my %Sequences;
# WT
$Sequences{"DQA101"} = "UGAAUCCCAUCCUGGAAGGGAAGUGCAUCGCCAUCUACAGGAGCAGAAGAGUGGACUUGCUACAUGACCUAGCACUAUUCUCUGGCCCGAUUUAUCAUAUCCCUUUUCUCCUCCAAAUAUUUCUCCUCUCACCUUUUCUGUGGGACUUAAGCUGCUAUAUCCCCUCAGAGCUCACAAAUGUCUUU";
$Sequences{"DQB105"} = "UGACUCCUGAGACUGUUUUAACUAAGACUGGUUAUCACUCUUCUGUGAUGCCUGCUUGUCCCUGCCCAGAAUUCCCAGCUGCCUGUGUCAGCUUGUCCCCCUGAGAUCAAAGUCCUACAGUGGCUGUCACGCAACCACCAGGUCAUCUCCUUUCAUCCCCACCCCAAGGCGCUGGCUGUGACUCUGCUUCCUGCACUGACCCAGAGCC";
# CD
$Sequences{"DQA105"} = "UGAAUCCCAUCCUGGAAUGGAAGUGCAUCGCCAUCUACAGGAGCAGAAGAGUGGACUUGCUACAUGACCUAGCAUUAUUUUCUGGCCCCAUUUAUCAUAUCCCUUUUCUCCUCCAAAUGUUUCUCCUCUCACCUCUUCUGUGGGACUUAAAUUGCUAUAUCUGCUCAGAGCUCACAAAUGCCUUU";
$Sequences{"DQB102"} = "UGACUCCUGAGACUAUUUUAACUGGGAUUGGUUAUCACUUUUCUGUAACGCCUGCUUGUCCCUGCCCAGAAUUCCCAGCUGUCUGUGUCAGCCUGUCCCCCUGAGAUCAGAGUCCUACAGUGGCUGUCACGCAGCCACCAGGUCAUCUCCUUUCAUCCCCACCUUGAGGCGGAUGGCUGUGACCCUACUUCCUGCACUGACCCACAGCC";
my ($i, $genome,
$dihead, $ditail, $trihead, $tritail, $quadhead, $quadtail,
$pentahead, $pentatail, $hexahead, $hexatail,
$mononucFile, $dinucFile, $trinucFile, $quadnucFile, $pentanucFile, $hexanucFile,
%mono_nt, %di_nt, %tri_nt, %quad_nt, %penta_nt, %hexa_nt);
$mononucFile = "mononuc.table.txt";
$dinucFile = "dinuc.table.txt";
$trinucFile = "trinuc.table.txt";
$quadnucFile = "quadnuc.table.txt";
$pentanucFile = "pentanuc.table.txt";
$hexanucFile = "hexanuc.table.txt";
open(MONO, ">$mononucFile") || die "Can't open $mononucFile for writing: $!\n";
open(DI, ">$dinucFile") || die "Can't open $dinucFile for writing: $!\n";
open(TRI, ">$trinucFile") || die "Can't open $trinucFile for writing: $!\n";
open(QUAD, ">$quadnucFile") || die "Can't open $quadnucFile for writing: $!\n";
open(PENTA,">$pentanucFile") || die "Can't open $pentanucFile for writing: $!\n";
open(HEXA, ">$hexanucFile") || die "Can't open $hexanucFile for writing: $!\n";
print MONO "Sequence\tMononucleotide\tObs_freq\tExp_freq\n";
print DI "Sequence\tDinucleotide\tObs_freq\tExp_freq\n";
print TRI "Sequence\tTrinucleotide\tObs_freq\tExp_freq\n";
print QUAD "Sequence\tQuadnucleotide\tObs_freq\tExp_freq\n";
print PENTA "Sequence\tPentanucleotide\tObs_freq\tExp_freq\n";
print HEXA "Sequence\tHexanucleotide\tObs_freq\tExp_freq\n";
foreach my $seqheader (keys %Sequences)
{
print $seqheader, " -- ", $Sequences{$seqheader}, "\n";
my $seq = $Sequences{$seqheader};
$genome .= uc $seq;
$dihead = uc substr($seq, 0, 1);
$di_nt{"$ditail$dihead"}-- if $ditail;
$ditail = uc substr($seq, -1);
$trihead = uc substr($seq, 0, 2);
$tri_nt{"$tritail$trihead"}-- if $tritail;
$tritail = uc substr($seq, -1);
$quadhead = uc substr($seq, 0, 3);
$quad_nt{"$quadtail$quadhead"}-- if $quadtail;
$quadtail = uc substr($seq, -1);
$pentahead = uc substr($seq, 0, 4);
$penta_nt{"$pentatail$pentahead"}-- if $pentatail;
$pentatail = uc substr($seq, -1);
$hexahead = uc substr($seq, 0, 5);
$hexa_nt{"$hexatail$hexahead"}-- if $hexatail;
$hexatail = uc substr($seq, -1);
my $len = length $genome;
for my $i (0..$len-2)
{
my $each_mono_nt = substr($genome, $i, 1);
my $each_di_nt = substr($genome, $i, 2);
$mono_nt{$each_mono_nt}++;
$di_nt{$each_di_nt}++;
}
for my $i (0..$len-3)
{
my $each_tri_nt = substr($genome, $i, 3);
$tri_nt{$each_tri_nt}++;
}
for my $i (0..$len-4)
{
my $each_quad_nt = substr($genome, $i, 4);
$quad_nt{$each_quad_nt}++;
}
for my $i (0..$len-5)
{
my $each_penta_nt = substr($genome, $i, 5);
$penta_nt{$each_penta_nt}++;
}
for my $i (0..$len-6)
{
my $each_hexa_nt = substr($genome, $i, 6);
$hexa_nt{$each_hexa_nt}++;
}
$mono_nt{$ditail}++;
print "+ Calculating Single nucleotide frequency...\n";
for my $nt (sort keys %mono_nt)
{
print MONO "$seqheader\t$nt\t", $mono_nt{$nt} / $len, "\t0.25\n";
}
print "+ Calculating Dinucleotide frequency...\n";
for my $nt_pair (sort keys %di_nt)
{
my ($first_nt, $second_nt) = split //, $nt_pair;
print DI "$seqheader\t$nt_pair\t", $di_nt{$nt_pair} / ($len-1), "\t",
$mono_nt{$first_nt} * $mono_nt{$second_nt} /$len /$len, "\n";
}
print "+ Calculating Trinucleotide frequency...\n";
for my $nt_tri (sort keys %tri_nt)
{
my ($first_nt, $second_nt, $third_nt) = split //, $nt_tri;
print TRI "$seqheader\t$nt_tri\t", $tri_nt{$nt_tri} / ($len-1), "\t",
$mono_nt{$first_nt} * $mono_nt{$second_nt} * $mono_nt{$third_nt} /$len /$len /$len, "\n";
}
print "+ Calculating Quadnucleotide frequency...\n";
for my $nt_quad (sort keys %quad_nt)
{
my ($first_nt, $second_nt, $third_nt, $forth_nt) = split //, $nt_quad;
print QUAD "$seqheader\t$nt_quad\t", $quad_nt{$nt_quad} / ($len-1), "\t",
$mono_nt{$first_nt} * $mono_nt{$second_nt} * $mono_nt{$third_nt} *
$mono_nt{$forth_nt} /$len /$len /$len /$len, "\n";
}
print "+ Calcualting Pentanucleotide frequency...\n";
for my $nt_penta (sort keys %penta_nt)
{
my ($first_nt, $second_nt, $third_nt, $forth_nt, $fifth_nt) = split //, $nt_penta;
print PENTA "$seqheader\t$nt_penta\t", $penta_nt{$nt_penta} / ($len-1), "\t",
$mono_nt{$first_nt} * $mono_nt{$second_nt} * $mono_nt{$third_nt} *
$mono_nt{$forth_nt} * $mono_nt{$fifth_nt} /$len /$len /$len /$len /$len, "\n";
}
print "+ Calcualting Hexanucleotide frequency...\n";
for my $nt_hexa (sort keys %hexa_nt)
{
my ($first_nt, $second_nt, $third_nt, $forth_nt, $fifth_nt, $sixth_nt) = split //, $nt_hexa;
print HEXA "$seqheader\t$nt_hexa\t", $hexa_nt{$nt_hexa} / ($len-1), "\t",
$mono_nt{$first_nt} * $mono_nt{$second_nt} * $mono_nt{$third_nt} *
$mono_nt{$forth_nt} * $mono_nt{$fifth_nt} * $mono_nt{$sixth_nt} /$len /$len /$len /$len /$len /$len, "\n";
}
}
close DI;
close TRI;
close QUAD;
close PENTA;
close HEXA;
exit;
print "+"x100, "\n";
print "+ Density Matrix\n";
print "+"x100, "\n";
print "+ Creating Density Map\n";
my %SeqDensity;
foreach my $seqheader (keys %Sequences)
{
my(@Seq_Density_Di, @Seq_Density_Tri, @Seq_Density_Quad, @Seq_Density_Penta, @Seq_Density_Hexa);
push @Seq_Density_Di, (0) x (length($Sequences{$seqheader}));
push @Seq_Density_Tri, (0) x (length($Sequences{$seqheader}));
push @Seq_Density_Quad, (0) x (length($Sequences{$seqheader}));
push @Seq_Density_Penta, (0) x (length($Sequences{$seqheader}));
push @Seq_Density_Hexa, (0) x (length($Sequences{$seqheader}));
print $seqheader, "...", "\n";
my $dipatternstring = "UA|AU|UU";
my @dipattern = split(/\|/, $dipatternstring);
my $tripatternstring = "[UA][UA][UA]";
my @tripattern = split(/\|/, $tripatternstring);
my $quadpatternstring = "[UA][UA][UA][UA]";
my @quadpattern = split(/\|/, $quadpatternstring);
my $pentapatternstring = "[UA][UA][UA][UA][UA]";
my @pentapattern = split(/\|/, $pentapatternstring);
my $hexapatternstring = "[UA][UA][UA][UA][UA][UA]";
my @hexapattern = split(/\|/, $hexapatternstring);
#print "Dinucleotide Densities\n";
foreach my $dipat (@dipattern)
{
while($Sequences{$seqheader} =~ m/($dipat)/g)
{
$Seq_Density_Di[pos($Sequences{$seqheader})] += 1;
$Seq_Density_Di[pos($Sequences{$seqheader})+1] += 1;
}
}
#print "Trinucleotide Densities\n";
foreach my $tripat (@tripattern)
{
while($Sequences{$seqheader} =~ m/($tripat)/g)
{
my $As = () = $1 =~ /A/gi;
if($As < length($tripat)/2)
{
$Seq_Density_Tri[pos($Sequences{$seqheader})] += 1;
$Seq_Density_Tri[pos($Sequences{$seqheader})+1] += 1;
$Seq_Density_Tri[pos($Sequences{$seqheader})+2] += 1;
}
}
}
#print "Quadnucleotide Densities\n";
foreach my $quadpat (@quadpattern)
{
while($Sequences{$seqheader} =~ m/($quadpat)/g)
{
my $As = () = $1 =~ /A/gi;
if($As < length($quadpat)/2)
{
$Seq_Density_Quad[pos($Sequences{$seqheader})] += 1;
$Seq_Density_Quad[pos($Sequences{$seqheader})+1] += 1;
$Seq_Density_Quad[pos($Sequences{$seqheader})+2] += 1;
$Seq_Density_Quad[pos($Sequences{$seqheader})+3] += 1;
}
}
}
#print "Pentanucleotide Densities\n";
foreach my $pentapat (@pentapattern)
{
while($Sequences{$seqheader} =~ m/($pentapat)/g)
{
my $As = () = $1 =~ /A/gi;
if($As < length($pentapat)/2)
{
$Seq_Density_Penta[pos($Sequences{$seqheader})] += 1;
$Seq_Density_Penta[pos($Sequences{$seqheader})+1] += 1;
$Seq_Density_Penta[pos($Sequences{$seqheader})+2] += 1;
$Seq_Density_Penta[pos($Sequences{$seqheader})+3] += 1;
$Seq_Density_Penta[pos($Sequences{$seqheader})+4] += 1;
}
}
}
#print "Pentanucleotide Densities\n";
foreach my $hexapat (@hexapattern)
{
while($Sequences{$seqheader} =~ m/($hexapat)/g)
{
my $As = () = $1 =~ /A/gi;
if($As < length($hexapat)/2)
{
$Seq_Density_Hexa[pos($Sequences{$seqheader})] += 1;
$Seq_Density_Hexa[pos($Sequences{$seqheader})+1] += 1;
$Seq_Density_Hexa[pos($Sequences{$seqheader})+2] += 1;
$Seq_Density_Hexa[pos($Sequences{$seqheader})+3] += 1;
$Seq_Density_Hexa[pos($Sequences{$seqheader})+4] += 1;
$Seq_Density_Hexa[pos($Sequences{$seqheader})+5] += 1;
}
}
}
$SeqDensity{$seqheader}{"di"} = [@Seq_Density_Di];
$SeqDensity{$seqheader}{"tri"} = [@Seq_Density_Tri];
$SeqDensity{$seqheader}{"quad"} = [@Seq_Density_Quad];
$SeqDensity{$seqheader}{"penta"} = [@Seq_Density_Penta];
$SeqDensity{$seqheader}{"hexa"} = [@Seq_Density_Hexa];
}
my @motif_ranges = ("di", "tri", "quad", "penta", "hexa");
print "+ Writing DQA101_DQA105_densities.txt\n";
open(PAIR1,">DQA101_DQA105_densities.txt") || die "Can't open DQA101_DQA105_densities.txt for writing\n";
my @Headers = ("DQA101", "DQA105");
print PAIR1 "position,";
for(my $k=0; $k<=$#Headers; $k++)
{
for(my $i=0; $i<=$#motif_ranges; $i++)
{
print PAIR1 "${Headers[$k]}_${motif_ranges[$i]}";
print PAIR1 ",", if( $k + $i < $#Headers + $#motif_ranges);
}
}
print PAIR1 "\n";
for(my $j=0; $j<=$#{ $SeqDensity{$Headers[0]}{$motif_ranges[$i]} }; $j++)
{
for(my $k=0; $k<=$#Headers; $k++)
{
for(my $i=0; $i<=$#motif_ranges; $i++)
{
print PAIR1 "$j,", if(($k == 0) and ($i ==0));
print PAIR1 $SeqDensity{$Headers[$k]}{$motif_ranges[$i]}[$j];
print PAIR1 ",", if( $k + $i < $#Headers + $#motif_ranges);
}
}
print PAIR1 "\n";
}
close PAIR1;
print "+ Writing DQB105_DQB102_densities.txt\n";
open(PAIR2,">DQB105_DQB102_densities.txt") || die "Can't open DQA101_DQA105_densities.txt for writing\n";
my @Headers = ("DQB105", "DQB102");
print PAIR2 "position,";
for(my $k=0; $k<=$#Headers; $k++)
{
for(my $i=0; $i<=$#motif_ranges; $i++)
{
print PAIR2 "${Headers[$k]}_${motif_ranges[$i]}";
print PAIR2 ",", if( $k + $i < $#Headers + $#motif_ranges);
}
}
print PAIR2 "\n";
for(my $j=0; $j<=$#{ $SeqDensity{$Headers[0]}{$motif_ranges[$i]} }; $j++)
{
for(my $k=0; $k<=$#Headers; $k++)
{
for(my $i=0; $i<=$#motif_ranges; $i++)
{
print PAIR2 "$j,", if(($k == 0) and ($i ==0));
print PAIR2 $SeqDensity{$Headers[$k]}{$motif_ranges[$i]}[$j];
print PAIR2 ",", if( $k + $i < $#Headers + $#motif_ranges);
}
}
print PAIR2 "\n";
}
close PAIR2;
print "+"x100, "\n";
print "+ End of Script\n";
print "+"x100, "\n";