Debian Codegraph @

atac-driver/gapShifter/cleanAtac.C

raw symbols SCIP
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 atac matches, trims off ends that are mismatch.
27 // Computes the percent identity of the resulting match.
28 // Outputs the trimmed match if it is above some percent identity.
29
30 void
31 usage(char *name) {
32 fprintf(stderr, "usage: %s [-d identity] [-i identity] -m matches\n", name);
33 fprintf(stderr, " -d discard the match if it is below this percent identity\n");
34 }
35
36 int
37 main(int argc, char *argv[]) {
38 char *matchesFile = 0L;
39 double discardThreshold = 0.0;
40 uint32 discardLength = 0;
41
42 int arg=1;
43 while (arg < argc) {
44 if (strcmp(argv[arg], "-m") == 0) {
45 matchesFile = argv[++arg];
46 } else if (strcmp(argv[arg], "-d") == 0) {
47 discardThreshold = atof(argv[++arg]);
48 if (discardThreshold > 1.0)
49 discardThreshold /= 100;
50 } else if (strcmp(argv[arg], "-l") == 0) {
51 discardLength = atoi(argv[++arg]);
52 } else {
53 usage(argv[0]);
54 exit(1);
55 }
56 arg++;
57 }
58
59 if (matchesFile == 0L)
60 usage(argv[0]), exit(1);
61
62 atacFile AF(matchesFile);
63 atacMatchList &ML = *AF.matches();
64 seqCache Acache(AF.assemblyFileA(), 32, false);
65 seqCache Bcache(AF.assemblyFileB(), 32, false);
66
67 for (uint32 i=0; i<ML.numMatches(); i++) {
68 atacMatch *m = ML.getMatch(i);
69
70 uint32 identities = 0;
71
72 //char *a = Acache.getSequenceInCore(m->iid1)->sequence() + m->pos1;
73 //char *b = Bcache.getSequenceInCore(m->iid2)->sequence() + m->pos2;
74 //uint32 p, q;
75
76
77 // Trim the match
78 //
79 if (m->fwd2) {
80 char *a = Acache.getSequenceInCore(m->iid1)->sequence() + m->pos1;
81 char *b = Bcache.getSequenceInCore(m->iid2)->sequence() + m->pos2;
82 uint32 p = 0;
83
84 while ((m->len1 > 0) && (toUpper[(int)a[p]] != toUpper[(int)b[p]])) {
85 m->pos1++;
86 m->pos2++;
87 m->len1--;
88 m->len2--;
89 p++;
90 }
91
92 a = Acache.getSequenceInCore(m->iid1)->sequence() + m->pos1;
93 b = Bcache.getSequenceInCore(m->iid2)->sequence() + m->pos2;
94 p = m->len1-1;
95 while ((m->len1 > 0) && (toUpper[(int)a[p]] != toUpper[(int)b[p]])) {
96 m->len1--;
97 m->len2--;
98 p--;
99 }
100
101 } else {
102 char *a = Acache.getSequenceInCore(m->iid1)->sequence() + m->pos1;
103 char *b = Bcache.getSequenceInCore(m->iid2)->sequence() + m->pos2;
104 uint32 p = 0;
105 uint32 q = m->len2 - 1;
106
107 while ((m->len1 > 0) && (toUpper[(int)a[p]] != complementSymbol[toUpper[(int)b[q]]])) {
108 m->pos1++;
109 m->len1--;
110 m->len2--;
111 p++;
112 q--;
113 }
114
115 a = Acache.getSequenceInCore(m->iid1)->sequence() + m->pos1;
116 b = Bcache.getSequenceInCore(m->iid2)->sequence() + m->pos2;
117 p = m->len1 - 1;
118 q = 0;
119 while ((m->len1 > 0) && (toUpper[(int)a[p]] != complementSymbol[toUpper[(int)b[q]]])) {
120 m->len1--;
121 m->pos2++;
122 m->len2--;
123 p--;
124 q++;
125 }
126 }
127
128 if (m->len1 > 0) {
129 char *a = Acache.getSequenceInCore(m->iid1)->sequence() + m->pos1;
130 char *b = Bcache.getSequenceInCore(m->iid2)->sequence() + m->pos2;
131
132 if (m->fwd2) {
133 for (uint32 p=0; p<m->len1; p++) {
134 if (toUpper[(int)a[p]] == toUpper[(int)b[p]])
135 identities++;
136 }
137 } else {
138 for (uint32 p=0, q=m->len2-1; p<m->len1; p++, q--) {
139 if (toUpper[(int)a[p]] == toUpper[complementSymbol[(int)b[q]]])
140 identities++;
141 }
142 }
143
144 double myIdentity = (double)identities / m->len1;
145
146 if ((myIdentity > discardThreshold) && (m->len1 > discardLength)) {
147 m->print(stdout, AF.labelA(), AF.labelB());
148 } else {
149 fprintf(stderr, "match "uint32FMT" is only %6.2f%% identity and "uint32FMT" long: ",
150 i, 100.0 * identities / m->len1, m->len1);
151 m->print(stderr, AF.labelA(), AF.labelB());
152 if (m->len1 < 200) {
153 char tmp[1000];
154
155 strncpy(tmp, a, m->len1);
156 tmp[m->len1] = 0;
157 fprintf(stderr, " %s\n", tmp);
158
159 strncpy(tmp, b, m->len1);
160 tmp[m->len1] = 0;
161 fprintf(stderr, " %s\n", tmp);
162 }
163 }
164 }
165 }
166
167 return(0);
168 }