码迷,mamicode.com
首页 > 其他好文 > 详细

Perl去重fasta序列

时间:2019-07-21 18:48:50      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:ast   write   for   foreach   put   usr   cat   grep   format   

常规方法

#! 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序列

标签:ast   write   for   foreach   put   usr   cat   grep   format   

原文地址:https://www.cnblogs.com/jessepeng/p/11221893.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!