-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathfaSize.pl
99 lines (88 loc) · 1.88 KB
/
faSize.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
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
#!/usr/bin/perl
print "faSize.pl v2: output fasta file stat\n";
$n_200 = 0;
$n_2k = 0;
open(IN, $ARGV[0]) or die"";
$/='>';
<IN>;
while(<IN>){
chomp;
($gene,$seq) = split(/\n/,$_,2);
$seq =~ s/\s+//g;
$infordb{$gene}->{'seq'} = $seq;
$l = length $seq;
if($l>500){
$n_500++;
}
if($l>2000){
$n_2k++;
}
$sum_l += $l;
$infordb{$gene}->{'len'} = $l;
}
close IN;
$num = keys %infordb;
$ave_len = int $sum_l/$num;
foreach $gene(sort {$infordb{$b}->{'len'}<=>$infordb{$a}->{'len'}} keys %infordb){
$l = $infordb{$gene}->{'len'};
push @data, $l;
}
$min = $data[-1];
$max = $data[0];
foreach $gene(sort {$infordb{$b}->{'len'}<=>$infordb{$a}->{'len'}} keys %infordb){
$l = $infordb{$gene}->{'len'};
$tmp += $l;
if($tmp>=$sum_l/2){
$N50 = $l;
last;
}
}
$tmp = 0;
foreach $gene(sort {$infordb{$b}->{'len'}<=>$infordb{$a}->{'len'}} keys %infordb){
$l = $infordb{$gene}->{'len'};
$tmp += $l;
if($tmp>=$sum_l*0.6){
$N60 = $l;
last;
}
}
$tmp = 0;
foreach $gene(sort {$infordb{$b}->{'len'}<=>$infordb{$a}->{'len'}} keys %infordb){
$l = $infordb{$gene}->{'len'};
$tmp += $l;
if($tmp>=$sum_l*0.7){
$N70 = $l;
last;
}
}
$tmp = 0;
foreach $gene(sort {$infordb{$b}->{'len'}<=>$infordb{$a}->{'len'}} keys %infordb){
$l = $infordb{$gene}->{'len'};
$tmp += $l;
if($tmp>=$sum_l*0.8){
$N80 = $l;
last;
}
}
$tmp = 0;
foreach $gene(sort {$infordb{$b}->{'len'}<=>$infordb{$a}->{'len'}} keys %infordb){
$l = $infordb{$gene}->{'len'};
$tmp += $l;
if($tmp>=$sum_l*0.9){
$N90 = $l;
last;
}
}
$tmp = 0;
print "number of seq: $num\n";
print "min length: $min\n";
print "max length: $max\n";
print "total size: $sum_l\n";
print "N90: $N90\n";
print "N80: $N80\n";
print "N70: $N70\n";
print "N60: $N60\n";
print "N50: $N50\n";
print "Average length: $ave_len\n";
print "Total number (>500bp): $n_500\n";
print "Total number (>2kb): $n_2k\n";