Perl去重fasta序列

Posted jessepeng

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Perl去重fasta序列相关的知识,希望对你有一定的参考价值。

常规方法

#! usr/bin/perl -w
use strict;
my $input=shift;
my %hash;
open IN,"<$input";
$/=">";
while(<IN>)
    chomp;
    $hash$_=1;

foreach my $key(keys %hash)
    print ">$key";

close IN;

Bioseq模块方法

#!/usr/bin/perl
use Bio::SeqIO;

my $fas=shift @ARGV;
my $IN=Bio::SeqIO->new(-file=>"$fas",-format=>'fasta');
my $OUT=Bio::SeqIO->new(-file=>">New_$fas",-format=>'fasta');
my $check=;
while (my $seq=$IN->next_seq())
    my $id=$seq->id;
    unless($check->$id)
       $check->$id=1;
       $OUT->write_seq($seq);
    

$IN->close();
$OUT->close();
print "Finished!\n";

单行命令

cat cat_allsample.fa |perl -076 -ne 'chomp; print ">$_" unless $c$_++ '|grep -c '>'

以上是关于Perl去重fasta序列的主要内容,如果未能解决你的问题,请参考以下文章