-
Notifications
You must be signed in to change notification settings - Fork 3
/
cat_seed.pl
50 lines (45 loc) · 895 Bytes
/
cat_seed.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/perl -w
use strict;
die "perl $0 <in.list><out-dir><out-number>\n" unless(@ARGV==3);
my ($list , $out , $max) = @ARGV;
my %all;
my %id_all;
open I, "$list" or die;
while(<I>)
{
chomp;
next unless( -s $_);
open N, "gzip -dc $_|" or die;
chomp(my $id = <N>);
my ($abund, $uniq);
($id, $abund, $uniq) = split /:/,$id;
if(exists $id_all{$id}){
$id_all{$id}->[0] += $abund;
$id_all{$id}->[1] += $uniq;
}
else{
$id_all{$id}->[0] = $abund;
$id_all{$id}->[1] = $uniq;
}
while(<N>){
my $r = $_;
my $s = <N>;
if(exists $all{$id}){
$all{$id} .= "$r$s";
}else{
$all{$id} = "$r$s";
}
}
close N;
}
close I;
my $flag = 1;
for(sort {$id_all{$b}->[0] <=> $id_all{$a}->[0]} keys %id_all)
{
last if($flag == $max);
open O, "|gzip >$out/seed.$flag.seq.gz" or die;
print O "$_:$id_all{$_}->[0]:$id_all{$_}->[1]\n";
print O "$all{$_}";
close O;
$flag++;
}