forked from pfrender-laboratory/epps
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKit_profiling_spp.pl
More file actions
63 lines (53 loc) · 1.47 KB
/
Kit_profiling_spp.pl
File metadata and controls
63 lines (53 loc) · 1.47 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!usr/bin/perl -w
use strict;
die "Usage: perl $0 [uc file] [SAP csv file] [Output]\n" unless (@ARGV == 3);
open (IN, $ARGV[0]) or die "$ARGV[0] $!\n";
open OUT, ">$ARGV[2]" or die "$ARGV[2] $!\n";
open (SP, $ARGV[1]) or die "$ARGV[1] $!\n";
my (%hash, %spp, %sample);
while(<SP>){
chomp;
my @line = split/\;/;
my $spp = $line[-1];
my @id = split/\,/, $line[0];
my $otu = $id[-1];
$otu =~ s/OTU\_//;
$spp =~ s/\,//;
$spp =~ s/\s+/\_/g;
$spp{$otu} = $spp;
}
while(<IN>){
chomp;
my @line = split/\s+/;
my @sample = split /\_/, $line[-2];
pop @sample;
my $sample_id = join "\_", @sample;
$sample{$sample_id} ++;
if($line[-1] eq "*"){
next;
}else{
my @otu = split /\_/, $line[-1];
$hash{$otu[1]}{$sample_id} ++;
}
}
my @samples = sort keys %sample;
my $header = join "\t", @samples;
print OUT "OTU_ID\t$header\tSAP\n";
foreach my $k (sort {$a<=>$b} keys %hash){
print OUT "$k\t";
# foreach my $l (sort keys %{$hash{$k}}){
foreach my $l (@samples){
if($hash{$k}{$l}){
print OUT "$hash{$k}{$l}\t";
}else{
print OUT "0\t";
}
}
if($spp{$k}){
print OUT "$spp{$k}\t";
}else{
print OUT "NA,NA,NA,NA,NA,NA,0,0,0\t";
}
print OUT "\n";
}
print "DONE!";