こんにちは、このスクリプトを作成して、silva データベースを使用して qiime から取得した OTU ファイルからすべての門を抽出しました。サブルーチンを追加して、重複する分類群を排除し、すべての冗長 (各分類群の 1 つ) を抽出しました。私の問題は、las 行を取得することです。 (1 つの分類群のみ)
#!/usr/bin/perl -w
use strict;
use Getopt::Long;
my ($imput, $output, $line, $phylum, @taxon_list, @final_list);
GetOptions (
'in=s' =>\$imput,
'ou=s' =>\$output,
'k' =>\$phylum,
);
if (!$imput or !$output){
exit;
print "Error";
}
#SUBRUTINE TO ELIMINATE DUPLICATES
# --------------------------------------------------------------------------------------------
sub uniq {
my %seen;
grep !$seen{$_}++, @_;
}
# --------------------------------------------------------------------------------------------
open INPUTFILE, "<", "$imput", or die "can`t open file\n";
open OUTPUTFILE, ">", "$output" or die "can`t creat file\n";
while (<INPUTFILE>){
$line=$_;
chomp($line);
if ($line=~ m/^#/g){
next;
}
elsif($phylum){
my @kingd=($line=~m/D_1__(.*);D_2/g);
foreach (@kingd){
if ($_=~/^$/){
next;
}
elsif ($_=~ m/^[Uu]nknown/g){
next;
}
elsif ($_=~ m/^[Uu]ncultured$/g){
next;
}
elsif ($_=~ m/^[Uu]nidentified$/g){
}
else {
@taxon_list =$_;
@final_list = uniq @taxon_list;
}
}
}
}
print OUTPUTFILE "@final_list\n";
close INPUTFILE;
close OUTPUTFILE;
exit;