Skip to content

Commit b0e096e

Browse files
committed
Fixed error that counts chars in fasta title lines in nucleotide counts.
1 parent 0a0800c commit b0e096e

File tree

1 file changed

+26
-17
lines changed

1 file changed

+26
-17
lines changed

CountRep.cpp

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,42 @@
22
#include <string>
33
#include <vector>
44
using namespace std;
5+
6+
// purpose: Calculate percent assembly masked.
7+
// method: Report number of lower and upper case chars in input.
8+
// input: (assembly) fasta file
9+
// output: <fasta entry header> <(num lowercase chars)/(num total chars)> <num lowercase chars in entry> <num uppercase chars in entry>
10+
511
int main() {
612
long int nl=0, nh=0, other=0;
713

814
string prevTitle = "";
915
while (cin) {
1016
string line;
1117
cin >> line;
12-
if (line.size() > 0 and line[0] == '>') {
13-
if (prevTitle != "") {
14-
int s=nl+nh;
15-
if (s > 0) {
16-
cout << prevTitle << "\t"<< nl / ((float)s) << "\t" << nl << "\t" << nh << endl;
18+
if (line.size() > 0) {
19+
if (line[0] == '>') {
20+
if (prevTitle != "") {
21+
int s=nl+nh;
22+
if (s > 0) {
23+
cout << prevTitle << "\t"<< nl / ((float)s) << "\t" << nl << "\t" << nh << endl;
24+
}
25+
else {
26+
cout << prevTitle << "\t0\t0\t0" << endl;
27+
}
1728
}
18-
else {
19-
cout << prevTitle << "\t0\t0\t0" << endl;
29+
nl=0; nh=0;
30+
prevTitle = line;
31+
} else {
32+
for (int i=0; i < line.size(); i++) {
33+
if (line[i] >= 'a' && line[i] <= 'z') {
34+
nl+=1;
35+
}
36+
else {
37+
nh+=1;
38+
}
2039
}
2140
}
22-
nl=0; nh=0;
23-
prevTitle = line;
24-
}
25-
for (int i=0; i < line.size(); i++) {
26-
if (line[i] >= 'a' && line[i] <= 'z') {
27-
nl+=1;
28-
}
29-
else {
30-
nh+=1;
31-
}
3241
}
3342
}
3443
int s=nl+nh;

0 commit comments

Comments
 (0)