8 perl脚本去除fa文件中ID重复的序列

老师,晚上好!我在网站中看到您的文章《去除fasta或fastq文件中ID重复的序列》,我之前还没有接触过perl语言。在我直接复制运行脚本的时候,出现了^Two-argument "open" used的报错。希望得到老师的帮助!下面是我复制运行的脚本:

use Getopt::Long;
use strict;
use Bio::SeqIO;
use Bio::Seq;
#get opts
my %opts;
GetOptions(\%opts, "fa=s", "fq=s", "fq1=s", "fq2=s", "f=s", "od=s", "n=s", "h");
if(!defined($opts{f}) || !defined($opts{od}) || !defined($opts{n}) || defined($opts{h}))
{
print <<"Usage End.";
Usage
Forced parameter:
-fa  C:/Users/Administrator/Desktop/comammoxfungene/comammox_fungene.fa      
-fq 
-fq1
-fq2
-f 
-od C:/Users/Administrator/Desktop/comammoxfungene/
-n  C:/Users/Administrator/Desktop/comammoxfungene/
Other parameter:
-h           Help document
Usage End.
exit;
}
if($opts{f} eq "fa" && defined($opts{fa})){
my$read1 = $opts{fa};
open my $FQ1 ,"zcat $read1|" or die "$!";
my$fq1=Bio::SeqIO->new(-fh=>$FQ1,-format=>'fasta');
open my $GZ1 ,"| gzip >$opts{od}/${n}.fa.gz" or die $!;
my$out1 = Bio::SeqIO->new(-fh => $GZ1 , -format => 'fasta');
my %id;
while ( my $obj1=$fq1->next_seq()  ) {
my $id1=$obj1->id;
if(exists $id{$id1}){
next;
}else{
$id{$id1} = 1;
}
$out1->write_seq($obj1);
}
}
if($opts{f} eq "fq"){
if(defined($opts{fq})){
my$read1 = $opts{fq};
open my $FQ1 ,"zcat $read1|" or die "$!";
my$fq1=Bio::SeqIO->new(-fh=>$FQ1,-format=>'fastq');
open my $GZ1 ,"| gzip >$opts{od}/${n}.fq.gz" or die $!;
my$out1 = Bio::SeqIO->new(-fh => $GZ1 , -format => 'fastq');
my %id;
while ( my $obj1=$fq1->next_seq()) {
my $id1=$obj1->id;
if(exists $id{$id1}){
next;
}else{
$id{$id1} = 1;
}
$out1->write_seq($obj1);
}
}elsif(defined($opts{fq1})  &&  defined($opts{fq2})){
my$read1 = $opts{fq1};
my$read2 = $opts{fq2};
open my $FQ1 ,"zcat $read1|" or die "$!";
my$fq1=Bio::SeqIO->new(-fh=>$FQ1,-format=>'fastq');
open my $FQ2 ,"zcat $read2|" or die "$!";
my$fq2=Bio::SeqIO->new(-fh=>$FQ2,-format=>'fastq');
open my $GZ1 ,"| gzip >$opts{od}/${n}_R1.fq.gz" or die $!;
my$out1 = Bio::SeqIO->new(-fh => $GZ1 , -format => 'fastq');
open my $GZ2 ,"| gzip >$opts{od}/${n}_R2.fq.gz" or die $!;
my$out2 = Bio::SeqIO->new(-fh => $GZ2 , -format => 'fastq');
my %id;
while ( my $obj1=$fq1->next_seq() and my $obj2=$fq2->next_seq() ) {
my ($id1,$id2)=($obj1->id,$obj2->id);
if(exists $id{$id1}){
next;
}else{
$id{$id1} = 1;
}
$out1->write_seq($obj1);
$out2->write_seq($obj2);
}
}
}


请先 登录 后评论

最佳答案 2019-05-28 17:50

脚本语法有错误吧,你了解一下perl的语法,张贴可能哪里漏掉了;

最好用editplus等专业的文本编辑器编辑perl脚本语言,不要用windows自带的记事本;

请先 登录 后评论

其它 0 个回答