| 1 |
#include <stdio.h> |
| 2 |
#include <stdlib.h> |
| 3 |
|
| 4 |
#include "bio++.H" |
| 5 |
//#include "fasta.H" |
| 6 |
#include "sim4.H" |
| 7 |
|
| 8 |
using namespace std; |
| 9 |
#include <vector> |
| 10 |
|
| 11 |
// |
| 12 |
// Current ESTmapper generated summary is: |
| 13 |
// |
| 14 |
// GOOD: >= 95% identity, >= 80% composite, >= 0 bp |
| 15 |
// cDNA-genomic matches 28715039 matches (24921387 different cDNA and 81 genomic) |
| 16 |
// Matches per cDNA 1.1522 matches/cDNA |
| 17 |
// Matches per genomic 354506.6543 matches/genomic |
| 18 |
// |
| 19 |
// cDNA COUNTS: |
| 20 |
// cDNA: 27440540 |
| 21 |
// cDNA-good: 24921387 ( 90.8196%) |
| 22 |
// cDNA-missing: 26071 ( 0.0950%) |
| 23 |
// cDNA-zero: 2493082 ( 9.0854%) |
| 24 |
// |
| 25 |
// |
| 26 |
// New format / summary should be |
| 27 |
// |
| 28 |
// |
| 29 |
// X% identity coverage: 50 55 60 65 70 75 80 85 90 95 100 |
| 30 |
// sequence-genomic matches %8u %8u %8u %8u %8u %8u %8u %8u %8u %8u %8u |
| 31 |
// Unique sequences %8u %8u %8u %8u %8u %8u %8u %8u %8u %8u %8u |
| 32 |
// Matches per sequence %8u %8u %8u %8u %8u %8u %8u %8u %8u %8u %8u |
| 33 |
// Unique genomic %8u %8u %8u %8u %8u %8u %8u %8u %8u %8u %8u |
| 34 |
// Matches per genomic %8u %8u %8u %8u %8u %8u %8u %8u %8u %8u %8u |
| 35 |
// |
| 36 |
// usage: |
| 37 |
// |
| 38 |
// Report raw numbers at 90, 95, 99 percent identity, 50, 60, 70, 80, 90, |
| 39 |
// 100 percent coverage: |
| 40 |
// summarizePolishes -i 90 95 99 -c 50 60 70 80 90 100 -p polishes-file |
| 41 |
// |
| 42 |
// Report percentages at same |
| 43 |
// summarizePolishes -i 90 95 99 -c 50 60 70 80 90 100 -nf cdna-file -p polishes-file |
| 44 |
// summarizePolishes -i 90 95 99 -c 50 60 70 80 90 100 -n num-seqs -p polishes-file |
| 45 |
// |
| 46 |
// Read from stdin, default to 95 percent identity, 50 percent coverage: |
| 47 |
// summarizePolishes -p - |
| 48 |
// |
| 49 |
// Buckets? Cumulative? Both? If we do buckets with size 1, we'll |
| 50 |
// use lots of space, but be fast. Compute correct bucket sizes on |
| 51 |
// output. 101*101 entries, 6 million sequences -> 190GB. |
| 52 |
// |
| 53 |
// So keep sorted list of values, find first bucket that is <= the |
| 54 |
// match we have. 792MB for the example below (3 %i, 11 %c, 6 million |
| 55 |
// seqs). |
| 56 |
// |
| 57 |
// Read in all %i,%c. Compute each identity x coverage pair |
| 58 |
// separately. 48MB for scores + 24MB for a pair. Memory efficient, |
| 59 |
// maybe not compute efficient. |
| 60 |
// |
| 61 |
|
| 62 |
struct match { |
| 63 |
uint32 _estid; |
| 64 |
uint32 _genid; |
| 65 |
uint32 _identity; |
| 66 |
uint32 _coverage; |
| 67 |
}; |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
void |
| 72 |
readMatches(char *filename, |
| 73 |
vector<match> &matches) { |
| 74 |
|
| 75 |
sim4polishReader *R = 0L; |
| 76 |
|
| 77 |
if ((filename != 0L) && (strcmp(filename, "-") != 0)) { |
| 78 |
|
| 79 |
fprintf(stderr, "Reading matches from '%s'\n", filename); |
| 80 |
R = new sim4polishReader(filename); |
| 81 |
|
| 82 |
} else { |
| 83 |
|
| 84 |
fprintf(stderr, "Reading matches from 'stdin'\n"); |
| 85 |
R = new sim4polishReader("-"); |
| 86 |
} |
| 87 |
|
| 88 |
matches.clear(); |
| 89 |
|
| 90 |
sim4polish *p = 0L; |
| 91 |
|
| 92 |
while (R->nextAlignment(p)) { |
| 93 |
match m; |
| 94 |
|
| 95 |
m._estid = p->_estID; |
| 96 |
m._genid = p->_genID; |
| 97 |
m._identity = p->_percentIdentity; |
| 98 |
m._coverage = p->_querySeqIdentity; |
| 99 |
|
| 100 |
matches.push_back(m); |
| 101 |
} |
| 102 |
|
| 103 |
delete R; |
| 104 |
|
| 105 |
fprintf(stderr, "read %d matches.\n", (int)matches.size()); |
| 106 |
} |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
int |
| 111 |
main(int argc, char **argv) { |
| 112 |
char *polishesFile = 0L; |
| 113 |
uint32 numSeqs = 0; |
| 114 |
char *sequenceFile = 0L;; |
| 115 |
uint32 idLen = 0; |
| 116 |
uint32 id[101] = { 0 }; |
| 117 |
uint32 cvLen = 0; |
| 118 |
uint32 cv[101] = { 0 }; |
| 119 |
bool formatExcel = false; |
| 120 |
|
| 121 |
if (argc == 1) { |
| 122 |
fprintf(stderr, "usage: %s [-excel] [-p polishes-file] [-n num-seqs | -nf seq-file] [-i val ...] [-c val ...]\n", argv[0]); |
| 123 |
exit(1); |
| 124 |
} |
| 125 |
|
| 126 |
int arg = 1; |
| 127 |
while (arg < argc) { |
| 128 |
if (strncmp(argv[arg], "-polishes", 2) == 0) { |
| 129 |
polishesFile = argv[++arg]; |
| 130 |
} else if (strncmp(argv[arg], "-n", 3) == 0) { |
| 131 |
numSeqs = atoi(argv[++arg]); |
| 132 |
} else if (strncmp(argv[arg], "-nf", 3) == 0) { |
| 133 |
sequenceFile = argv[++arg]; |
| 134 |
} else if (strncmp(argv[arg], "-identity", 2) == 0) { |
| 135 |
arg++; |
| 136 |
while ((argv[arg]) && (argv[arg][0] != '-')) |
| 137 |
id[idLen++] = atoi(argv[arg++]); |
| 138 |
arg--; |
| 139 |
} else if (strncmp(argv[arg], "-coverage", 2) == 0) { |
| 140 |
arg++; |
| 141 |
while ((argv[arg]) && (argv[arg][0] != '-')) |
| 142 |
cv[cvLen++] = atoi(argv[arg++]); |
| 143 |
arg--; |
| 144 |
} else if (strncmp(argv[arg], "-excel", 2) == 0) { |
| 145 |
formatExcel=true; |
| 146 |
} |
| 147 |
arg++; |
| 148 |
} |
| 149 |
|
| 150 |
if (polishesFile == 0L) { |
| 151 |
fprintf(stderr, "ERROR: No polishes file specified!\n"); |
| 152 |
exit(1); |
| 153 |
} |
| 154 |
|
| 155 |
if (idLen == 0) { |
| 156 |
fprintf(stderr, "WARNING: Defaulting to 95%% identity.\n"); |
| 157 |
id[idLen++] = 95; |
| 158 |
} |
| 159 |
|
| 160 |
if (cvLen == 0) { |
| 161 |
fprintf(stderr, "WARNING: Defaulting to 50%% coverage.\n"); |
| 162 |
cv[cvLen++] = 50; |
| 163 |
} |
| 164 |
|
| 165 |
|
| 166 |
fprintf(stderr, "Polishes: %s\n", polishesFile); |
| 167 |
fprintf(stderr, "numSeqs: "uint32FMT"\n", numSeqs); |
| 168 |
fprintf(stderr, "sequenceFile: %s\n", sequenceFile); |
| 169 |
fprintf(stderr, "ids: "uint32FMT" -- ", idLen); |
| 170 |
for (uint32 i=0; i<idLen; i++) |
| 171 |
fprintf(stderr, " "uint32FMT"", id[i]); |
| 172 |
fprintf(stderr, "\n"); |
| 173 |
fprintf(stderr, "cvs: "uint32FMT" -- ", cvLen); |
| 174 |
for (uint32 i=0; i<cvLen; i++) |
| 175 |
fprintf(stderr, " "uint32FMT"", cv[i]); |
| 176 |
fprintf(stderr, "\n"); |
| 177 |
|
| 178 |
vector<match> matches; |
| 179 |
|
| 180 |
readMatches(polishesFile, matches); |
| 181 |
|
| 182 |
// Find the largest cDNA and genomic idx |
| 183 |
// |
| 184 |
uint32 estmax = 0; |
| 185 |
uint32 genmax = 0; |
| 186 |
for (uint32 i=0; i<matches.size(); i++) { |
| 187 |
if (estmax < matches[i]._estid) |
| 188 |
estmax = matches[i]._estid; |
| 189 |
if (genmax < matches[i]._genid) |
| 190 |
genmax = matches[i]._genid; |
| 191 |
} |
| 192 |
|
| 193 |
estmax++; |
| 194 |
genmax++; |
| 195 |
|
| 196 |
// Allocate space for statistics |
| 197 |
// |
| 198 |
uint32 *estcounts = new uint32 [estmax]; |
| 199 |
uint32 *gencounts = new uint32 [genmax]; |
| 200 |
uint32 mapped; |
| 201 |
uint32 notmapped; |
| 202 |
uint32 uniqest; |
| 203 |
uint32 uniqgen; |
| 204 |
|
| 205 |
if (formatExcel) { |
| 206 |
fprintf(stdout, "identity\tcoverage\tmapped\tnotmapped\tuniqest\tuniqgen\n"); |
| 207 |
fflush(stdout); |
| 208 |
} |
| 209 |
|
| 210 |
// Foreach identity and each coverage, find how many things |
| 211 |
// are above that level. |
| 212 |
// |
| 213 |
for (uint32 i=0; i<idLen; i++) { |
| 214 |
for (uint32 c=0; c<cvLen; c++) { |
| 215 |
mapped = 0; |
| 216 |
notmapped = 0; |
| 217 |
for (uint32 z=0; z<estmax; z++) |
| 218 |
estcounts[z] = 0; |
| 219 |
for (uint32 z=0; z<genmax; z++) |
| 220 |
gencounts[z] = 0; |
| 221 |
|
| 222 |
for (uint32 z=0; z<matches.size(); z++) { |
| 223 |
if ((id[i] <= matches[z]._identity) && |
| 224 |
(cv[c] <= matches[z]._coverage)) { |
| 225 |
mapped++; |
| 226 |
estcounts[ matches[z]._estid ]++; |
| 227 |
gencounts[ matches[z]._genid ]++; |
| 228 |
} else { |
| 229 |
notmapped++; |
| 230 |
} |
| 231 |
} |
| 232 |
|
| 233 |
uniqest = 0; |
| 234 |
uniqgen = 0; |
| 235 |
|
| 236 |
for (uint32 z=0; z<estmax; z++) |
| 237 |
if (estcounts[z]) |
| 238 |
uniqest++; |
| 239 |
for (uint32 z=0; z<genmax; z++) |
| 240 |
if (gencounts[z]) |
| 241 |
uniqgen++; |
| 242 |
|
| 243 |
if (formatExcel) { |
| 244 |
fprintf(stdout, uint32FMT"\t"uint32FMT"\t"uint32FMT"\t"uint32FMT"\t"uint32FMT"\t"uint32FMT"\n", id[i], cv[c], mapped, notmapped, uniqest, uniqgen); |
| 245 |
fflush(stdout); |
| 246 |
} else { |
| 247 |
fprintf(stdout, uint32FMTW(3)" "uint32FMTW(3)": mapped="uint32FMTW(8)" notmapped="uint32FMTW(8)" est="uint32FMTW(8)" gen="uint32FMTW(8)"\n", id[i], cv[c], mapped, notmapped, uniqest, uniqgen); |
| 248 |
fflush(stdout); |
| 249 |
} |
| 250 |
} |
| 251 |
} |
| 252 |
} |
| 253 |
|