-
Notifications
You must be signed in to change notification settings - Fork 0
/
Perl_script_to_count_positive_values
130 lines (51 loc) · 1.41 KB
/
Perl_script_to_count_positive_values
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
use strict;
use warnings;
my $file = "229E_O.csv";
my @filearray = ();
my @array_ids = ();
my $thres = 0.5;
#### Abrir archivo como tabular
open (F, $file) or die;
while(my $l = <F>) {
$l =~ s/\n//g;
$l =~ s/\r//g;
my @cols = split(/\s+/, $l); # partir las columnas por "más de un espacio"
next unless (scalar (@cols) == 8); ### si la linea no tiene 6 cols, no se agrega al array
#### almacenar linea
push @filearray, $l;
#### almacenar ID
my $current_id = $cols[0];
push @array_ids, $current_id;
#print "$l\n"; #### DIAG
}
close F;
#### Crear array de IDs no redundante
#print scalar(@filearray); #### DIAG
#print scalar(@array_ids); #### DIAG
#print @array_ids; #### DIAG
my @nr_array_ids = uniq(@array_ids);
#print "\n"; #### DIAG
#print scalar(@nr_array_ids); #### DIAG
#print "\n"; #### DIAG
foreach my $new_id (@nr_array_ids) { ### para cada ID no redundante
my $counter = 0;
my $total = 0;
foreach my $new_L (@filearray) { ### para cada linea del archivo
my @n_cols = split(/\s+/, $new_L);
my $potential = $n_cols[5];
my $idd = $n_cols[0];
if ($new_id eq $idd) {
++$total;
}
if ( ($new_id eq $idd) and ($potential >= $thres) ) {
++$counter;
}
}
print "$new_id\t$counter\t$total\n";
}
exit;
#### SUBRUTINE uniq
sub uniq {
my %seen;
return grep { !$seen{$_}++ } @_;
}