-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassembly_stats.pl
executable file
·140 lines (116 loc) · 2.79 KB
/
assembly_stats.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
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
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/perl -w
use strict;
# USAGE: "cat fasta | getLength.pl"
# Only use unwrapped fasta file
my $max = -1;
my $nnmax = -1;
my $maxSeq = "";
my $nnmaxSeq = "";
my $numSeq = 0;
my $sum = 0;
my $nnsum = 0;
my @lengths;
my @nnlengths;
while (my $line = <STDIN>) {
if ($line =~ /\>/) {
chomp $line;
$numSeq ++;
my $nxtLine = <STDIN>;
chomp $nxtLine;
my $len = length($nxtLine);
push (@lengths, $len);
$sum += $len;
$nxtLine =~ s/[nN]//g;
my $nnlen = length($nxtLine);
push (@nnlengths, $nnlen);
$nnsum += $nnlen;
if ($max == -1 || $max < $len) {
$max = $len;
$maxSeq = $line;
}
if ($nnmax == -1 || $nnmax < $nnlen) {
$nnmax = $nnlen;
$nnmaxSeq = $line;
}
}
}
print "Of total $numSeq sequences:\n";
print "Total length is $sum\n";
print "Total Non-N's length is $nnsum\n";
my @sorted = reverse sort {$a <=> $b} @lengths;
my $count = 0;
my $scount =0;
while (my $slice = shift @sorted) {
$scount++;
$count += $slice;
if ($count > $sum/2) {
print "N50 size is $slice with $scount sequences\n";
last;
}
}
@sorted = reverse sort {$a <=> $b} @lengths;
$count = 0;
$scount =0;
while (my $slice = shift @sorted) {
$count += $slice;
$scount++;
if ($count > $sum*0.9) {
print "N90 size is $slice with $scount sequences\n";
last;
}
}
@sorted = reverse sort {$a <=> $b} @lengths;
$count = 0;
$scount =0;
while (my $slice = shift @sorted) {
$count += $slice;
$scount++;
if ($count > $sum*0.95) {
print "N95 size is $slice with $scount sequences\n";
last;
}
}
@sorted = reverse sort {$a <=> $b} @lengths;
$count = 0;
$scount =0;
while (my $slice = shift @sorted) {
$count += $slice;
$scount++;
if ($count > $sum*0.99) {
print "N99 size is $slice with $scount sequences\n";
last;
}
}
my @nnsorted = reverse sort {$a <=> $b} @nnlengths;
$count = 0;
while (my $slice = shift @nnsorted) {
$count += $slice;
if ($count > $nnsum/2) {
print "Non-N N50 size is $slice\n";
last;
}
}
print "Longest read length is $max from $maxSeq\n";
print "Longest non-N read length is $nnmax from $nnmaxSeq\n";
print "Average length is ", $sum/$numSeq, "\n";
print "Average Non-N length is ", $nnsum/$numSeq, "\n";
@sorted = reverse sort {$a <=> $b} @lengths;
open(my $fh, '>', 'assembly_stats.histo');
foreach(@sorted)
{
print $fh "$_\r\n";
}
close $fh;
print "done\n";
@sorted = reverse sort {$a <=> $b} @lengths;
$count = 0;
$scount =0;
my $percentile=0;
open(my $fj, '>', 'assembly_stats.histo2');
while (my $slice = shift @sorted) {
$scount++;
$count += $slice;
$percentile=$count/$sum;
print $fj "$percentile\t$slice\t$scount\n";
}
close $fj;