| 1 | // This file is part of A2Amapper. |
| 2 | // Copyright (c) 2006 J. Craig Venter Institute |
| 3 | // Author: Brian Walenz |
| 4 | // |
| 5 | // This program is free software; you can redistribute it and/or modify |
| 6 | // it under the terms of the GNU General Public License as published by |
| 7 | // the Free Software Foundation; either version 2 of the License, or |
| 8 | // (at your option) any later version. |
| 9 | // |
| 10 | // This program is distributed in the hope that it will be useful, |
| 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | // GNU General Public License for more details. |
| 14 | // |
| 15 | // You should have received (LICENSE.txt) a copy of the GNU General Public |
| 16 | // License along with this program; if not, write to the Free Software |
| 17 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 | |
| 19 | #include <stdio.h> |
| 20 | #include <stdlib.h> |
| 21 | #include <unistd.h> |
| 22 | |
| 23 | #include "bio++.H" |
| 24 | #include "atac.H" |
| 25 | |
| 26 | // Reads a set of matches, coalesces those on the same diagonal. |
| 27 | // Does not preserve runs. |
| 28 | // |
| 29 | // No args, reads stdin, writes stdout. |
| 30 | |
| 31 | int |
| 32 | main(int argc, char *argv[]) { |
| 33 | atacFile AF("-"); |
| 34 | atacMatchOrder MO(*AF.matches()); |
| 35 | atacMatch *l = 0L; |
| 36 | atacMatch *r = 0L; |
| 37 | |
| 38 | MO.sortDiagonal(); |
| 39 | |
| 40 | for (uint32 i=1; i<MO.numMatches(); i++) { |
| 41 | l = MO[i-1]; |
| 42 | r = MO[i]; |
| 43 | |
| 44 | if ((l->iid1 == r->iid1) && |
| 45 | (l->iid2 == r->iid2) && |
| 46 | (l->fwd1 == r->fwd1) && |
| 47 | (l->fwd2 == r->fwd2) && |
| 48 | (l->pos1 + l->len1 == r->pos1) && |
| 49 | (l->pos2 + l->len2 == r->pos2) && |
| 50 | (strcmp(l->type, r->type) == 0) && |
| 51 | (strcmp(l->parentuid, r->parentuid) == 0)) { |
| 52 | |
| 53 | fprintf(stderr, "MERGE:\n"); |
| 54 | l->print(stderr, AF.labelA(), AF.labelB()); |
| 55 | r->print(stderr, AF.labelA(), AF.labelB()); |
| 56 | |
| 57 | l->len1 += r->len1; |
| 58 | l->len2 += r->len2; |
| 59 | |
| 60 | l->print(stderr, AF.labelA(), AF.labelB()); |
| 61 | } else { |
| 62 | l->print(stdout, AF.labelA(), AF.labelB()); |
| 63 | l = 0L; |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | if (l) |
| 68 | l->print(stdout, AF.labelA(), AF.labelB()); |
| 69 | |
| 70 | return(0); |
| 71 | } |