-
Notifications
You must be signed in to change notification settings - Fork 1
/
goods_coverage.pl
62 lines (52 loc) · 1.26 KB
/
goods_coverage.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
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/perl
use strict;
use warnings;
######## PROGRAMA QUE CALCULA EL INDICE DE GOOD (GOODS COVERAGE) A PARTIR DE UN TABLA DE OTUS #######
######## Alejandra Escobar Zepeda, UUSMB, IBt, UNAM
######## 18/Enero/2018
scalar@ARGV == 1 || die "usage: $0 <filtered_OTU_matrix.txt>
";
my $file=$ARGV[0];
## Recorriendo la matriz
open (FILE, $file) or die ("I cannot open the file $file\n");
my $header=<FILE>;
chomp $header;
my @header=split(/\t/, $header);
shift(@header);
my$tamano=scalar@header;
my %singletones=();
my %Total=();
my $indice=0;
while (<FILE>) {
chomp;
my@line=split(/\t/, $_);
shift@line;
foreach my $var (@line){
if ($var == 1) {
if ($singletones{$indice}){
$singletones{$indice}++;
}else{
$singletones{$indice}=1;
}
} elsif ($var > 1){
if ($Total{$indice}){
my $last=$Total{$indice};
my $new=$last+$var;
$Total{$indice}=$new;
}else{
$Total{$indice}=$var;
}
}
$indice++;
}
$indice=0;
}
close(FILE);
open OUT, ">goods_$file" || die ("I cannot create goods_$file\n");
print OUT "Sample\tGoods_coverage\tTotal_singletones\n";
for (my $i=0; $i<$tamano; $i++){
my$total=$Total{$i}+$singletones{$i};
my$good=1-($singletones{$i}/$total);
print OUT "$header[$i]\t$good\t$singletones{$i}\n";
}
close(OUT);