[Bio] / FigKernelScripts / genbank2gff3.pl Repository:
ViewVC logotype

Annotation of /FigKernelScripts/genbank2gff3.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (view) (download) (as text)

1 : olson 1.5 #
2 :     # Copyright (c) 2003-2006 University of Chicago and Fellowship
3 :     # for Interpretations of Genomes. All Rights Reserved.
4 :     #
5 :     # This file is part of the SEED Toolkit.
6 :     #
7 :     # The SEED Toolkit is free software. You can redistribute
8 :     # it and/or modify it under the terms of the SEED Toolkit
9 :     # Public License.
10 :     #
11 :     # You should have received a copy of the SEED Toolkit Public License
12 :     # along with this program; if not write to the University of Chicago
13 :     # at info@ci.uchicago.edu or the Fellowship for Interpretation of
14 :     # Genomes at veronika@thefig.info or download a copy from
15 :     # http://www.theseed.org/LICENSE.TXT.
16 :     #
17 :    
18 : overbeek 1.1
19 :    
20 :    
21 :     # A genbank2gff3 converter written by Rob in part for Ed DeLong
22 :     # this uses BioPerl to read the genbank file and then writes out a more custom
23 :     # gff3 file.
24 :    
25 :     use strict;
26 :     use lib '/Users/Rob/perl/bioperl/cvs/bioperl-live';
27 :     use Bio::SeqIO;
28 :     use URI::Escape;
29 :    
30 :     # I am not using the Bio::Feature::GFF3 because, well, screw them
31 :    
32 :     my $usage=<<EOF;
33 :    
34 :     $0
35 :     -f genbank file
36 :     -g genome ID
37 :    
38 :    
39 :     EOF
40 :    
41 :     my ($file, $genomeid)=('', 'xxxxxxxx');
42 :    
43 :     while (@ARGV) {
44 :     my $t=shift;
45 :     if ($t eq "-f") {$file=shift}
46 :     elsif ($t eq "-g") {$genomeid=shift}
47 :     }
48 :    
49 :     die $usage unless ($file);
50 :    
51 :    
52 :     my $sio=Bio::SeqIO->new(-file=>$file, -format=>"genbank");
53 :    
54 :    
55 :     my $taxid=$genomeid;
56 :     $taxid=~s/\.\d+//;
57 :    
58 :    
59 :     my $genecount; my $rnacount;
60 :     while (my $seqobj=$sio->next_seq)
61 :     {
62 :     print "#gff-version 3\n#seed\tgenome_id\t$genomeid\n#seed\ttaxon_id\t$taxid\n";
63 :     print "#seed\tname\t", $seqobj->desc, "\n";
64 :     print join("\t", "##sequence-region", $seqobj->display_id, "1", $seqobj->length()), "\n";
65 :    
66 :     my %translation;
67 :     foreach my $feature ($seqobj->get_SeqFeatures) {
68 :     #$feat is a Bio::SeqFeature::Generic
69 :     my @gff3;
70 :     my $col9;
71 : overbeek 1.3 my $id; my $label; my $peg;
72 : overbeek 1.1 if ($feature->primary_tag eq "CDS")
73 :     {
74 : overbeek 1.3 $peg="fig|".$genomeid.".peg.".++$genecount;
75 : overbeek 1.1 $label="cds";
76 : overbeek 1.3 $id="cds.".$genecount;
77 : overbeek 1.1 # translate the protein. Here we actually make a new sequence object containing the DNA sequence and then use bioperl to
78 :     # do the translation. There are some things in bioperl that return objects (like translate) and somethings that don't (like subseq)
79 :     # note we also need a rev comp if the strand is -1. If we don't know the strand (or it is not -1) we return the forward translation
80 :     my $translationid="pro.$genecount";
81 :     ($feature->strand == -1) ?
82 :     ($translation{$translationid}=Bio::Seq->new(-seq=>$seqobj->subseq($feature->start, $feature->end))->revcom->translate->seq) :
83 :     ($translation{$translationid}=Bio::Seq->new(-seq=>$seqobj->subseq($feature->start, $feature->end))->translate->seq) ;
84 :    
85 :     push @{$col9->{"translation_id"}}, $translationid;
86 :     }
87 :     elsif ($feature->primary_tag eq "tRNA" || $feature->primary_tag eq "rRNA")
88 :     {
89 : overbeek 1.3 $peg="fig|".$genomeid.".rna.".++$rnacount;
90 : overbeek 1.1 $label=$feature->primary_tag;
91 : overbeek 1.3 $id="rna.".$rnacount;
92 : overbeek 1.1 }
93 :     elsif ($feature->primary_tag eq "gene")
94 :     {
95 :     # we ignore these, especially since they are the same as rna's in this case!
96 :     }
97 :     else {print STDERR "Got a ", $feature->primary_tag, "\n"}
98 :     next unless ($id);
99 :    
100 : overbeek 1.2 push @gff3, $seqobj->display_id;
101 : overbeek 1.4 push @{$col9->{"Dbxref"}}, "FIG_ID:$peg";
102 : overbeek 1.1
103 :     if ($feature->display_name) {push @{$col9->{"Alias"}}, $feature->display_name}
104 :     if ($feature->source_tag) {push @gff3, $feature->source_tag} else {push @gff3, "DeLong's sequencing"}
105 :     push @gff3, $label, $feature->start, $feature->end;
106 :     $feature->score ? push @gff3, $feature->score : push @gff3, ".";
107 :     $feature->strand == +1 ? push @gff3, "+" :
108 :     $feature->strand == -1 ? push @gff3, "-" :
109 :     push @gff3, ".";
110 :     $feature->frame ? push @gff3, $feature->frame : push @gff3, ".";
111 :     foreach my $tag ($feature->get_all_tags) {
112 :     push @{$col9->{$tag}}, $feature->get_tag_values($tag)
113 :     }
114 :    
115 : overbeek 1.3 push @gff3, join(";", "ID=$id", map {"$_=" . uri_escape(join(",", @{$col9->{$_}}))} keys %$col9);
116 : overbeek 1.1 print join("\t", @gff3), "\n";
117 :     }
118 :     # now print out the translations
119 :     print "##FASTA\n";
120 :     map {$translation{$_}=~s/(.{60})/$1\n/g; chomp($translation{$_}); print ">$_\n$translation{$_}\n"} sort keys %translation;
121 :     my $seq=$seqobj->seq;
122 :     $seq=~s/(.{60})/$1\n/g; chomp($seq);
123 :     print ">", $seqobj->display_id, "\n", $seq, "\n";
124 :     }
125 :    
126 :    
127 :    
128 :    

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3