Skip to content

Commit

Permalink
Fixed error that counts chars in fasta title lines in nucleotide counts.
Browse files Browse the repository at this point in the history
  • Loading branch information
krabbani3 committed Aug 4, 2022
1 parent 0a0800c commit b0e096e
Showing 1 changed file with 26 additions and 17 deletions.
43 changes: 26 additions & 17 deletions CountRep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,42 @@
#include <string>
#include <vector>
using namespace std;

// purpose: Calculate percent assembly masked.
// method: Report number of lower and upper case chars in input.
// input: (assembly) fasta file
// output: <fasta entry header> <(num lowercase chars)/(num total chars)> <num lowercase chars in entry> <num uppercase chars in entry>

int main() {
long int nl=0, nh=0, other=0;

string prevTitle = "";
while (cin) {
string line;
cin >> line;
if (line.size() > 0 and line[0] == '>') {
if (prevTitle != "") {
int s=nl+nh;
if (s > 0) {
cout << prevTitle << "\t"<< nl / ((float)s) << "\t" << nl << "\t" << nh << endl;
if (line.size() > 0) {
if (line[0] == '>') {
if (prevTitle != "") {
int s=nl+nh;
if (s > 0) {
cout << prevTitle << "\t"<< nl / ((float)s) << "\t" << nl << "\t" << nh << endl;
}
else {
cout << prevTitle << "\t0\t0\t0" << endl;
}
}
else {
cout << prevTitle << "\t0\t0\t0" << endl;
nl=0; nh=0;
prevTitle = line;
} else {
for (int i=0; i < line.size(); i++) {
if (line[i] >= 'a' && line[i] <= 'z') {
nl+=1;
}
else {
nh+=1;
}
}
}
nl=0; nh=0;
prevTitle = line;
}
for (int i=0; i < line.size(); i++) {
if (line[i] >= 'a' && line[i] <= 'z') {
nl+=1;
}
else {
nh+=1;
}
}
}
int s=nl+nh;
Expand Down

0 comments on commit b0e096e

Please sign in to comment.