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

Annotation of /FigKernelScripts/genbank2gff3.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (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 : overbeek 1.3 my $id; my $label; my $peg;
55 : overbeek 1.1 if ($feature->primary_tag eq "CDS")
56 :     {
57 : overbeek 1.3 $peg="fig|".$genomeid.".peg.".++$genecount;
58 : overbeek 1.1 $label="cds";
59 : overbeek 1.3 $id="cds.".$genecount;
60 : overbeek 1.1 # translate the protein. Here we actually make a new sequence object containing the DNA sequence and then use bioperl to
61 :     # do the translation. There are some things in bioperl that return objects (like translate) and somethings that don't (like subseq)
62 :     # 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
63 :     my $translationid="pro.$genecount";
64 :     ($feature->strand == -1) ?
65 :     ($translation{$translationid}=Bio::Seq->new(-seq=>$seqobj->subseq($feature->start, $feature->end))->revcom->translate->seq) :
66 :     ($translation{$translationid}=Bio::Seq->new(-seq=>$seqobj->subseq($feature->start, $feature->end))->translate->seq) ;
67 :    
68 :     push @{$col9->{"translation_id"}}, $translationid;
69 :     }
70 :     elsif ($feature->primary_tag eq "tRNA" || $feature->primary_tag eq "rRNA")
71 :     {
72 : overbeek 1.3 $peg="fig|".$genomeid.".rna.".++$rnacount;
73 : overbeek 1.1 $label=$feature->primary_tag;
74 : overbeek 1.3 $id="rna.".$rnacount;
75 : overbeek 1.1 }
76 :     elsif ($feature->primary_tag eq "gene")
77 :     {
78 :     # we ignore these, especially since they are the same as rna's in this case!
79 :     }
80 :     else {print STDERR "Got a ", $feature->primary_tag, "\n"}
81 :     next unless ($id);
82 :    
83 : overbeek 1.2 push @gff3, $seqobj->display_id;
84 :     push @{$col9->{"Dbxref"}}, "FIG_ID:$id";
85 : overbeek 1.1
86 :     if ($feature->display_name) {push @{$col9->{"Alias"}}, $feature->display_name}
87 :     if ($feature->source_tag) {push @gff3, $feature->source_tag} else {push @gff3, "DeLong's sequencing"}
88 :     push @gff3, $label, $feature->start, $feature->end;
89 :     $feature->score ? push @gff3, $feature->score : push @gff3, ".";
90 :     $feature->strand == +1 ? push @gff3, "+" :
91 :     $feature->strand == -1 ? push @gff3, "-" :
92 :     push @gff3, ".";
93 :     $feature->frame ? push @gff3, $feature->frame : push @gff3, ".";
94 :     foreach my $tag ($feature->get_all_tags) {
95 :     push @{$col9->{$tag}}, $feature->get_tag_values($tag)
96 :     }
97 :    
98 : overbeek 1.3 push @gff3, join(";", "ID=$id", map {"$_=" . uri_escape(join(",", @{$col9->{$_}}))} keys %$col9);
99 : overbeek 1.1 print join("\t", @gff3), "\n";
100 :     }
101 :     # now print out the translations
102 :     print "##FASTA\n";
103 :     map {$translation{$_}=~s/(.{60})/$1\n/g; chomp($translation{$_}); print ">$_\n$translation{$_}\n"} sort keys %translation;
104 :     my $seq=$seqobj->seq;
105 :     $seq=~s/(.{60})/$1\n/g; chomp($seq);
106 :     print ">", $seqobj->display_id, "\n", $seq, "\n";
107 :     }
108 :    
109 :    
110 :    
111 :    

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3