File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -25,8 +25,7 @@ countfa
2525Counts the number of characters per sequence in a fasta file. For each sequence,
2626the name followed by the character count are returned to stdout. The aim is to
2727count sequence lengths without taking up too much memory. To this end, only one
28- line is kept in memory at a time. Though this means that if the sequence is not
29- split up with newlines, the entire thing will be loaded into memory.
28+ character is loaded into memory at a time.
3029
3130Example usage:
3231
Original file line number Diff line number Diff line change @@ -39,6 +39,41 @@ void usage() {
3939
4040void do_countfa (istream &input) {
4141
42+ bool at_name{false };
43+ int counter{0 };
44+ char l;
45+
46+ while (input.get (l)) {
47+
48+ if (l == ' >' ) {
49+ if (counter > 0 ) cout << counter << endl;
50+ at_name = true ;
51+ counter = 0 ;
52+ }
53+
54+ if (l == ' \n ' && at_name) {
55+ at_name = false ;
56+ cout << endl;
57+ }
58+
59+ if (at_name) cout << l;
60+ else {
61+ if (l != ' ' && l != ' \n ' ) ++counter;
62+ }
63+
64+ }
65+
66+ if (!at_name && counter > 0 ) cout << counter << endl;
67+
68+ return ;
69+
70+ }
71+
72+ /*
73+ void do_countfa(istream &input) {
74+
75+ // this version is faster, but potentially loads entire sequence in memory
76+
4277 string name, line;
4378 int counter{0};
4479
@@ -81,6 +116,7 @@ void do_countfa(istream &input) {
81116 }
82117
83118}
119+ */
84120
85121int main (int argc, char **argv) {
86122
You can’t perform that action at this time.
0 commit comments