2016-10-26 3 views
1

안녕하세요, 저는 silva 데이터베이스를 사용하여 qiime에서 얻은 OTUs 파일에서 모든 문을 추출하기 위해이 스크립트를 만들었습니다. 중복 분류군을 제거하고 각 분류군 중 하나를 추출하기 위해 서브 루틴을 추가했습니다. 내 문제는 함께 난 그냥 (하나 개의 분류군)perl로 중복 목록을 제거하십시오

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

내가 문제를 의심 라스 라인을 얻을 수 있습니다 :

@taxon_list =$_; 

그것은 추가하지만, 현재의 요소를 대신 덮어 쓰기되지 않습니다.

시도 :

push @taxon_list, $_; 

당신은 또한 루프 외부에서 다음을 이동할 수 있습니다

@final_list = uniq @taxon_list; 
+0

정말 고마워요 빈스, 정말 작동! –

관련 문제