Debian Codegraph @

seatac/filter-nop.C

raw symbols SCIP
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4
5 // A very simple seatac filter. It reports the single longest match for each pair.
6 //
7 // Also shows how to use a C++ object as a filter. C is pretty much the same thing.
8
9 #include "bio.h"
10 #include "util++.H"
11
12 extern "C" {
13 void *construct(char *options);
14 void destruct(void *handle);
15 void addHit(void *handle,
16 char orientation,
17 uint32 id1,
18 uint32 pos1,
19 uint32 len1,
20 uint32 id2,
21 uint32 pos2,
22 uint32 len2,
23 uint32 filled);
24 void filter(void *handle);
25 uint64 output(void *handle, FILE *file, uint64 matchid);
26
27 void *constructStats(char *options);
28 void destructStats(void *handle);
29 void addStats(void *handle, void *filterhandle);
30 void showStats(void *handle, FILE *file);
31 }
32
33
34
35 class filterLongest {
36 public:
37 filterLongest(char *n1, char *n2) {
38 fprintf(stderr, "Creating a filterLongest\n");
39 strncpy(name1, n1, 31);
40 strncpy(name2, n2, 31);
41 };
42
43 ~filterLongest() {
44 fprintf(stderr, "Destroyed a filterLongest\n");
45 };
46
47 void addHit(char orientation,
48 uint32 id1,
49 uint32 pos1,
50 uint32 len1,
51 uint32 id2,
52 uint32 pos2,
53 uint32 len2,
54 uint32 filled) {
55
56 if (maxfilled < filled) {
57 fprintf(stderr, "filterNOP-- addHit\n");
58
59 maxfilled = filled;
60 #if 0
61 sprintf(outstring,
62 "-%c -e "uint32FMT" "uint32FMT" "uint32FMT" -D "uint32FMT" "uint32FMT" "uint32FMT" -F "uint32FMT"\n",
63 orientation, id1, pos1, len1, id2, pos2, len2, filled);
64 #endif
65
66 sprintf(outstring,
67 "M x . . %s:"uint32FMT" "uint32FMT" "uint32FMT" 1 %s:"uint32FMT" "uint32FMT" "uint32FMT" %s "uint32FMT"\n",
68 name1, id1, pos1, len1, name2, id2, pos2, len2, (orientation == 'f') ? "1" : "-1", filled);
69 }
70 };
71
72 void filter(void) {
73 fprintf(stderr, "filterNOP-- filter\n");
74 };
75
76 uint64 output(FILE *file, uint64 matchid) {
77 fprintf(stderr, "filterNOP-- output (ignoring matchid)\n");
78 fprintf(file, "%s", outstring);
79 return(matchid);
80 };
81 private:
82 char outstring[512];
83 char name1[32], name2[32];
84 uint32 maxfilled;
85 };
86
87
88
89 class statLongest {
90 public:
91 statLongest() {
92 num = 0;
93 }
94 ~statLongest() {
95 }
96
97 void add(filterLongest *F) {
98 num++;
99 }
100
101 void show(FILE *file) {
102 fprintf(file, "/statObjNum=%d\n", num);
103 }
104
105 private:
106 int num;
107 };
108
109
110
111
112
113
114 void*
115 construct(char *opts) {
116 char *seq1 = "UNK";
117 char *seq2 = "UNK";
118
119 // Parse the options to find the parameters
120 //
121 splitToWords W(opts);
122
123 uint32 arg = 0;
124 while (arg < W.numWords()) {
125 if (strcmp(W.getWord(arg), "-1") == 0) {
126 seq1 = W.getWord(++arg);
127 } else if (strcmp(W.getWord(arg), "-2") == 0) {
128 seq2 = W.getWord(++arg);
129 }
130
131 arg++;
132 }
133
134 return(new filterLongest(seq1, seq2));
135 }
136
137 void
138 destruct(void *handle) {
139 delete (filterLongest *)handle;
140 }
141
142 void
143 addHit(void *handle,
144 char orientation,
145 uint32 id1,
146 uint32 pos1,
147 uint32 len1,
148 uint32 id2,
149 uint32 pos2,
150 uint32 len2,
151 uint32 filled) {
152 ((filterLongest *)handle)->addHit(orientation, id1, pos1, len1, id2, pos2, len2, filled);
153 }
154
155 void
156 filter(void *handle) {
157 ((filterLongest *)handle)->filter();
158 }
159
160 uint64
161 output(void *handle, FILE *file, uint64 matchid) {
162 return(((filterLongest *)handle)->output(file, matchid));
163 }
164
165
166
167
168 void*
169 constructStats(char *options) {
170 return(new statLongest);
171 }
172
173 void
174 destructStats(void *handle) {
175 delete (statLongest *)handle;
176 }
177
178 void
179 addStats(void *handle, void *filterhandle) {
180 ((statLongest *)handle)->add((filterLongest *)filterhandle);
181 }
182
183 void
184 showStats(void *handle, FILE *file) {
185 ((statLongest *)handle)->show(file);
186 }