https://github.com/zhangwei2015/IMPre
Raw File
Tip revision: eefd18227a23b8d9b48c10b1e481db9350dd444f authored by Zhang Wei on 16 July 2020, 04:04:08 UTC
Update README.txt
Tip revision: eefd182
Filter_by_depth.pl
#!/usr/bin/perl -w
use strict;

die "perl $0 <in><cut-off>\n" unless(@ARGV==2);

open I, "$ARGV[0]" or die;
my %raw;
my ($abund_s,$uniq_s,$num) = (0,0,0);
while(<I>)
{
	chomp;
	my $id = $_;
	chomp(my $seq=<I>);
	my ($abund,$uniq) = (split /:/,$id)[3,4];
	$raw{$id} = [($abund,$uniq,$seq)];
	$abund_s += $abund;
	$uniq_s += $uniq;
	$num++;
}
close I;

my $cutoff=$ARGV[1];
for(keys %raw){
	my ($abund,$uniq,$seq) = @{$raw{$_}};
	my $abund_r = $abund/$abund_s*100*$num;
	my $uniq_r = $uniq/$uniq_s*100*$num;
	if($abund_r>$cutoff && $uniq_r>$cutoff){
		print "$_\n$seq\n";
	}
	
}
back to top