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

Annotation of /FigKernelScripts/genbank2gff3.pl

Parent Directory Parent Directory | Revision Log Revision Log


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

1 : overbeek 1.1
2 :    
3 :    
4 :     # A genbank2gff3 converter written by Rob in part for Ed DeLong
5 :     # this uses BioPerl to read the genbank file and then writes out a more custom
6 :     # gff3 file.
7 :    
8 :     use strict;
9 :     use lib '/Users/Rob/perl/bioperl/cvs/bioperl-live';
10 :     use Bio::SeqIO;
11 :     use URI::Escape;
12 :    
13 :     # I am not using the Bio::Feature::GFF3 because, well, screw them
14 :    
15 :     my $usage=<<EOF;
16 :    
17 :     $0
18 :     -f genbank file
19 :     -g genome ID
20 :    
21 :    
22 :     EOF
23 :    
24 :     my ($file, $genomeid)=('', 'xxxxxxxx');
25 :    
26 :     while (@ARGV) {
27 :     my $t=shift;
28 :     if ($t eq "-f") {$file=shift}
29 :     elsif ($t eq "-g") {$genomeid=shift}
30 :     }
31 :    
32 :     die $usage unless ($file);
33 :    
34 :    
35 :     my $sio=Bio::SeqIO->new(-file=>$file, -format=>"genbank");
36 :    
37 :    
38 :     my $taxid=$genomeid;
39 :     $taxid=~s/\.\d+//;
40 :    
41 :    
42 :     my $genecount; my $rnacount;
43 :     while (my $seqobj=$sio->next_seq)
44 :     {
45 :     print "#gff-version 3\n#seed\tgenome_id\t$genomeid\n#seed\ttaxon_id\t$taxid\n";
46 :     print "#seed\tname\t", $seqobj->desc, "\n";
47 :     print join("\t", "##sequence-region", $seqobj->display_id, "1", $seqobj->length()), "\n";
48 :    
49 :     my %translation;
50 :     foreach my $feature ($seqobj->get_SeqFeatures) {
51 :     #$feat is a Bio::SeqFeature::Generic
52 :     my @gff3;
53 :     my $col9;
54 :     my $id; my $label;
55 :     if ($feature->primary_tag eq "CDS")
56 :     {
57 :     $id="fig|".$genomeid.".peg.".++$genecount;
58 :     $label="cds";
59 :     # translate the protein. Here we actually make a new sequence object containing the DNA sequence and then use bioperl to
60 :     # do the translation. There are some things in bioperl that return objects (like translate) and somethings that don't (like subseq)
61 :     # 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
62 :     my $translationid="pro.$genecount";
63 :     ($feature->strand == -1) ?
64 :     ($translation{$translationid}=Bio::Seq->new(-seq=>$seqobj->subseq($feature->start, $feature->end))->revcom->translate->seq) :
65 :     ($translation{$translationid}=Bio::Seq->new(-seq=>$seqobj->subseq($feature->start, $feature->end))->translate->seq) ;
66 :    
67 :     push @{$col9->{"translation_id"}}, $translationid;
68 :     }
69 :     elsif ($feature->primary_tag eq "tRNA" || $feature->primary_tag eq "rRNA")
70 :     {
71 :     $id="fig|".$genomeid.".rna.".++$rnacount;
72 :     $label=$feature->primary_tag;
73 :     }
74 :     elsif ($feature->primary_tag eq "gene")
75 :     {
76 :     # we ignore these, especially since they are the same as rna's in this case!
77 :     }
78 :     else {print STDERR "Got a ", $feature->primary_tag, "\n"}
79 :     next unless ($id);
80 :    
81 : overbeek 1.2 push @gff3, $seqobj->display_id;
82 :     push @{$col9->{"Dbxref"}}, "FIG_ID:$id";
83 : overbeek 1.1
84 :     if ($feature->display_name) {push @{$col9->{"Alias"}}, $feature->display_name}
85 :     if ($feature->source_tag) {push @gff3, $feature->source_tag} else {push @gff3, "DeLong's sequencing"}
86 :     push @gff3, $label, $feature->start, $feature->end;
87 :     $feature->score ? push @gff3, $feature->score : push @gff3, ".";
88 :     $feature->strand == +1 ? push @gff3, "+" :
89 :     $feature->strand == -1 ? push @gff3, "-" :
90 :     push @gff3, ".";
91 :     $feature->frame ? push @gff3, $feature->frame : push @gff3, ".";
92 :     foreach my $tag ($feature->get_all_tags) {
93 :     push @{$col9->{$tag}}, $feature->get_tag_values($tag)
94 :     }
95 :    
96 :     push @gff3, join(";", map {"$_=" . uri_escape(join(",", @{$col9->{$_}}))} keys %$col9);
97 :     print join("\t", @gff3), "\n";
98 :     }
99 :     # now print out the translations
100 :     print "##FASTA\n";
101 :     map {$translation{$_}=~s/(.{60})/$1\n/g; chomp($translation{$_}); print ">$_\n$translation{$_}\n"} sort keys %translation;
102 :     my $seq=$seqobj->seq;
103 :     $seq=~s/(.{60})/$1\n/g; chomp($seq);
104 :     print ">", $seqobj->display_id, "\n", $seq, "\n";
105 :     }
106 :    
107 :    
108 :    
109 :    

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3