-
Notifications
You must be signed in to change notification settings - Fork 0
/
crispr_spurious1_initial.pl
201 lines (184 loc) · 4.76 KB
/
crispr_spurious1_initial.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
#!/usr/bin/perl
# crispr_spurious1_initial.pl
# AJPerez, feb 2019
use strict;
# Inputs and variables
my $FASTA = $ARGV[0] || "./uniprot_sprot_archaea.fasta";
my $CRISPR = $ARGV[1] || "./20190618_dr_34.fasta";
my $ONE = 0 || $ARGV[2]; # 1 = one only result per protein
my $minSP = 7;
my $maxSP = 20;
my $OUTFILE = $FASTA;
$OUTFILE =~ s/\.fasta/\.tsv/;
$| = 1;
# Gather genome sequence
my %p;
my $id;
open fasta, $FASTA || die "Error! Problem opening fasta file\n";
while (<fasta>) {
chomp;
if (/^>(.+)/) {
$id = $1;
} else {
$p{$id} .= $_;
}
}
close fasta;
# Run through repeats
my $n = 0;
my %trip;
open repeats, $CRISPR || die "Error! Problem opening crispr db fasta\n";
while (<repeats>) {
chomp;
next if /^>/;
next if /[^ACGT]/;
$n++;
my $sseq = $_;
for (my $cadena = 0; $cadena <= 1; $cadena++) {
my @aa;
my $strand = "+";
if ($cadena == 1) {
$sseq =~ tr/ACGT/TGCA/;
$sseq = reverse $sseq;
$strand = "-";
$n++;
}
#print "s$n\t";
for (my $pos = 0; $pos < 3; $pos++) {
my $pos_6 = $pos;
$pos_6 += 3 if $strand eq "-";
my $s = substr($sseq, $pos);
my $aa = &translate($s);
next if $aa =~ /X/;
push @aa, $aa;
}
# Check tri-peptides from the same strand
next if @aa == ();
my $trip = join "|", sort @aa;
push @{$trip{$trip}}, $sseq;
}
}
close repeats;
# Run though proteins
my $n = 0;
open FILE, ">$OUTFILE" || die "Error! Problem creating $OUTFILE\n";
protein: for my $id (keys %p) {
$n++;
my $pseq = $p{$id};
repeat: foreach my $t (keys %trip) {
my (@sp) = split/$t/, $pseq;
next unless ($#sp >= 2);
for (my $i = 1; $i <= $#sp - 1; $i++) {
my $l = length $sp[$i];
next repeat if $l < $minSP || $l > $maxSP;
}
print FILE "$id\t";
print FILE join ",", @{$trip{$t}};
print FILE "\t$t\t$#sp\t$pseq\n";
last if $ONE == 1;
}
print "$n proteins analysed...\n" if $n =~ /000$/;
}
close FILE;
print "$n proteins analysed...\n";
print "$OUTFILE file created";
exit;
##############
# SUBRUTINES #
##############
sub translate () {
my ($s) = @_;
# Código genético
my (%cg) = (
'TCA' => 'S', # Serina
'TCC' => 'S', # Serina
'TCG' => 'S', # Serina
'TCT' => 'S', # Serina
'TCN' => 'S', # Serina
'TTC' => 'F', # Fenilalanina
'TTT' => 'F', # Fenilalanina
'TTA' => 'L', # Leucina
'TTG' => 'L', # Leucina
'TAC' => 'Y', # Tirosina
'TAT' => 'Y', # Tirosina
'TAA' => 'X', # Stop
'TAG' => 'X', # Stop
'TGC' => 'C', # Cisteina
'TGT' => 'C', # Cisteina
'TGA' => 'X', # Stop
'TGG' => 'W', # Triptofano
'CTA' => 'L', # Leucina
'CTC' => 'L', # Leucina
'CTG' => 'L', # Leucina
'CTT' => 'L', # Leucina
'CTN' => 'L', # Leucina
'CCA' => 'P', # Prolina
'CCC' => 'P', # Prolina
'CCG' => 'P', # Prolina
'CCT' => 'P', # Prolina
'CCN' => 'P', # Prolina
'CAC' => 'H', # Histidina
'CAT' => 'H', # Histidina
'CAA' => 'Q', # Glutamina
'CAG' => 'Q', # Glutamina
'CGA' => 'R', # Arginina
'CGC' => 'R', # Arginina
'CGG' => 'R', # Arginina
'CGT' => 'R', # Arginina
'CGN' => 'R', # Arginina
'ATA' => 'I', # Isoleucina
'ATC' => 'I', # Isoleucina
'ATT' => 'I', # Isoleucina
'ATG' => 'M', # Methionina
'ACA' => 'T', # Treonina
'ACC' => 'T', # Treonina
'ACG' => 'T', # Treonina
'ACT' => 'T', # Treonina
'ACN' => 'T', # Treonina
'AAC' => 'N', # Asparagina
'AAT' => 'N', # Asparagina
'AAA' => 'K', # Lisina
'AAG' => 'K', # Lisina
'AGC' => 'S', # Serina
'AGT' => 'S', # Serina
'AGA' => 'R', # Arginina
'AGG' => 'R', # Arginina
'GTA' => 'V', # Valina
'GTC' => 'V', # Valina
'GTG' => 'V', # Valina
'GTT' => 'V', # Valina
'GTN' => 'V', # Valina
'GCA' => 'A', # Alanina
'GCC' => 'A', # Alanina
'GCG' => 'A', # Alanina
'GCT' => 'A', # Alanina
'GCN' => 'A', # Alanina
'GAC' => 'D', # Acido Aspartico
'GAT' => 'D', # Acido Aspartico
'GAA' => 'E', # Acido Glutamico
'GAG' => 'E', # Acido Glutamico
'GGA' => 'G', # Glicina
'GGC' => 'G', # Glicina
'GGG' => 'G', # Glicina
'GGT' => 'G', # Glicina
'GGN' => 'G', # Glicina
);
my $aa;
for (my $x = 0; $x <= length($s)-1; $x += 3) {
my $tri = substr($s, $x, 3);
my $tri_len = length($tri);
last if ($tri_len < 3);
if (!$cg{$tri}) {
if ($tri =~ /N/) {
$aa .= "X";
} else {
if ($tri =~ /[^ACGT]/) {
die "Error! with codon $tri\n";
}
}
} else { # if exist
$aa .= $cg{$tri};
}
}
return $aa;
}