| 1 | // This file is part of A2Amapper. |
| 2 | // Copyright (c) 2004 Applera Corporation |
| 3 | // Copyright (c) 2005 The J. Craig Venter Institute |
| 4 | // Author: Clark Mobarry |
| 5 | // Author: Brian Walenz |
| 6 | // |
| 7 | // This program is free software; you can redistribute it and/or modify |
| 8 | // it under the terms of the GNU General Public License as published by |
| 9 | // the Free Software Foundation; either version 2 of the License, or |
| 10 | // (at your option) any later version. |
| 11 | // |
| 12 | // This program is distributed in the hope that it will be useful, |
| 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | // GNU General Public License for more details. |
| 16 | // |
| 17 | // You should have received (LICENSE.txt) a copy of the GNU General Public |
| 18 | // License along with this program; if not, write to the Free Software |
| 19 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 20 | |
| 21 | #include <stdio.h> |
| 22 | #include <stdlib.h> |
| 23 | |
| 24 | #include "heavychains.H" |
| 25 | |
| 26 | #define BUFFERSIZE 1024 |
| 27 | |
| 28 | int main(int argc, char *argv[]) { |
| 29 | int beVerbose = 0; |
| 30 | char *assemblyId1 = 0L; |
| 31 | char *assemblyId2 = 0L; |
| 32 | double minScore = 100.0; // Default minimum of bp filled in a good run. |
| 33 | int maxJump = 100000; // Default maximum intra-run jump allowed in a good run. |
| 34 | char *inFileName = 0L; |
| 35 | char *outFileName = 0L; |
| 36 | |
| 37 | int arg = 1; |
| 38 | while (arg < argc) { |
| 39 | if (strcmp(argv[arg], "-v") == 0) { |
| 40 | beVerbose++; |
| 41 | } else if (strcmp(argv[arg], "-1") == 0) { |
| 42 | assemblyId1 = argv[++arg]; |
| 43 | } else if (strcmp(argv[arg], "-2") == 0) { |
| 44 | assemblyId2 = argv[++arg]; |
| 45 | } else if (strcmp(argv[arg], "-s") == 0) { |
| 46 | minScore = atof(argv[++arg]); |
| 47 | } else if (strcmp(argv[arg], "-j") == 0) { |
| 48 | maxJump = atoi(argv[++arg]); |
| 49 | } else if (strcmp(argv[arg], "-i") == 0) { |
| 50 | inFileName = argv[++arg]; |
| 51 | } else if (strcmp(argv[arg], "-o") == 0) { |
| 52 | outFileName = argv[++arg]; |
| 53 | } else { |
| 54 | fprintf(stderr,"%s : unknown flag '-%s'\n", argv[0], *argv); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | FILE *inpF = fopen(inFileName, "r"); |
| 59 | FILE *outF = fopen(outFileName, "w"); |
| 60 | |
| 61 | fprintf(outF,"! format atac 1.0\n"); |
| 62 | |
| 63 | int old_stra1 = -1; |
| 64 | int old_stra2 = -1; // True strand ordinals are non-negative. |
| 65 | char linebuffer[BUFFERSIZE] = {0}; |
| 66 | long matchid = 0; |
| 67 | |
| 68 | StrandPair *sp = new StrandPair(beVerbose, assemblyId1, assemblyId2, maxJump, minScore); |
| 69 | TheStats *ts = new TheStats(beVerbose, assemblyId1, assemblyId2, maxJump, minScore); |
| 70 | |
| 71 | bool endOfInput = false; |
| 72 | |
| 73 | while (!endOfInput) { |
| 74 | endOfInput = true; |
| 75 | |
| 76 | int new_stra1 = -1; |
| 77 | int new_stra2 = -1; |
| 78 | int xln = 0; |
| 79 | int yln = 0; |
| 80 | int tmp_xlo = 0; |
| 81 | int tmp_ylo = 0; |
| 82 | int tmp_filled = 0; // This is never changed! |
| 83 | char tmp_ori = 0; |
| 84 | |
| 85 | if (fgets(linebuffer, BUFFERSIZE, inpF)) { |
| 86 | endOfInput = false; |
| 87 | |
| 88 | if(linebuffer[0] == 'M') { |
| 89 | char classCode; |
| 90 | char subtype; |
| 91 | char selfId[100]; |
| 92 | char parentId[100]; |
| 93 | char new_ass1[100]; |
| 94 | char new_ass2[100]; |
| 95 | int xfl; |
| 96 | int yfl; |
| 97 | |
| 98 | if (12 != sscanf(linebuffer, |
| 99 | "%c %c %s %s %s %d %d %d %s %d %d %d\n", |
| 100 | &classCode, |
| 101 | &subtype, |
| 102 | selfId, |
| 103 | parentId, |
| 104 | new_ass1, |
| 105 | &tmp_xlo, |
| 106 | &xln, |
| 107 | &xfl, |
| 108 | new_ass2, |
| 109 | &tmp_ylo, |
| 110 | &yln, |
| 111 | &yfl)) { |
| 112 | fprintf(stderr, "WARNING: short read on '%s'\n", linebuffer); |
| 113 | } |
| 114 | |
| 115 | #if 0 |
| 116 | printf("classCode=%c\n", classCode); |
| 117 | printf("subtype =%c\n", subtype); |
| 118 | printf("selfId =%s\n", selfId); |
| 119 | printf("parentId =%s\n", parentId); |
| 120 | printf("new_ass1 =%s\n", new_ass1); |
| 121 | printf("xfl =%d\n", xfl); |
| 122 | printf("new_ass2 =%s\n", new_ass2); |
| 123 | printf("yfl =%d\n", yfl); |
| 124 | #endif |
| 125 | |
| 126 | if ((xfl != 1 && xfl != -1) || |
| 127 | (yfl != 1 && yfl != -1)) { |
| 128 | fprintf(stderr, "ERROR: orientation wrong.\n%s\n", linebuffer); |
| 129 | exit(1); |
| 130 | } |
| 131 | |
| 132 | tmp_ori = (xfl == yfl ? 'f' : 'r'); |
| 133 | |
| 134 | // Parse the IID out of the ID |
| 135 | // |
| 136 | for (char *p = new_ass1; *p; p++) |
| 137 | if (*p == ':') |
| 138 | new_stra1 = atoi(p+1); |
| 139 | |
| 140 | for (char *p = new_ass2; *p; p++) |
| 141 | if (*p == ':') |
| 142 | new_stra2 = atoi(p+1); |
| 143 | |
| 144 | } else if ((linebuffer[0] == '#') || (linebuffer[0] == '!') || (linebuffer[0] == '/')) { |
| 145 | fprintf(stderr,"%s",linebuffer); |
| 146 | } else { |
| 147 | fprintf(stderr, "UNRECOGNIZED: %s", linebuffer); |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | if ((new_stra1 != old_stra1) || |
| 152 | (new_stra2 != old_stra2) || endOfInput) { |
| 153 | sp->process(); |
| 154 | matchid = sp->print(outF, matchid); |
| 155 | |
| 156 | ts->add(sp); |
| 157 | |
| 158 | delete sp; |
| 159 | sp = new StrandPair(beVerbose, assemblyId1, assemblyId2, maxJump, minScore); |
| 160 | } |
| 161 | |
| 162 | // Add the hit to the sp if we just read a point |
| 163 | // |
| 164 | if (linebuffer[0] == 'M') { |
| 165 | sp->addHit(tmp_ori, |
| 166 | new_stra1, tmp_xlo, xln, |
| 167 | new_stra2, tmp_ylo, yln, |
| 168 | tmp_filled); |
| 169 | |
| 170 | old_stra1 = new_stra1; |
| 171 | old_stra2 = new_stra2; |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | ts->add(sp); |
| 176 | ts->show(outF); |
| 177 | |
| 178 | delete sp; |
| 179 | delete ts; |
| 180 | |
| 181 | fclose(inpF); |
| 182 | fclose(outF); |
| 183 | } |