| 1 | #include "aHit.H" |
| 2 | |
| 3 | #include <stdio.h> |
| 4 | #include <stdlib.h> |
| 5 | |
| 6 | |
| 7 | void ahit_writeBinary(aHit *a, FILE *F) { |
| 8 | fwrite(a, sizeof(aHit), 1, F); |
| 9 | } |
| 10 | |
| 11 | void ahit_readBinary(aHit *a, FILE *F) { |
| 12 | fread(a, sizeof(aHit), 1, F); |
| 13 | } |
| 14 | |
| 15 | void ahit_readBinary(aHit *a, readBuffer *F) { |
| 16 | F->read((char *)a, sizeof(aHit)); |
| 17 | } |
| 18 | |
| 19 | void ahit_printASCII(aHit *a, FILE *F) { |
| 20 | fprintf(F, "-%c -e "uint32FMT" -D "uint32FMT" "uint32FMT" "uint32FMT" -M "uint32FMT" "uint32FMT" "uint32FMT"\n", |
| 21 | a->_forward ? 'f' : 'r', |
| 22 | a->_qsIdx, |
| 23 | a->_dsIdx, |
| 24 | a->_dsLo, |
| 25 | a->_dsHi, |
| 26 | a->_covered, |
| 27 | a->_matched, |
| 28 | a->_numMers); |
| 29 | } |
| 30 | |
| 31 | |
| 32 | // We don't read the string here so that we can use a static buffer |
| 33 | // in whatever loop we read with. |
| 34 | // |
| 35 | // e.g., |
| 36 | // |
| 37 | // char b[1025]; |
| 38 | // while (!feof(I)) { |
| 39 | // fgets(b, 1024, I); |
| 40 | // if (!feof(I)) |
| 41 | // ahit_parseString(a, b); |
| 42 | // } |
| 43 | // |
| 44 | // Note that using sscanf, while easy to implement, and safe |
| 45 | // (looking, anyways), is terribly slow, and not really that safe. |
| 46 | // |
| 47 | // char c; |
| 48 | // sscanf(b, "-%c -e %d -D %d %d %d -M %d %d %d", |
| 49 | // &c, |
| 50 | // &a->_qsIdx, |
| 51 | // &a->_dsIdx, |
| 52 | // &a->_dsLo, |
| 53 | // &a->_dsHi, |
| 54 | // &a->_covered, |
| 55 | // &a->_matched, |
| 56 | // &a->_numMers); |
| 57 | // a->_direction = (c == 'f'); |
| 58 | // |
| 59 | // fast: 138.440u 40.500s 4:04.61 73.1% 0+2k 327822+0io 4pf+0w |
| 60 | // slow: 737.587u 38.652s 13:12.42 97.9% 0+2k 328006+0io 11pf+0w |
| 61 | // |
| 62 | void ahit_parseString(aHit *a, char *b) { |
| 63 | char *c = b+1; |
| 64 | |
| 65 | a->_forward = (*c == 'f'); |
| 66 | |
| 67 | c += 1; |
| 68 | |
| 69 | if (c[2] != 'e') fprintf(stderr, "'%s' didn't get -e\n", b); |
| 70 | |
| 71 | c += 4; |
| 72 | a->_qsIdx = (uint32)strtoul(c, &c, 10); |
| 73 | |
| 74 | // If we get a "-D" next then we are reading search output, |
| 75 | // otherwise, we are (hopefully) reading seatac output. |
| 76 | |
| 77 | if (c[2] == 'D') { |
| 78 | |
| 79 | // searchGENOME format here! |
| 80 | |
| 81 | c += 4; |
| 82 | a->_dsIdx = (uint32)strtoul(c, &c, 10); |
| 83 | a->_dsLo = (uint32)strtoul(c, &c, 10); |
| 84 | a->_dsHi = (uint32)strtoul(c, &c, 10); |
| 85 | |
| 86 | if (c[2] == 'M') { |
| 87 | c += 4; |
| 88 | a->_covered = (uint32)strtoul(c, &c, 10); |
| 89 | a->_matched = (uint32)strtoul(c, &c, 10); |
| 90 | a->_numMers = (uint32)strtoul(c, &c, 10); |
| 91 | } else { |
| 92 | a->_covered = 0; |
| 93 | a->_matched = 0; |
| 94 | a->_numMers = 0; |
| 95 | } |
| 96 | } else { |
| 97 | |
| 98 | // seatac format here! |
| 99 | #if 0 |
| 100 | fprintf(stderr, "seatac?\n"); |
| 101 | |
| 102 | |
| 103 | // We make horrible use of variable names here -- covered and |
| 104 | // matched are the regions on the first sequence, and numMers |
| 105 | // is the "F" value. |
| 106 | |
| 107 | a->_covered = (uint32)strtoul(c, &c, 10); |
| 108 | a->_matched = (uint32)strtoul(c, &c, 10); |
| 109 | |
| 110 | c += 4; |
| 111 | a->_dsIdx = (uint32)strtoul(c, &c, 10); |
| 112 | a->_dsLo = (uint32)strtoul(c, &c, 10); |
| 113 | a->_dsHi = (uint32)strtoul(c, &c, 10); |
| 114 | |
| 115 | c += 4; |
| 116 | a->_numMers = (uint32)strtoul(c, &c, 10); |
| 117 | #endif |
| 118 | } |
| 119 | } |