Debian Codegraph @

wtools/embl2ace

raw
1 #!/usr/local/bin/perl -w
2 # $Id: embl2ace,v 1.2 1995/08/17 22:30:41 rd Exp $
3 # script to process EMBL entry to ACEDB4 .ace file
4 #
5 #
6
7 $/ = "//\n" ;
8
9 for (split (" ", "CDS mRNA " .
10 "tRNA snRNA scRNA rRNA misc_RNA")) {
11 $transcripts{$_} = 1 ;
12 }
13
14 while (<>) {
15
16 /^ID/ || die "Entry does not start with ID line: $_" ;
17 ($id) = /^ID (\S+)/ ;
18 $nam = "EM:" . $id ;
19 print "\nSequence $nam\n" ;
20 print "From_database EMBL\n" ;
21
22 print "DB_annotation EMBL $nam\n" ; # text handle
23
24 $text = "" ;
25
26 for (split (/XX\n/)) {
27 if (/^SQ/) {
28 s/ //g ;
29 s/\d//g ;
30 s/\/\/\n// ;
31 s/U/T/g ; # no RNA sequence!
32 s/^.*\n// ;
33 $seq = $_ ;
34 }
35 else {
36 $text .= $_ . "XX\n" ;
37 }
38 if (/^OS (\S+ \S+)/) {
39 print "Species \"$1\"\n" ;
40 }
41 if (/^AC/) {
42 s/AC //g ;
43 s/;//g ;
44 for (split) { print "Database EMBL $id $_\n" ; }
45 }
46 if (/^DE/) {
47 s/DE //g ;
48 chop ;
49 s/\n/ /g ;
50 s/"/\\"/g ;
51 print "Title \"$_\"\n" ;
52 }
53 if (/^RN/) {
54 # /RX (\S+); (\d+)/ && print "-RX $1 $2\n" ;
55 # /(\d+:\d+-\d+)\(19/ && print "-RF $1\n" ;
56 }
57 if (/^FH/) {
58 s/FT (\S)/ZZZZ$1/g ;
59 undef $haveExons ;
60 undef (@subseqs) ;
61 $nsubs = 0 ;
62 for (split (/ZZZZ/)) {
63 /^FH/ && next ;
64 # process into $key, $loc, @quals
65 chop ;
66 s/\nFT \//ZZZZ/g ;
67 s/\nFT //g ;
68 (s/(\S+)\s+// && ($key = $1)) || die "No FT key in $id\n" ;
69 @quals = split (/ZZZZ/) ;
70 ($loc = shift (@quals)) || die "No loc in $id - $key\n" ;
71
72 if ($key eq "source") {
73 # /organism="([^"]*)"/ && print "Species \"$1\"\n" ;
74 next ;
75 }
76 ($key eq "intron") && next ;
77 ($key eq "3'UTR") && next ;
78 ($key eq "5'UTR") && next ;
79 ($key eq "-") && next ;
80 if ($key eq "exon") {
81 $haveExons = 1 ;
82 next ;
83 }
84
85 # parse the location, somewhat roughly I am afraid
86 $_ = $loc ;
87
88 # arbitrarily take first of complex options
89 s/(one-of\(([^,]+),[^\)]+\))/$2/ && warn "Fixed $1 into $2\n" ;
90 s/\((\d+).\d+\)/$1/ ;
91
92 # shift replace() argument into qualifiers
93 s/^replace\(([^,]+),(.*)\)$/$1/ && push (@quals, "replace_by=$2") ;
94
95 # expand single position to pair of the same
96 s/^([<>]?\d+)$/$1..$1/ ;
97
98 # replace ^ symbol by ..
99 s/\^/\.\./ ;
100
101 undef @exons ;
102 if (/join\(complement\((.*complement.*)\)$/) {
103 $_ = $1;
104 s/complement\(|\)//g;
105 s/<//g && push (@quals, "End_not_found") ;
106 s/>//g && push (@quals, "Start_not_found") ;
107 $start = 0 ;
108 for (split (/,/, $_)) {
109 s/^(\d+)$/$1..$1/ ;
110 /(\d+)\.\.(\d+)/ || warn "In $id CJ parse $loc | $_\n" ;
111 ($start == 0) && ($start = $2) ;
112 push (@exons, ($start+1-$2) . " " . ($start+1-$1)) ;
113 $stop = $1 ;
114
115 }
116
117 } elsif (/^complement\((.*)\)$/) {
118 $_ = $1 ;
119 s/<//g && push (@quals, "End_not_found") ;
120 s/>//g && push (@quals, "Start_not_found") ;
121 if (/^join\((.*)\)$/) {
122 $start = 0 ;
123 for (reverse split (/,/, $1)) {
124 s/^(\d+)$/$1..$1/ ;
125 /(\d+)\.\.(\d+)/ || warn "In $id CJ parse $loc | $_\n" ;
126 ($start == 0) && ($start = $2) ;
127 push (@exons, ($start+1-$2) . " " . ($start+1-$1)) ;
128 $stop = $1 ;
129 }
130 }
131 else {
132 /(\d+)\.\.(\d+)/ || warn "In $id C parse $loc | $_\n" ;
133 $start = $2 ; $stop = $1 ;
134 }
135 }
136 else {
137 s/<//g && push (@quals, "Start_not_found") ;
138 s/>//g && push (@quals, "End_not_found") ;
139 if (/^join\((.*)\)$/) {
140 $start = 0 ;
141 for (split (/,/, $1)) {
142 s/^(\d+)$/$1..$1/ ;
143 /(\d+)\.\.(\d+)/ || warn "In $id J parse $loc | $_\n" ;
144 ($start == 0) && ($start = $1) ;
145 push (@exons, ($1+1-$start) . " " . ($2+1-$start)) ;
146 $stop = $2 ;
147 }
148 }
149 else {
150 /(\d+)\.\.(\d+)/ || warn "In $id parse $loc | $_\n" ;
151 $start = $1 ; $stop = $2 ;
152 }
153 }
154
155 # add to subseq stack, or write out
156 if ($transcripts{$key}) {
157 ++$nsubs ;
158 print "Subsequence $nam.$nsubs $start $stop\n" ;
159 push (@subseqs, join ("ZZZ", $key, join ("YYY", @quals),
160 join ("XXX", @exons))) ;
161 }
162 else {
163 print "$key $start $stop\n" ;
164 }
165 }
166 }
167 }
168
169 ($haveExons && !@subseqs) && warn "Exons but no subseqs in $id\n" ;
170
171 $nsubs = 0 ;
172 for (@subseqs) {
173 ++$nsubs ;
174 ($key, $q, $e) = split (/ZZZ/) ;
175 @quals = split (/YYY/, $q) ;
176 @exons = split (/XXX/, $e) ;
177 print "\nSequence $nam.$nsubs\n" ;
178 print "$key\n" ;
179 for (@exons) {
180 print "Source_exons $_\n" ;
181 }
182 for (@quals) {
183 (/Start_not_found/ || /End_not_found/) && print "$_\n" ;
184 /gene="(.*)"/ && print "Locus $1\n" ;
185 /codon_start=(.*)/ && ($1 != 1) && print "CDS $1\n" ;
186 }
187 }
188
189 print "\nDNA $nam\n" ;
190 print $seq ;
191
192 print "\nLongText $nam\n" ;
193 print $text ;
194 print "***LongTextEnd***\n" ;
195 }