| 1 |
#include "bio++.H" |
| 2 |
#include "seqCache.H" |
| 3 |
|
| 4 |
#include <algorithm> |
| 5 |
|
| 6 |
using namespace std; |
| 7 |
|
| 8 |
|
| 9 |
void |
| 10 |
stats(char *filename, uint64 refLen) { |
| 11 |
seqCache *F = new seqCache(filename); |
| 12 |
|
| 13 |
bool V[256]; |
| 14 |
for (uint32 i=0; i<256; i++) |
| 15 |
V[i] = false; |
| 16 |
V['n'] = true; |
| 17 |
V['N'] = true; |
| 18 |
|
| 19 |
uint32 numSeq = F->getNumberOfSequences(); |
| 20 |
|
| 21 |
uint64 Ss = 0; // actual length of span |
| 22 |
uint64 Rs = 0; // reference length of span |
| 23 |
uint32 *Ls = new uint32 [numSeq]; |
| 24 |
|
| 25 |
uint64 Sb = 0; |
| 26 |
uint64 Rb = 0; |
| 27 |
uint32 *Lb = new uint32 [numSeq]; |
| 28 |
|
| 29 |
for (uint32 i=0; i<numSeq; i++) |
| 30 |
Ls[i] = Lb[i] = 0; |
| 31 |
|
| 32 |
for (uint32 s=0; s<numSeq; s++) { |
| 33 |
seqInCore *S = F->getSequenceInCore(s); |
| 34 |
uint32 len = S->sequenceLength(); |
| 35 |
uint32 span = len; |
| 36 |
uint32 base = len; |
| 37 |
|
| 38 |
for (uint32 pos=1; pos<len; pos++) { |
| 39 |
if (V[S->sequence()[pos]]) |
| 40 |
base--; |
| 41 |
} |
| 42 |
|
| 43 |
Ss += span; |
| 44 |
Sb += base; |
| 45 |
|
| 46 |
Ls[S->getIID()] = span; |
| 47 |
Lb[S->getIID()] = base; |
| 48 |
|
| 49 |
delete S; |
| 50 |
} |
| 51 |
|
| 52 |
if (refLen > 0) { |
| 53 |
Rs = refLen; |
| 54 |
Rb = refLen; |
| 55 |
} else { |
| 56 |
Rs = Ss; |
| 57 |
Rb = Sb; |
| 58 |
} |
| 59 |
|
| 60 |
//qsort(Ls, numSeq, sizeof(uint32), uint32_compare); |
| 61 |
//qsort(Lb, numSeq, sizeof(uint32), uint32_compare); |
| 62 |
|
| 63 |
sort(Ls, Ls + numSeq); |
| 64 |
sort(Lb, Lb + numSeq); |
| 65 |
|
| 66 |
reverse(Ls, Ls + numSeq); |
| 67 |
reverse(Lb, Lb + numSeq); |
| 68 |
|
| 69 |
uint32 n50s[11] = {0}; |
| 70 |
uint32 l50s[11] = {0}; |
| 71 |
|
| 72 |
uint32 n50b[11] = {0}; |
| 73 |
uint32 l50b[11] = {0}; |
| 74 |
|
| 75 |
uint32 sizes[11] = {0}; |
| 76 |
uint32 sizeb[11] = {0}; |
| 77 |
|
| 78 |
for (uint32 i=0; i<11; i++) { |
| 79 |
sizes[i] = i * Rs / 10; |
| 80 |
sizeb[i] = i * Rb / 10; |
| 81 |
//fprintf(stderr, "SIZE %2d s=%d b=%d\n", i, sizes[i], sizeb[i]); |
| 82 |
} |
| 83 |
|
| 84 |
for (uint32 i=0, sum=0, n=1; (i < numSeq) && (n < 11); i++) { |
| 85 |
if ((sum < sizes[n]) && (sizes[n] <= sum + Ls[i])) { |
| 86 |
n50s[n] = Ls[i]; |
| 87 |
l50s[n] = i; |
| 88 |
n++; |
| 89 |
} |
| 90 |
|
| 91 |
sum += Ls[i]; |
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
for (uint32 i=0, sum=0, n=1; (i < numSeq) && (n < 11); i++) { |
| 96 |
if ((sum < sizeb[n]) && (sizeb[n] <= sum + Lb[i])) { |
| 97 |
n50b[n] = Ls[i]; |
| 98 |
l50b[n] = i; |
| 99 |
n++; |
| 100 |
} |
| 101 |
|
| 102 |
sum += Lb[i]; |
| 103 |
} |
| 104 |
|
| 105 |
//for (uint32 i=0, sum=0; sum < Rb/2; i++) { |
| 106 |
//} |
| 107 |
|
| 108 |
fprintf(stdout, "%s\n", F->getSourceName()); |
| 109 |
fprintf(stdout, "\n"); |
| 110 |
fprintf(stdout, "numSeqs "uint32FMT"\n", numSeq); |
| 111 |
fprintf(stdout, "\n"); |
| 112 |
fprintf(stdout, "SPAN (smallest "uint32FMT" largest "uint32FMT")\n", Ls[numSeq-1], Ls[0]); |
| 113 |
for (uint32 i=1; i<10; i++) |
| 114 |
fprintf(stdout, "n"uint32FMT" "uint32FMT" at index "uint32FMT"\n", 10 * i, n50s[i], l50s[i]); |
| 115 |
fprintf(stdout, "totLen "uint64FMTW(10)"\n", Ss); |
| 116 |
fprintf(stdout, "refLen "uint64FMTW(10)"\n", Rs); |
| 117 |
fprintf(stdout, "\n"); |
| 118 |
fprintf(stdout, "BASES (smallest "uint32FMT" largest "uint32FMT")\n", Lb[numSeq-1], Lb[0]); |
| 119 |
for (uint32 i=1; i<10; i++) |
| 120 |
fprintf(stdout, "n"uint32FMT" "uint32FMT" at index "uint32FMT"\n", 10 * i, n50b[i], l50b[i]); |
| 121 |
fprintf(stdout, "totLen "uint64FMTW(10)"\n", Sb); |
| 122 |
fprintf(stdout, "refLen "uint64FMTW(10)"\n", Rb); |
| 123 |
|
| 124 |
delete [] Ls; |
| 125 |
delete [] Lb; |
| 126 |
} |