-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse_genewise_prediction_results.pl
380 lines (352 loc) · 14.9 KB
/
parse_genewise_prediction_results.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 -w
use strict;
my $geneWiseInFile = "";
my $geneWiseProteinFile = "";
my $geneWiseDNAFile = "";
my $geneWise3LevelGFF3File = "";
my $geneWisePseudoGeneDNAFile = "";
my $summaryOutputFile = "";
my %possiblyTruncated = ();
foreach my $arg (@ARGV)
{
($arg =~ m/^-(h|help)$/) and usage();
($arg =~ m/^-g=(.+)$/) and $geneWiseInFile = $1;
}
if (-e $geneWiseInFile)
{
$geneWiseProteinFile = $geneWiseInFile . ".faa";
$geneWiseDNAFile = $geneWiseInFile . ".fna";
$geneWise3LevelGFF3File = $geneWiseInFile . ".gff3";
$geneWisePseudoGeneDNAFile = $geneWiseInFile . ".pseudo.fna";
}
($summaryOutputFile) or $summaryOutputFile = $geneWiseInFile . ".sum";
my $oldSep = $/;
$/= "genewise ";
open(IN, "<$geneWiseInFile") or die "Can not open genewise file $geneWiseInFile $!\n";
open(FAA, ">$geneWiseProteinFile") or die "Can not open genewise faa outfile $geneWiseProteinFile $!\n";
open(FNA, ">$geneWiseDNAFile") or die "Can not open genewise fna outfile $geneWiseDNAFile $!\n";
open(FNA, ">$geneWiseDNAFile") or die "Can not open genewise fna outfile $geneWiseDNAFile $!\n";
open(PSEUDO, ">$geneWisePseudoGeneDNAFile") or die "Can not open genewise fna outfile $geneWisePseudoGeneDNAFile $!\n";
open(GFF3, ">$geneWise3LevelGFF3File") or die "Can not open genewise fna outfile $geneWise3LevelGFF3File $!\n";
open(SUM, ">$summaryOutputFile") or die "Can not open genewise fna outfile $summaryOutputFile $!\n";
my $recordCounter = 0;
while ( my $record = <IN>)
{
next if ($record eq "genewise ");
$recordCounter++;
if ($recordCounter % 100 == 0)
{
select STDERR; print STDERR "$recordCounter\n";
}
my @lines = split/\n/, $record;
my $getTranslation = 0;
my $getDNASequence = 0;
my $getGFF3 = 0;
my $summaryLine = "";
my $faaSeq = "";
my $fnaSeq = "";
my $isPseudoGene = 0;
my $lastmRNAParentId = "";
my $lastGeneId = "";
if ($record =~ m/is a pseudo gene/s)
{
$isPseudoGene = 1;
}
my @gff3 =();
my $lineCount = 0;
my $summaryTxt = "";
foreach my $i (0 .. $#lines)
{
my $line = $lines[$i];
chomp $line;
my @lineData = split/\t/, $line;
if ($line =~ m/^Bits\tQuery/)
{
$summaryLine = $lines[$i + 1];
next;
}
elsif ($line =~ m/^>.+\.sp\.tr$/)
{
#>scaffold00001.[695800:696851].sp.tr
$getTranslation = 1;
my $nameLine = $line;
#$nameLine =~ s/\.tr$//g; # replace terminal .tr
$nameLine =~ s/\./_/g; # replace .
$nameLine =~ s/\:/_/g; # replace :
$nameLine =~ s/\[//g; # replace [
$nameLine =~ s/\]//g; # replace ]
my @nameData = split /\s+/, $nameLine;
$nameData[0] = $nameData[0] . "_" . $recordCounter;
$nameLine = join(" ", @nameData);
$faaSeq = $nameLine . " " . $summaryLine . "\n";
next;
}
elsif ($line =~ m/^>.+\.sp$/)
{
$getDNASequence = 1;
my $nameLine = $line;
$nameLine =~ s/\./_/g; # replace .
$nameLine =~ s/\:/_/g; # replace :
$nameLine =~ s/\[//g; # replace [
$nameLine =~ s/\]//g; # replace ]
my @nameData = split /\s+/, $nameLine;
$nameData[0] = $nameData[0] . "_" . $recordCounter;
$lastGeneId = $nameData[0];
$lastGeneId =~ s/^>//;
$nameLine = join(" ", @nameData);
$fnaSeq = $nameLine . " " . $summaryLine . "\n";
next;
}
elsif (($line =~ m!^//$!) and ($i < $#lines))
{
if (($isPseudoGene == 0) and ($lines[$i + 1] =~ m/^>.+\.sp\.tr$/))
{
$getTranslation = 1;
$getDNASequence = 0;
$getGFF3 = 0;
next;
}
elsif ($lines[$i + 1] =~ m/^>.+\.sp$/)
{
$getTranslation = 0;
$getDNASequence = 1;
$getGFF3 = 0;
next;
}
elsif ($getDNASequence)
{
$getTranslation = 0;
$getDNASequence = 0;
$getGFF3 = 1;
next;
}
else
{
$getDNASequence = 0;
$getTranslation = 0;
$getGFF3 = 0;
next;
}
next;
}
elsif ($getTranslation)
{
$faaSeq .= $line;
next;
}
elsif ($getDNASequence)
{
$fnaSeq .= $line;
next;
}
elsif ($getGFF3 and ($#lineData == 8))
{
# GFF3 line
if ($lineData[2] eq 'match')
{
# scaffold00001 GeneWise match 695800 696851 140.81 + . scaffold00001-genewise-prediction-1
#my $geneIdAttr = "ID=" . $lineData[0] . "_" . $lineData[3] . "_" . $lineData[4] . "_sp_" . $recordCounter;
my $geneIdAttr = "ID=$lastGeneId";
#my $mrnaIdAttr = "ID=" . $lineData[0] . "_" . $lineData[3] . "_" . $lineData[4] . ".mrna";
my $mrnaIdAttr = "ID=$lastGeneId" . "_mrna";
$lastmRNAParentId = $mrnaIdAttr;
my $nameAttr = "Name=$lastGeneId";
my $parentAttr = "Parent=$geneIdAttr";
my $pseudoGeneAttr = "";
if ($isPseudoGene == 1)
{
$pseudoGeneAttr = ";IsAPseudogene=1";
}
push(@gff3, join("\t", $lineData[0], $lineData[1], 'gene', $lineData[3], $lineData[4], $lineData[5], $lineData[6], $lineData[7], "$geneIdAttr;$nameAttr$pseudoGeneAttr") );
push(@gff3, join("\t", $lineData[0], $lineData[1], 'mRNA', $lineData[3], $lineData[4], $lineData[5], $lineData[6], $lineData[7], "$mrnaIdAttr;$nameAttr;$parentAttr") );
$summaryTxt = join("\t", $lastGeneId, $lineData[0], $lineData[3], $lineData[4], $lineData[6]);
}
elsif ($lineData[2] eq 'cds')
{
my $parentAttr = "Parent=$lastmRNAParentId";
push(@gff3, join("\t", $lineData[0], $lineData[1], 'CDS', $lineData[3], $lineData[4], $lineData[5], $lineData[6], $lineData[7], "$parentAttr") );
}
}
}
if ($isPseudoGene)
{
select PSEUDO; print PSEUDO "$fnaSeq\n";
}
else
{
if ($faaSeq)
{
select FAA; print FAA "$faaSeq\n";
my @fastaLine = split /\n/, $faaSeq;
if ($fastaLine[1] !~ m/^M/)
{
$possiblyTruncated{$fastaLine[0]}++;
}
}
else
{
die "No protein sequence for \n#$record#\n";
}
if ($fnaSeq)
{
select FNA; print FNA "$fnaSeq\n";
}
else
{
die "No DNA sequence for \n$record\n";
}
}
if (scalar(@gff3))
{
my $gff3 = join("\n", @gff3);
select GFF3; print GFF3 "$gff3\n";
select SUM; print SUM "$summaryTxt\n";
}
else
{
die "No DNA sequence for \n$record\n";
}
}
close(SUM);
close(GFF3);
close(PSEUDO);
close(FNA);
close(FAA);
close(IN);
open(OUT, ">possiblyTruncated.list") or die "Can not open possiblyTruncated.list $!\n";
foreach my $line (keys %possiblyTruncated)
{
print OUT "$line\n";
}
close(OUT);
exit(0);
sub usage
{
print "$0 -g=geneWiseInFile\n";
exit(0);
}
__END__
=head1 DESCRIPTION
Takes genewise records (all concatenated into single file
and parses out the proteins and DNA sequence and reformats
the GFF3 to GBrowse 3 level system
=head1 SYNOPSIS
$0 -g=geneWiseInFile
Where geneWiseInFile is output file from genewise and/or
several genewise results file concatenated into single
results file.
=head1 DISCLAIMER
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHORS, COPYRIGHT HOLDER, OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=head1 GeneWise Record Structure
Genewise records start with:
genewise $Name: $ (unreleased release)
This program is freely distributed under a GPL. See source directory
Copyright (c) GRL limited: portions of the code are from separate copyright
Query protein: gene00217-v1.0-hybrid
Comp Matrix: BLOSUM62.bla
Gap open: 12
Gap extension: 2
Start/End default
Target Sequence scaffold00001
Strand: reverse
Start/End (protein) default
Gene Parameter file: gene.stat
Splice site model: GT/AG only
GT/AG bits penalty -9.95
Codon Table: codon.table
Subs error: 1e-06
Indel error: 1e-06
Null model syn
Algorithm 623
Bits Query start end Target start end idels introns
330.06 gene00217-v1.0-hybrid 1 164 scaffold00001 195114 193933 0 1
//
Gene 1
Gene 195114 193933
Exon 195114 194878 phase 0
Exon 194187 193933 phase 0
//
>scaffold00001.[195114:193931].sp.tr
MPAGHGLRSRTRDLFSRAFRKKGYIPLSTYLKTYRIGDHVDVKVNGAVHKGMPHKFYHGR
TGRVWNVTKRAIGVEINKQVGNRIIRKRIHVRVEHVQPSRCTEEFRLRKIKNDQLKAEAK
AKGEVISTKRQPKGPKPGFRVEGAVMETVTPIPYDVVNDLKGGY
//
>scaffold00001.[195114:193931].sp
ATGCCGGCTGGACACGGTCTCCGTTCCCGGACTCGCGATCTGTTCTCGAGGGCCTTCAGG
AAGAAGGGGTACATACCACTCTCCACCTACCTCAAGACCTACAGGATCGGCGACCATGTC
GACGTCAAGGTTAACGGCGCCGTCCACAAGGGTATGCCCCACAAGTTCTACCACGGCCGT
ACCGGTCGCGTCTGGAACGTTACCAAGCGCGCCATCGGTGTCGAGATCAACAAGCAGGTT
GGAAACAGAATCATCAGGAAGAGGATCCACGTGCGTGTGGAGCATGTGCAGCCATCAAGG
TGCACCGAAGAATTCCGTTTGAGGAAGATTAAGAATGACCAGCTGAAGGCCGAGGCTAAA
GCAAAGGGTGAGGTCATTAGCACCAAGAGGCAGCCAAAGGGACCAAAGCCTGGTTTCAGG
GTGGAAGGTGCCGTCATGGAAACTGTTACTCCCATTCCTTATGATGTCGTCAACGATCTT
AAAGGAGGGTAC
//
scaffold00001 GeneWise match 195114 193933 330.06 - . scaffold00001-genewise-prediction-1
scaffold00001 GeneWise cds 195114 194878 0.00 - 0 scaffold00001-genewise-prediction-1
scaffold00001 GeneWise intron 194877 194188 0.00 - . scaffold00001-genewise-prediction-1
scaffold00001 GeneWise cds 194187 193933 0.00 - 0 scaffold00001-genewise-prediction-1
//
genewise $Name: $ (unreleased release)
This program is freely distributed under a GPL. See source directory
Copyright (c) GRL limited: portions of the code are from separate copyright
Query protein: gene04071-v1.0-hybrid
Comp Matrix: BLOSUM62.bla
Gap open: 12
Gap extension: 2
Start/End default
Target Sequence scaffold00001
Strand: forward
Start/End (protein) default
Gene Parameter file: gene.stat
Splice site model: GT/AG only
GT/AG bits penalty -9.95
Codon Table: codon.table
Subs error: 1e-06
Indel error: 1e-06
Null model syn
Algorithm 623
Bits Query start end Target start end idels introns
135.90 gene04071-v1.0-hybrid 1 209 scaffold00001 695800 696851 0 2
//
Gene 1
Gene 695800 696851
Exon 695800 696045 phase 0
Exon 696166 696245 phase 0
Exon 696575 696851 phase 2
//
>scaffold00001.[695800:696851].sp.tr
VASAEEAEDTAAPLSSPNSTVSSFQMDFGIRSGGRSSKRDLEVDADRASDDENGSTRKKL
RLSKDQSAFLEESFKEHSTLNPKQKLALAKQLNLRPRQVEVWFQNRRARTKLKQTEVDCE
YLKRCCETLTEENRRLQKELQELRALKTSQPFYMQLPATTLTMCPSCERVVTTASANTST
TTTTTTTNNHIKSVQKKQPRL
//
>scaffold00001.[695800:696851].sp
GTGGCCTCGGCTGAGGAGGCAGAAGATACGGCGGCGCCGCTATCATCTCCGAACAGCACA
GTTTCATCGTTTCAGATGGATTTTGGAATAAGAAGTGGAGGAAGATCGAGTAAAAGAGAT
TTGGAGGTTGATGCCGACAGAGCGAGTGATGACGAGAACGGGTCGACTCGAAAGAAACTC
AGGCTCTCTAAAGATCAATCGGCTTTTCTTGAGGAGAGCTTCAAAGAGCACAGCACTCTC
AATCCTAAGCAAAAACTTGCTCTGGCTAAACAGTTGAATCTTCGTCCTCGCCAAGTGGAA
GTGTGGTTTCAGAATCGAAGAGCAAGGACCAAGCTGAAGCAGACAGAAGTAGATTGCGAG
TACTTAAAGAGATGCTGTGAGACACTGACAGAAGAGAATAGGAGGTTACAAAAAGAACTG
CAAGAATTAAGAGCTTTGAAGACCTCTCAGCCTTTCTACATGCAGCTGCCTGCCACCACA
CTCACCATGTGCCCCTCATGTGAGCGCGTGGTCACAACTGCCTCAGCCAACACCTCCACC
ACCACCACCACCACCACCACCAACAACCACATAAAGTCTGTTCAGAAGAAGCAGCCAAGG
TTA
//
scaffold00001 GeneWise match 695800 696851 140.81 + . scaffold00001-genewise-prediction-1
scaffold00001 GeneWise cds 695800 696045 0.00 + 0 scaffold00001-genewise-prediction-1
scaffold00001 GeneWise intron 696046 696165 0.00 + . scaffold00001-genewise-prediction-1
scaffold00001 GeneWise cds 696166 696245 0.00 + 0 scaffold00001-genewise-prediction-1
scaffold00001 GeneWise intron 696246 696574 0.00 + . scaffold00001-genewise-prediction-1
scaffold00001 GeneWise cds 696575 696851 0.00 + 1 scaffold00001-genewise-prediction-1
//