之前多次遇到需要从nwk文件中提取基因ID的情况,为此写了一脚本,可以实现此操作。
用法:
perl nwk_geneid.pl -i in.nwk -o out.txt
in.nwk 为输入的nwk文件,out.txt是输出的基因ID文件。
脚本代码;
use Getopt::Long;
use strict;
my %opts;
GetOptions(\%opts,"i=s","o=s","h");
open(IN,"$opts{i}") || die "open $opts{i} failed\n";
open(OUT,">$opts{o}") ||die "open $opts{o} failed\n";
while(<IN>){
chomp;
my $str = $_;
$str =~ s/\d\.\d+//g;
$str =~ s/\(//g;
$str =~ s/\)//g;
$str =~ s/://g;
$str =~ s/;//g;
my @line = split(",",$str);
print OUT join("\n",@line);
}
close(IN);
close(OUT);
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!