【问题标题】:eliminate redundant in a list with perl用 perl 消除列表中的冗余
【发布时间】:2016-10-26 17:37:56
【问题描述】:

嗨,我制作了这个脚本来从 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;

【问题讨论】:

    标签: perl bioinformatics redundancy qiime


    【解决方案1】:

    我怀疑问题出在:

    @taxon_list =$_;
    

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

    试试:

    push @taxon_list, $_;
    

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

    @final_list = uniq @taxon_list;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-13
      • 2020-09-29
      • 1970-01-01
      • 2021-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-07
      相关资源
      最近更新 更多