| 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 |
|
| 27 |
// Attempts to align unmapped regions. |
| 28 |
// |
| 29 |
// For each unmapped region, we extract the corresponding sequences, |
| 30 |
// sim4db them together, parse the output to make atac-format |
| 31 |
// matches, but of a lower confidence. |
| 32 |
// |
| 33 |
// IDX1 ------------------------------------------ |
| 34 |
// |||||||| |||||||||| |
| 35 |
// IDX2 -A------------\ /--------------B- |
| 36 |
// \ / |
| 37 |
// |
| 38 |
// The nasty case is that IDX1 could be doubly mapped, once by A and |
| 39 |
// once by B. So we also need to label those regions that are mapped |
| 40 |
// multiple times as an even lower confidence. |
| 41 |
// |
| 42 |
// We probably should bias the alignment towards the anchored edge, |
| 43 |
// implying I should use something other than sim4db here. |
| 44 |
// |
| 45 |
// We end up with three confidence classes: |
| 46 |
// 1) mapped by atac itself, 1-to-1 matches |
| 47 |
// 2) mapped by sim4db above, with no conflict, between anchors |
| 48 |
// 3) same as 2, but conflicting |
| 49 |
// |
| 50 |
// Why sim4db? It's splicing model might introduce some noise on the |
| 51 |
// ends (which we'll clean up), but more importantly, the splicing |
| 52 |
// allows us to skip over large blocks of whatever (rearrangement, |
| 53 |
// tandem repeat, etc). And it's also in my source tree and I know |
| 54 |
// how to use it. |
| 55 |
|
| 56 |
|
| 57 |
this is unfinished crap |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
// The below is the main from writing unmatched regions |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
int |
| 67 |
main(int argc, char *argv[]) { |
| 68 |
FILE *Aoutput = 0L; |
| 69 |
FILE *Boutput = 0L; |
| 70 |
char *matchesFile = 0L; |
| 71 |
|
| 72 |
int arg=1; |
| 73 |
while (arg < argc) { |
| 74 |
if (strcmp(argv[arg], "-a") == 0) { |
| 75 |
errno = 0; |
| 76 |
Aoutput = fopen(argv[++arg], "w"); |
| 77 |
if (errno) |
| 78 |
fprintf(stderr, "Failed to open '%s': %s\n", argv[arg], strerror(errno)), exit(1); |
| 79 |
} else if (strcmp(argv[arg], "-b") == 0) { |
| 80 |
errno = 0; |
| 81 |
Boutput = fopen(argv[++arg], "w"); |
| 82 |
if (errno) |
| 83 |
fprintf(stderr, "Failed to open '%s': %s\n", argv[arg], strerror(errno)), exit(1); |
| 84 |
} else if (strcmp(argv[arg], "-m") == 0) { |
| 85 |
matchesFile = argv[++arg]; |
| 86 |
} else { |
| 87 |
fprintf(stderr, "usage: %s -a Aunmatched.fasta -b B.unmatched.fasta < matches\n", argv[0]); |
| 88 |
exit(1); |
| 89 |
} |
| 90 |
arg++; |
| 91 |
} |
| 92 |
|
| 93 |
if ((Aoutput == 0L) || (Boutput == 0L) || (matchesFile == 0L)) { |
| 94 |
fprintf(stderr, "usage: %s -a Aunmatched.fasta -b B.unmatched.fasta < matches\n", argv[0]); |
| 95 |
exit(1); |
| 96 |
} |
| 97 |
|
| 98 |
atacMatchList ML1(matchesFile, 'm', false); |
| 99 |
atacMatchList ML2(matchesFile, 'm', false); |
| 100 |
|
| 101 |
ML1.sort1(); // Sorted by first index |
| 102 |
ML2.sort2(); // Sorted by second index |
| 103 |
|
| 104 |
seqCache *W1 = ML1._seq1; |
| 105 |
seqCache *W2 = ML1._seq2; |
| 106 |
|
| 107 |
|
| 108 |
// For every match, |
| 109 |
// find the match before and the match after, on both axes |
| 110 |
// |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
// Extract unmapped in sequence 1 |
| 116 |
|
| 117 |
ML.sort1(); |
| 118 |
W = ML._seq1; |
| 119 |
W->find(ML[0]->iid1); |
| 120 |
S = W->getSequenceInCore(); |
| 121 |
for (uint32 i=1; i<ML.numMatches(); i++) { |
| 122 |
atacMatch *l = ML[i-1]; |
| 123 |
atacMatch *r = ML[i]; |
| 124 |
|
| 125 |
if (l->iid1 != r->iid1) |
| 126 |
continue; |
| 127 |
|
| 128 |
if (l->iid1 != S->getIID()) { |
| 129 |
delete S; |
| 130 |
W->find(l->iid1); |
| 131 |
S = W->getSequenceInCore(); |
| 132 |
} |
| 133 |
|
| 134 |
// Extract from (l->pos1 + l->len1) to (r->pos1), if it's longer than 20bp |
| 135 |
// |
| 136 |
if (l->pos1 + l->len1 + 20 < r->pos1) |
| 137 |
writeGaplessSequence(Aoutput, |
| 138 |
S, |
| 139 |
l->pos1 + l->len1, |
| 140 |
r->pos1); |
| 141 |
} |
| 142 |
|
| 143 |
// Extract unmapped in sequence 2 |
| 144 |
|
| 145 |
ML.sort2(); |
| 146 |
W = ML._seq2; |
| 147 |
W->find(ML[0]->iid2); |
| 148 |
S = W->getSequenceInCore(); |
| 149 |
for (uint32 i=1; i<ML.numMatches(); i++) { |
| 150 |
atacMatch *l = ML[i-1]; |
| 151 |
atacMatch *r = ML[i]; |
| 152 |
|
| 153 |
if (l->iid2 != r->iid2) |
| 154 |
continue; |
| 155 |
|
| 156 |
if (l->iid2 != S->getIID()) { |
| 157 |
delete S; |
| 158 |
W->find(l->iid2); |
| 159 |
S = W->getSequenceInCore(); |
| 160 |
} |
| 161 |
|
| 162 |
// Extract from (l->pos2 + l->len2) to (r->pos2), if it's longer than 20bp |
| 163 |
// |
| 164 |
if (l->pos2 + l->len2 + 20 < r->pos2) |
| 165 |
writeGaplessSequence(Boutput, |
| 166 |
S, |
| 167 |
l->pos2 + l->len2, |
| 168 |
r->pos2); |
| 169 |
} |
| 170 |
|
| 171 |
|
| 172 |
fclose(Aoutput); |
| 173 |
fclose(Boutput); |
| 174 |
|
| 175 |
return(0); |
| 176 |
} |