-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathN50.cpp
More file actions
57 lines (51 loc) · 1.04 KB
/
N50.cpp
File metadata and controls
57 lines (51 loc) · 1.04 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
#include <fstream>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main(int argc, char ** argv){
if(argc<2){
cout<<"[Fasta file]"<<endl;
exit(0);
}
string input(argv[1]);
srand (time(NULL));
string ref, useless;
ifstream in(input);
vector<uint> lengths;
uint size(0);
while(not in.eof()){
getline(in,useless);
getline(in,ref);
if(not ref.empty() and not useless.empty()){
lengths.push_back(ref.size());
size+=ref.size();
}
}
sort(lengths.begin(),lengths.end(),greater<uint>());
uint total(0),i(0);
while(total<size*0.5){
total+=lengths[i];
++i;
}
cout<<"#contigs: "<<lengths.size()<<endl;
cout<<"Total size: "<<size<<endl;
cout<<"N50: "<<lengths[i-1]<<endl;
cout<<"L50: "<<i<<endl;
total=i=0;
while(total<size*0.80){
total+=lengths[i];
++i;
}
cout<<"N80: "<<lengths[i-1]<<endl;
cout<<"L80: "<<i<<endl;
total=i=0;
while(total<size*0.90){
total+=lengths[i];
++i;
}
cout<<"N90: "<<lengths[i-1]<<endl;
cout<<"L90: "<<i<<endl;
}