| 1 |
#include "posix.H" |
| 2 |
#include <stdio.h> |
| 3 |
#include <stdlib.h> |
| 4 |
#include <unistd.h> |
| 5 |
#include <string.h> |
| 6 |
#include <errno.h> |
| 7 |
#include "aHit.H" |
| 8 |
|
| 9 |
// Filters a hit file based on the length of the genomic region |
| 10 |
|
| 11 |
typedef struct { |
| 12 |
uint32 dir; |
| 13 |
uint32 estID; |
| 14 |
uint32 scfID; |
| 15 |
uint32 scfLo; |
| 16 |
uint32 scfHi; |
| 17 |
} hit_s; |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
int |
| 22 |
main(int argc, char **argv) { |
| 23 |
|
| 24 |
if (argc < 2) { |
| 25 |
fprintf(stderr, "usage: %s ....\n", argv[0]); |
| 26 |
exit(1); |
| 27 |
} |
| 28 |
|
| 29 |
int arg = 1; |
| 30 |
|
| 31 |
// Things for reading hits |
| 32 |
// |
| 33 |
FILE *file; |
| 34 |
char b[1024]; |
| 35 |
aHit a; |
| 36 |
bool isBINARY; |
| 37 |
int histogram[12] = {0}; |
| 38 |
FILE *outf[12]; |
| 39 |
|
| 40 |
outf[0] = fopen("filteredHits.0", "w"); |
| 41 |
outf[1] = fopen("filteredHits.1", "w"); |
| 42 |
outf[2] = fopen("filteredHits.2", "w"); |
| 43 |
outf[3] = fopen("filteredHits.3", "w"); |
| 44 |
outf[4] = fopen("filteredHits.4", "w"); |
| 45 |
outf[5] = fopen("filteredHits.5", "w"); |
| 46 |
outf[6] = fopen("filteredHits.6", "w"); |
| 47 |
outf[7] = fopen("filteredHits.7", "w"); |
| 48 |
outf[8] = fopen("filteredHits.8", "w"); |
| 49 |
outf[9] = fopen("filteredHits.9", "w"); |
| 50 |
outf[10] = fopen("filteredHits.a", "w"); |
| 51 |
outf[11] = fopen("filteredHits.b", "w"); |
| 52 |
|
| 53 |
while (arg < argc) { |
| 54 |
|
| 55 |
// Open the file, fatally failing if we cannot do it. |
| 56 |
// |
| 57 |
errno = 0; |
| 58 |
file = fopen(argv[arg], "r"); |
| 59 |
if (file == 0L) { |
| 60 |
fprintf(stderr, "ESTmapper/filterEST-- ERROR opening '%s'\n%s\n", argv[arg], strerror(errno)); |
| 61 |
exit(1); |
| 62 |
} |
| 63 |
|
| 64 |
// Binary or ASCII input? |
| 65 |
// |
| 66 |
char x = (char)fgetc(file); |
| 67 |
ungetc(x, file); |
| 68 |
|
| 69 |
isBINARY = (x != '-'); |
| 70 |
|
| 71 |
if (isBINARY) |
| 72 |
fprintf(stderr, "reading BINARY hits from '%s'\n", argv[arg]); |
| 73 |
else |
| 74 |
fprintf(stderr, "reading ASCII hits from '%s'\n", argv[arg]); |
| 75 |
|
| 76 |
// Read hits until we run out of space |
| 77 |
// |
| 78 |
while (!feof(file)) { |
| 79 |
if (isBINARY) { |
| 80 |
ahit_readBinary(&a, file); |
| 81 |
} else { |
| 82 |
fgets(b, 1024, file); |
| 83 |
ahit_parseString(&a, b); |
| 84 |
} |
| 85 |
|
| 86 |
// Fill the histogram |
| 87 |
// |
| 88 |
int len = a._dsHi - a._dsLo; |
| 89 |
if (len < 25000) { |
| 90 |
fprintf(outf[0], "-%c -e %u -D %u %u %u\n", a._direction ? 'f' : 'r', a._qsIdx, a._dsIdx, a._dsLo, a._dsHi); |
| 91 |
histogram[0]++; |
| 92 |
} else if (len < 50000) { |
| 93 |
fprintf(outf[1], "-%c -e %u -D %u %u %u\n", a._direction ? 'f' : 'r', a._qsIdx, a._dsIdx, a._dsLo, a._dsHi); |
| 94 |
histogram[1]++; |
| 95 |
} else if (len < 100000) { |
| 96 |
fprintf(outf[2], "-%c -e %u -D %u %u %u\n", a._direction ? 'f' : 'r', a._qsIdx, a._dsIdx, a._dsLo, a._dsHi); |
| 97 |
histogram[2]++; |
| 98 |
} else if (len < 200000) { |
| 99 |
fprintf(outf[3], "-%c -e %u -D %u %u %u\n", a._direction ? 'f' : 'r', a._qsIdx, a._dsIdx, a._dsLo, a._dsHi); |
| 100 |
histogram[3]++; |
| 101 |
} else if (len < 400000) { |
| 102 |
fprintf(outf[4], "-%c -e %u -D %u %u %u\n", a._direction ? 'f' : 'r', a._qsIdx, a._dsIdx, a._dsLo, a._dsHi); |
| 103 |
histogram[4]++; |
| 104 |
} else if (len < 800000) { |
| 105 |
fprintf(outf[5], "-%c -e %u -D %u %u %u\n", a._direction ? 'f' : 'r', a._qsIdx, a._dsIdx, a._dsLo, a._dsHi); |
| 106 |
histogram[5]++; |
| 107 |
} else if (len < 1600000) { |
| 108 |
fprintf(outf[6], "-%c -e %u -D %u %u %u\n", a._direction ? 'f' : 'r', a._qsIdx, a._dsIdx, a._dsLo, a._dsHi); |
| 109 |
histogram[6]++; |
| 110 |
} else if (len < 3200000) { |
| 111 |
fprintf(outf[7], "-%c -e %u -D %u %u %u\n", a._direction ? 'f' : 'r', a._qsIdx, a._dsIdx, a._dsLo, a._dsHi); |
| 112 |
histogram[7]++; |
| 113 |
} else if (len < 6400000) { |
| 114 |
fprintf(outf[8], "-%c -e %u -D %u %u %u\n", a._direction ? 'f' : 'r', a._qsIdx, a._dsIdx, a._dsLo, a._dsHi); |
| 115 |
histogram[8]++; |
| 116 |
} else if (len < 12800000) { |
| 117 |
fprintf(outf[9], "-%c -e %u -D %u %u %u\n", a._direction ? 'f' : 'r', a._qsIdx, a._dsIdx, a._dsLo, a._dsHi); |
| 118 |
histogram[9]++; |
| 119 |
} else if (len < 25600000) { |
| 120 |
fprintf(outf[10], "-%c -e %u -D %u %u %u\n", a._direction ? 'f' : 'r', a._qsIdx, a._dsIdx, a._dsLo, a._dsHi); |
| 121 |
histogram[10]++; |
| 122 |
} else { |
| 123 |
fprintf(outf[11], "-%c -e %u -D %u %u %u\n", a._direction ? 'f' : 'r', a._qsIdx, a._dsIdx, a._dsLo, a._dsHi); |
| 124 |
histogram[11]++; |
| 125 |
} |
| 126 |
} |
| 127 |
|
| 128 |
fclose(file); |
| 129 |
|
| 130 |
arg++; |
| 131 |
} |
| 132 |
|
| 133 |
for (int i=0; i<12; i++) |
| 134 |
fprintf(stderr, "%2d] %d\n", i, histogram[i]); |
| 135 |
|
| 136 |
return(0); |
| 137 |
} |