Debian Codegraph @

atac-driver/libatac/atacMatch.C

raw symbols SCIP
1 // This file is part of A2Amapper.
2 // Copyright (c) 2005 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 "atac.H"
20
21 static
22 uint32
23 decodeAtacName(char *atac,
24 char *label) {
25 if (label) {
26 while (*atac && (*atac != ':'))
27 *label++ = *atac++;
28 *label = 0;
29 } else {
30 while (*atac && (*atac != ':'))
31 atac++;
32 }
33 if (*atac)
34 return(strtouint32(atac+1, 0L));
35 return(~uint32ZERO);
36 }
37
38
39 atacMatch::atacMatch(char *line) {
40 decode(line);
41 }
42
43 atacMatch::atacMatch(char *muid,
44 char *puid,
45 uint32 miid,
46 char *t,
47 uint32 i1, uint32 p1, uint32 l1, uint32 f1,
48 uint32 i2, uint32 p2, uint32 l2, uint32 f2) {
49
50 strncpy(matchuid, muid, 16);
51 strncpy(parentuid, puid, 16);
52
53 matchuid[15] = 0;
54 parentuid[15] = 0;
55
56 matchiid = miid;
57
58 type[0] = 0;
59 type[1] = 0;
60 type[2] = 0;
61 type[3] = 0;
62
63 type[0] = t[0];
64 type[1] = t[1];
65 if (t[1])
66 type[2] = t[2];
67
68 iid1 = i1;
69 pos1 = p1;
70 len1 = l1;
71 fwd1 = f1;
72 iid2 = i2;
73 pos2 = p2;
74 len2 = l2;
75 fwd2 = f2;
76 }
77
78 void
79 atacMatch::decode(char *line) {
80 iid1 = 0;
81 pos1 = 0;
82 len1 = 0;
83 fwd1 = 0;
84 iid2 = 0;
85 pos2 = 0;
86 len2 = 0;
87 fwd2 = 0;
88
89 splitToWords S(line);
90
91 iid1 = decodeAtacName(S[4], 0L);
92 pos1 = strtouint32(S[5], 0L);
93 len1 = strtouint32(S[6], 0L);
94 fwd1 = (S[7][0] == '-') ? 0 : 1;
95 iid2 = decodeAtacName(S[8], 0L);
96 pos2 = strtouint32(S[9], 0L);
97 len2 = strtouint32(S[10], 0L);
98 fwd2 = (S[11][0] == '-') ? 0 : 1;
99
100 strncpy(matchuid, S[2], 16);
101 strncpy(parentuid, S[3], 16);
102
103 matchuid[15] = 0;
104 parentuid[15] = 0;
105
106 matchiid = 0;
107
108 type[0] = 0;
109 type[1] = 0;
110 type[2] = 0;
111 type[3] = 0;
112
113 type[0] = S[1][0];
114 type[1] = S[1][1];
115 if (S[1][1])
116 type[2] = S[1][2];
117 }
118
119
120 // Sanity check the match record -- make sure it's within the
121 // sequence itself.
122 //
123 bool
124 atacMatch::sanity(seqCache *A, seqCache *B, char *inLine) {
125
126 bool matchOK = true;
127
128 if (A && B) {
129 if ((pos1) > A->getSequenceLength(iid1) || (pos1 + len1) > A->getSequenceLength(iid1)) {
130 chomp(inLine);
131 fprintf(stderr, "Match longer than sequence (by "uint32FMT"bp) in 1: seqLen="uint32FMTW(8)" %s\n",
132 pos1 + len1 - A->getSequenceLength(iid1),
133 A->getSequenceLength(iid1), inLine);
134 matchOK = false;
135 }
136
137 if ((pos2) > B->getSequenceLength(iid2) || (pos2 + len2) > B->getSequenceLength(iid2)) {
138 chomp(inLine);
139 fprintf(stderr, "Match longer than sequence (by "uint32FMT"bp) in 2: seqLen="uint32FMTW(8)" %s\n",
140 pos2 + len2 - B->getSequenceLength(iid2),
141 B->getSequenceLength(iid2), inLine);
142 matchOK = false;
143 }
144
145 if ((iid1 >= A->getNumberOfSequences()) || (iid2 >= B->getNumberOfSequences())) {
146 chomp(inLine);
147 fprintf(stderr, "Match references invalid sequence iid: %s\n", inLine);
148 matchOK = false;
149 }
150 }
151
152 return(matchOK);
153 }
154