Debian Codegraph @

atac-driver/gapShifter/testAtac.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, computes the percent identity of the
27 // regions, and warns if any identites are low.
28
29 void
30 usage(char *name) {
31 fprintf(stderr, "usage: %s [-d identity] [-i identity] -m matches\n", name);
32 fprintf(stderr, " -i print a warning if a match is below this percent identity\n");
33 }
34
35 int
36 main(int argc, char *argv[]) {
37 char *matchesFile = 0L;
38 double identityLimit = 0.9;
39
40 int arg=1;
41 while (arg < argc) {
42 if (strcmp(argv[arg], "-m") == 0) {
43 matchesFile = argv[++arg];
44 } else if (strcmp(argv[arg], "-i") == 0) {
45 identityLimit = atof(argv[++arg]);
46 if (identityLimit > 1.0)
47 identityLimit /= 100;
48 } else {
49 usage(argv[0]);
50 exit(1);
51 }
52 arg++;
53 }
54
55 if (matchesFile == 0L)
56 usage(argv[0]), exit(1);
57
58 atacFile AF(matchesFile);
59 atacMatchList &ML = *AF.matches();
60 seqCache Acache(AF.assemblyFileA(), 0, false);
61 seqCache Bcache(AF.assemblyFileB(), 0, false);
62
63 Acache.loadAllSequences();
64 Bcache.loadAllSequences();
65
66 for (uint32 i=0; i<ML.numMatches(); i++) {
67 atacMatch *m = ML.getMatch(i);
68
69 uint32 identities = 0;
70
71 char *a = Acache.getSequenceInCore(m->iid1)->sequence() + m->pos1;
72 char *b = Bcache.getSequenceInCore(m->iid2)->sequence() + m->pos2;
73
74 if (m->fwd2) {
75 for (uint32 p=0; p<m->len1; p++) {
76 if (toUpper[(int)a[p]] == toUpper[(int)b[p]])
77 identities++;
78 }
79 } else {
80 for (uint32 p=0, q=m->len2-1; p<m->len1; p++, q--) {
81 if (toUpper[(int)a[p]] == toUpper[complementSymbol[(int)b[q]]])
82 identities++;
83 }
84 }
85
86 double myIdentity = (double)identities / m->len1;
87
88 if (myIdentity < identityLimit) {
89 fprintf(stderr, "match "uint32FMT" is only %6.2f%% identity: ",
90 i, 100.0 * identities / m->len1);
91 m->print(stderr, AF.labelA(), AF.labelB());
92 if (m->len1 < 200) {
93 char tmp[1000];
94
95 strncpy(tmp, a, m->len1);
96 tmp[m->len1] = 0;
97 fprintf(stderr, " %s\n", tmp);
98
99 strncpy(tmp, b, m->len1);
100 tmp[m->len1] = 0;
101 fprintf(stderr, " %s\n", tmp);
102 }
103 }
104 }
105
106 return(0);
107 }