Bioperl:把Genbank格式的序列转换为基因结构图

下面是一个BioPerl 的小 程序,可以把Genbank格式的序列转换为png图片-基因结构图,显示序列的长度,CDS区,exon区,STS区等。简单地讲就是把该序列的 Genbank格式里的信息用图片表示。 这个程序来源于网络。

下面举个例子,以 NM_172587为例。

NM_172587的Genbank格式下面的链接,另 存为文件名’NM_172587.gb’:

http://www.liucheng.name/entrez/entrez.php?acc=NM_172587&db=nucleotide&format=gb&start=Submit

下面是Bioperl脚本:

#!/usr/bin/Perl -w
use Bio::Graphics;

use Bio::SeqIO;

use Bio::SeqFeature::Generic;

my $file = shift    or die "provide a sequence file as the argument";

my $io = Bio::SeqIO->new(-file=>$file)    or die "couldn't create Bio::SeqIO";

my $seq = $io->next_seq    or die "couldn't find a sequence in the file";

my @features = $seq->all_SeqFeatures;# sort features by their primary tags
my %sorted_features;

for my $f (@features) {
  my $tag = $f->primary_tag;
  push @{$sorted_features{$tag}},$f;
  }
 
  my $panel = Bio::Graphics::Panel->new(
    -length => $seq->length,
    -key_style => 'between',
    -width => 800,
    -pad_left => 10,
    -pad_right => 10
   );
 
  $panel->add_track(
          arrow =>Bio::SeqFeature::Generic->new(-start => 1,-end => $seq->length),
    -bump => 0,
    -double=>1,
    -tick => 2
    );
 
  $panel->add_track(generic =>Bio::SeqFeature::Generic->new(-start => 1,-end => $seq->length,-bgcolor => 'blue', -label => 1));# general case
  my @colors = qw(cyan orange blue purple green  chartreuse magenta yellow aqua);
  my $idx = 0;   
 
  for my $tag (sort keys %sorted_features)
  {
          my $features = $sorted_features{$tag};
    $panel->add_track(
       $features,-glyph => 'generic',
       -bgcolor => $colors[$idx++ % @colors],
       -fgcolor => 'black',
       -font2color => 'red',
       -key => "${tag}s",
       -bump => +1,
       -height => 8,
       -label => 1,
       -description => 1
     );   
  }
 
  print $panel->png;

存为文件 名:graphics.pl

用法:

perl graphics.pl NM_172587.gb >1.png

结果就生成了一个名为1.png的图片,如下图

Bioperl:把Genbank格式的序列转换为基因结构图 - xiaofeng1982 - Leon

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值