使用perl

时间:2016-10-26 17:37:57

标签: perl bioinformatics redundancy qiime

您好我使用silva数据库从qiime获取的OTU文件中提取所有门,我添加了一个子程序来消除重复的分类单元并提取所有没有多余的(每个分类单元之一),我的问题是我刚刚得到拉斯维加斯(只有一个分类群)

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

1 个答案:

答案 0 :(得分:1)

我怀疑问题是:

@taxon_list =$_;

它不会附加到,而是用当前元素覆盖。

尝试:

push @taxon_list, $_;

您还可以在循环外移动以下内容:

@final_list = uniq @taxon_list;
相关问题