gff文件_gff文件解析 - _lhtk_的个人空间 - OSCHINA - 中文开源技术交流社区

filter_gff3_by_transcript_id.pl

#!/usr/bin/perl

# by lhtk : lhtk80t7@gmail.com

use strict;

use warnings;

use Bio::Tools::GFF;

use feature 'switch';

use experimental 'smartmatch';

#use Getopt::Long;

my $transcript_id_file = $ARGV[0];

my $gff_in = $ARGV[1];

my $gff_out = $ARGV[2];

die "根据 transcript_id 来过滤 gff3 文件。\n\nUsage:\n\t$0 transcript_id_file gff3_in gff3_out\n" unless (defined $transcript_id_file and defined $gff_in and defined $gff_out);

die "文件已存在!" if ((-e $gff_out) and ($gff_out ne 'tmp.gff3'));

open IDS, '

my %transcript_ids;

my %gene_ids;

while () {

next if /^\s*$/;

chomp;

$transcript_ids{$_} = 1;

my $gid = (split /\./, $_)[0];

$gene_ids{$gid} = 1;

}

close IDS;

print "Get transcript_ids and gene_ids.\n\n";

# debug

# while (my($k,$v) = each %transcript_ids) {

# print "$k => $v\n";

# }

# while (my($k,$v) = each %gene_ids) {

# print "$k => $v\n";

# }

my $gffio_i = Bio::Tools::GFF->new(-file => $gff_in, -gff_version => 3);

my $gffio_o = Bio::Tools::GFF->new(-file => '>' . $gff_out, -gff_version => 3);

while (my $f = $gffio_i->next_feature()) {

# debug

# print $f->primary_tag(), "\n";

given ($f->primary_tag()) {

when (/predicted_gene/) {

# my $id = $f->primary_id(); # 也可以

my ($id) = $f->get_tag_values('ID');

# print "$id\n"; # debug

next unless exists $gene_ids{$id};

}

when (/mRNA/) {

my ($id) = $f->get_tag_values('ID');

next unless exists $transcript_ids{$id};

}

when (/exon|CDS/) {

my ($parent) = $f->get_tag_values('Parent');

next unless exists $transcript_ids{$parent};

}

default {

die "Do you know this? -- ", $f->primary_tag(), "\n";

}

}

$gffio_o->write_feature($f);

}

$gffio_i->close();

$gffio_o->close();

print "Done!\n";

获取 gff 文件第一列数据:$feat->seq_id(),更多请参考Bio::SeqFeature::Generic。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值