根据去冗余的蛋白序列提取核酸序列

rename.pl
#!/usr/bin/perl -w
use strict;
use Getopt::Long;

my $usage = <<_USAGE_;
usage : perl $0 -i fasta file -o output
_USAGE_

my ($input, $output);
GetOptions(
	"i=s" => \$input,
	"o=s" => \$output
);
die $usage if (!$input || !$output);

open (my $in, "$input") || die "$!:$input\n";
open (my $out, ">$output") || die "$!:$output\n";
open (my $out2, ">$output.idChangeList") || die "$!:$output.idChangeList\n";
my $n = 1;
while (<$in>){
	chomp;next if ($_ eq '');s/\r//g;
	if (/^>/){
		/\|(\d+)$/;
		my $newID = ">gene_$n\|$1";
		print $out "$newID\n";
		print $out2 "$_\t$newID\n";
		$n++;
	}else{
		print $out "$_\n";
	}
}
close;
getNRNucl.pl
#!/usr/bin/perl -w
use strict;
use Getopt::Long;
my $usage = <<_USAGE_;
usage : 
version 1.0
getNrNucl.pl -i P_GC
_USAGE_

my $P_GC;
GetOptions(
	"i=s" => \$P_GC
);
die $usage if (!$P_GC);

my %nrGeneListP;
open (my $pgl, "$P_GC/all.nr.prot.fa") || die "$!:$P_GC/all.nr.prot.fa\n";
while (<$pgl>){
	chomp;next if ($_ eq '');s/\r//g;
	if (/^>/){
		$_ =~ s/^>(.+?)\|.+/$1/;
		$nrGeneListP{$_} = 1;
	}
}
close $pgl;

my %idExchange;
open (my $ie, "$P_GC/all.rename.nr.prot.fa.idChangeList") || die "$!:$P_GC/all.rename.nr.prot.fa.idChangeList\n";
while (<$ie>){
	chomp;next if ($_ eq '');s/\r//g;
	my @entries = split/\t/;
	$entries[0] =~ /^>(.+?)\|.+/;
	my $ri = $1;
	$entries[1] =~ /^>(.+?)\|.+/;
	my $ni = $1;
	$idExchange{$ri} = $ni;
}
close $ie;

open (my $ng, "$P_GC/all.nucl.fa") || die "$P_GC/all.nucl.fa";
open (my $ngn, ">$P_GC/all.nr.nucl.fa") || die "$P_GC/all.nr.nucl.fa";
my $flag = 0;
while (<$ng>){
	chomp;next if ($_ eq '');s/\r//g;
	if (/^>(.+?\|(\d+))/){
		my $id = $1;
		my $len = $2;
		$id =~ s/(\|.+)//;
		if ($nrGeneListP{$id}){
			$flag = 1;
			$_ = ">$idExchange{$id}|$len";
		}else{
			$flag = 0;
		}
	}
	if ($flag == 1){
		print $ngn "$_\n";
	}
}
close $ng;
close $ngn;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值