1

嗨,我制作了这个脚本来从 qiime 使用 silva 数据库获得的 OTUs 文件中提取所有门,我添加了一个子程序来消除重复的分类单元并提取所有没有冗余的(每个分类单元之一),我的问题是我只是得到 las 线(只有一种分类群)

#!/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;
4

1 回答 1

1

我怀疑问题出在:

@taxon_list =$_;

它没有附加到当前元素,而是被当前元素覆盖。

尝试:

push @taxon_list, $_;

您还可以将以下内容移出循环:

@final_list = uniq @taxon_list;
于 2016-10-26T18:29:09.883 回答