Debian Codegraph @

atac-driver/libatac/atacFeature.C

raw symbols SCIP
1 // This file is part of A2Amapper.
2 // Copyright (c) 2005, 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 static
28 uint32
29 decodeAtacName(char *atac,
30 char *label) {
31 if (label) {
32 while (*atac && (*atac != ':'))
33 *label++ = *atac++;
34 *label = 0;
35 } else {
36 while (*atac && (*atac != ':'))
37 atac++;
38 }
39 if (*atac)
40 return(strtouint32(atac+1, 0L));
41 return(~uint32ZERO);
42 }
43
44
45 atacFeature::atacFeature(char *line) {
46 decode(line);
47 }
48
49
50 atacFeature::atacFeature(char *fuid,
51 char *puid,
52 uint32 fiid,
53 char *t,
54 uint32 i, uint32 p, uint32 l) {
55
56 strcpy(featureuid, fuid);
57 strcpy(parentuid, puid);
58
59 featureuid[15] = 0;
60 parentuid[15] = 0;
61
62 featureiid = fiid;
63
64 type[0] = 0;
65 type[1] = 0;
66 type[2] = 0;
67 type[3] = 0;
68 strcpy(type, t);
69
70 iid = i;
71 pos = p;
72 len = l;
73 }
74
75
76 void
77 atacFeature::decode(char *line) {
78
79 splitToWords W(line);
80
81 strcpy(featureuid, W[2]);
82 strcpy(parentuid, W[3]);
83
84 featureuid[15] = 0;
85 parentuid[15] = 0;
86
87 featureiid = 0;
88
89 type[0] = 0;
90 type[1] = 0;
91 type[2] = 0;
92 type[3] = 0;
93 strcpy(type, W[1]);
94
95 iid = decodeAtacName(W[4], 0L);
96 pos = strtouint32(W[5], 0L);
97 len = strtouint32(W[6], 0L);
98 }
99
100
101 bool
102 atacFeature::sanity(seqCache *A, char *inLine) {
103
104 bool featureOK = true;
105
106 if (A) {
107 if ((pos) > A->getSequenceLength(iid) || (pos + len) > A->getSequenceLength(iid)) {
108 chomp(inLine);
109 fprintf(stderr, "Feature longer than sequence (by "uint32FMT"bp): seqLen="uint32FMTW(8)" %s\n",
110 pos + len - A->getSequenceLength(iid),
111 A->getSequenceLength(iid), inLine);
112 featureOK = false;
113 }
114
115 if (iid >= A->getNumberOfSequences()) {
116 chomp(inLine);
117 fprintf(stderr, "Feature references invalid sequence iid: %s\n", inLine);
118 featureOK = false;
119 }
120 }
121
122 return(featureOK);
123 }