Debian Codegraph @

atac-driver/statsGenerator/statsGenerator.C

raw symbols SCIP
1 // This file is part of A2Amapper.cxx . . $ `<file>/atac-driver/statsGenerator/statsGenerator.C`/
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 // Compute some simple statistics on a set of matches
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <time.h>
24 #include <math.h>
25
26 #include "atac.H"cxx . . $ `<file>/atac-driver/libatac/atac.H`/
27 #include "util++.H"cxx . . $ `<file>/libutil/util++.H`/
28 #include "bio++.H"cxx . . $ `<file>/libbio/bio++.H`/
29 #include "seqCache.H"cxx . . $ `<file>/libseq/seqCache.H`/
30
31 bool noHistogramPlotscxx . . $ noHistogramPlots. = true;
32
33
34 // Sort uint32 backwards
35 int
36 uint32comparecxx . . $ uint32compare(9148c8c3ff42c9d8).(const void *a, const void *b) {
37 const uint32cxx . . $ uint32# A = *((const uint32cxx . . $ uint32# *)a);
38 const uint32cxx . . $ uint32# B = *((const uint32cxx . . $ uint32# *)b);
39 if (A < B) return(1);
40 if (A > B) return(-1);
41 return(0);
42 }
43
44
45 class histogramcxx . . $ histogram# {
46 public:
47 histogramcxx . . $ histogram#histogram(6714b5f2551eea49).(uint64cxx . . $ uint64# blockSize, uint64cxx . . $ uint64# maxSize) {
48 _bcxx . . $ histogram#_b. = blockSize;
49 _mcxx . . $ histogram#_m. = maxSize;
50 _lcxx . . $ histogram#_l. = 0;
51 _hcxx . . $ histogram#_h. = new uint32cxx . . $ uint32# [maxSize / blockSize + 1];
52 for (uint32cxx . . $ uint32# i=0; i<maxSize / blockSize + 1; i++)
53 _hcxx . . $ histogram#_h.[i] = 0;
54 _eLencxx . . $ histogram#_eLen. = 0;
55 _eMaxcxx . . $ histogram#_eMax. = 10240;
56 _ecxx . . $ histogram#_e. = new uint32cxx . . $ uint32# [_eMaxcxx . . $ histogram#_eMax.];
57 };
58 ~cxx . . $ histogram#`~histogram`(ced63f7c635d850d).histogramcxx . . $ histogram#() {
59 delete [] _hcxx . . $ histogram#_h.;
60 delete [] _ecxx . . $ histogram#_e.;
61 };
62
63 void addcxx . . $ histogram#add(2c44cd906ae4e829).(uint64cxx . . $ uint64# x) {
64 if (_eLencxx . . $ histogram#_eLen. >= _eMaxcxx . . $ histogram#_eMax.) {
65 _eMaxcxx . . $ histogram#_eMax. *= 2;
66 uint32cxx . . $ uint32# *e = new uint32cxx . . $ uint32# [_eMaxcxx . . $ histogram#_eMax.];
67 memcpy(e, _ecxx . . $ histogram#_e., sizeof(uint32cxx . . $ uint32#) * _eLencxx . . $ histogram#_eLen.);
68 delete [] _ecxx . . $ histogram#_e.;
69 _ecxx . . $ histogram#_e. = e;
70 }
71 _ecxx . . $ histogram#_e.[_eLencxx . . $ histogram#_eLen.++] = x;
72
73 if (x > _mcxx . . $ histogram#_m.)
74 _lcxx . . $ histogram#_l.++;
75 else
76 _hcxx . . $ histogram#_h.[x/_bcxx . . $ histogram#_b.]++;
77 };
78
79 void showcxx . . $ histogram#show(85c52e162fed56f9).(char const *label) {
80 double average = 0;
81 double stddev = 0;
82
83 for (uint32cxx . . $ uint32# i=0; i<_eLencxx . . $ histogram#_eLen.; i++)
84 average += _ecxx . . $ histogram#_e.[i];
85 average /= _eLencxx . . $ histogram#_eLen.;
86
87 for (uint32cxx . . $ uint32# i=0; i<_eLencxx . . $ histogram#_eLen.; i++)
88 stddev += (_ecxx . . $ histogram#_e.[i] - average) * (_ecxx . . $ histogram#_e.[i] - average);
89 stddev = sqrtcxx . . $ sqrt(fee4f1d22bc8e617).(stddev / _eLencxx . . $ histogram#_eLen.);
90
91 fprintf(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "histogram %s "uint32FMTcxx . . $ `libutil/util.h:65:10`!" items %8.3f average %8.3f std.dev.\n",
92 label, _eLencxx . . $ histogram#_eLen., average, stddev);
93 };
94
95 void dumpcxx . . $ histogram#dump(2fa786934fe80e24).(char const *prefix, char const *label) {
96 if (noHistogramPlotscxx . . $ noHistogramPlots.)
97 return;
98 char filename[1024];
99 sprintf(filename, "%s.%s.histogramdat", prefix, label);
100 FILE *out = fopen(filename, "w");
101 for (uint64cxx . . $ uint64# i=0; i<_mcxx . . $ histogram#_m. / _bcxx . . $ histogram#_b.; i++)
102 fprintf(out, uint64FMTcxx . . $ `libutil/util.h:55:10`!" "uint32FMTcxx . . $ `libutil/util.h:65:10`!"\n", i * _bcxx . . $ histogram#_b., _hcxx . . $ histogram#_h.[i]);
103 fprintf(out, ">"uint64FMTcxx . . $ `libutil/util.h:55:10`!" "uint32FMTcxx . . $ `libutil/util.h:65:10`!"\n", _mcxx . . $ histogram#_m., _lcxx . . $ histogram#_l.);
104 fclose(out);
105 }
106
107 void plotcxx . . $ histogram#plot(2fa786934fe80e24).(char const *prefix, char const *label) {
108
109 if (noHistogramPlotscxx . . $ noHistogramPlots.)
110 return;
111
112 // Find max's of the data
113 uint64cxx . . $ uint64# maxx = 0;
114 uint64cxx . . $ uint64# maxy = 0;
115
116 for (uint64cxx . . $ uint64# i=0; i<_mcxx . . $ histogram#_m. / _bcxx . . $ histogram#_b.; i++) {
117 if (_hcxx . . $ histogram#_h.[i] > 0)
118 maxx = i * _bcxx . . $ histogram#_b.;
119 if (maxy < _hcxx . . $ histogram#_h.[i])
120 maxy = _hcxx . . $ histogram#_h.[i];
121 }
122
123 if ((maxx == 0) || (maxy == 0))
124 return;
125
126 char filename[1024];
127 sprintf(filename, "%s.%s.histogram.gnuplot", prefix, label);
128 FILE *out = fopen(filename, "w");
129 fprintf(out, "set terminal postscript color\n");
130 fprintf(out, "set output \"%s.%s.histogram.ps\"\n", prefix, label);
131 fprintf(out, "set xlabel \"length bp\"\n");
132 fprintf(out, "set ylabel \"number of matches\"\n");
133 fprintf(out, "plot [0:"uint64FMTcxx . . $ `libutil/util.h:55:10`!"][0:"uint64FMTcxx . . $ `libutil/util.h:55:10`!"] \"%s.%s.histogramdat\" using 2 with lines\n",
134 maxx, maxy, prefix, label);
135 fprintf(out, "set output \"%s.%s.histogram.closeup.ps\"\n", prefix, label);
136 fprintf(out, "plot [0:"uint64FMTcxx . . $ `libutil/util.h:55:10`!"][0:"uint64FMTcxx . . $ `libutil/util.h:55:10`!"] \"%s.%s.histogramdat\" using 2 with lines\n",
137 maxx/10, maxy, prefix, label);
138 fprintf(out, "quit\n");
139 fclose(out);
140 sprintf(filename, "gnuplot < %s.%s.histogram.gnuplot", prefix, label);
141 if (systemcxx . . $ system(5c4306d8553b3696).(filename))
142 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Failed to execute '%s'\n", filename);
143 };
144
145
146 private:
147 uint64cxx . . $ uint64# _bcxx . . $ histogram#_b.; // blockSize
148 uint64cxx . . $ uint64# _mcxx . . $ histogram#_m.; // maximum element size
149 uint32cxx . . $ uint32# _lcxx . . $ histogram#_l.; // number of things bigger than _m
150 uint32cxx . . $ uint32# *_hcxx . . $ histogram#_h.; // the histogram
151 uint32cxx . . $ uint32# _eMaxcxx . . $ histogram#_eMax.;
152 uint32cxx . . $ uint32# _eLencxx . . $ histogram#_eLen.;
153 uint32cxx . . $ uint32# *_ecxx . . $ histogram#_e.; // the elements -- for computing the stats;
154 };
155
156
157
158 // Compute the total gapped and ungapped length of the input
159 // sequences. Uses atacMatchList only to access the underlying fasta
160 // sequences.
161 //
162 void
163 totalLengthcxx . . $ totalLength(2d5fc859995a3fb5).(atacFilecxx . . $ atacFile# &AF, seqCachecxx . . $ seqCache# *A, seqCachecxx . . $ seqCache# *B) {
164 uint64cxx . . $ uint64# length1 = 0;
165 uint64cxx . . $ uint64# length2 = 0;
166
167 for (uint32cxx . . $ uint32# i=0; i<A->getNumberOfSequencescxx . . $ seqCache#getNumberOfSequences(db52760e79bf9054).(); i++)
168 length1 += A->getSequenceLengthcxx . . $ seqCache#getSequenceLength(2141b656ce2cc063).(i);
169 for (uint32cxx . . $ uint32# i=0; i<B->getNumberOfSequencescxx . . $ seqCache#getNumberOfSequences(db52760e79bf9054).(); i++)
170 length2 += B->getSequenceLengthcxx . . $ seqCache#getSequenceLength(2141b656ce2cc063).(i);
171
172 fprintf(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "totalLength %s "uint64FMTcxx . . $ `libutil/util.h:55:10`!" %s "uint64FMTcxx . . $ `libutil/util.h:55:10`!" # all letters, including N\n",
173 AF.labelAcxx . . $ atacFileBase#labelA(41208ce6ca65dd58).(), length1,
174 AF.labelBcxx . . $ atacFileBase#labelB(41208ce6ca65dd58).(), length2);
175
176 length1 = 0;
177 length2 = 0;
178 for (uint32cxx . . $ uint32# i=0; i<A->getNumberOfSequencescxx . . $ seqCache#getNumberOfSequences(db52760e79bf9054).(); i++) {
179 seqInCorecxx . . $ seqInCore# *S = A->getSequenceInCorecxx . . $ seqCache#getSequenceInCore(715c05706546271f).(i);
180 char *s = S->sequencecxx . . $ seqInCore#sequence(e7e5aa338b9d5147).();
181 for (uint32cxx . . $ uint32# j=0; j<S->sequenceLengthcxx . . $ seqInCore#sequenceLength(ddd8539a2fcdd4ce).(); j++)
182 if (letterToBits[s[j]] != 0xff)
183 length1++;
184 }
185 for (uint32cxx . . $ uint32# i=0; i<B->getNumberOfSequencescxx . . $ seqCache#getNumberOfSequences(db52760e79bf9054).(); i++) {
186 seqInCorecxx . . $ seqInCore# *S = B->getSequenceInCorecxx . . $ seqCache#getSequenceInCore(715c05706546271f).(i);
187 char *s = S->sequencecxx . . $ seqInCore#sequence(e7e5aa338b9d5147).();
188 for (uint32cxx . . $ uint32# j=0; j<S->sequenceLengthcxx . . $ seqInCore#sequenceLength(ddd8539a2fcdd4ce).(); j++)
189 if (letterToBits[s[j]] != 0xff)
190 length2++;
191 }
192
193 fprintf(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "totalLength %s "uint64FMTcxx . . $ `libutil/util.h:55:10`!" %s "uint64FMTcxx . . $ `libutil/util.h:55:10`!" # ACGT only\n",
194 AF.labelAcxx . . $ atacFileBase#labelA(41208ce6ca65dd58).(), length1,
195 AF.labelBcxx . . $ atacFileBase#labelB(41208ce6ca65dd58).(), length2);
196 }
197
198
199
200
201 uint64cxx . . $ uint64#
202 tandemRepeatACGTLengthcxx . . $ tandemRepeatACGTLength(7fbbe5fded0adf00).(intervalListcxx . . $ intervalList#<uint64cxx . . $ uint64#> &il,
203 uint64cxx . . $ uint64# *offset,
204 seqCachecxx . . $ seqCache# *A) {
205
206 // s -- the sequence
207 // i -- the interval list index
208
209 il.mergecxx . . $ intervalList#merge(cb2f890c2fdad230).();
210 uint64cxx . . $ uint64# length = 0;
211 uint64cxx . . $ uint64# unknown[256] = {0};
212 for (uint32cxx . . $ uint32# i=0, s=0; i<il.numberOfIntervalscxx . . $ intervalList#numberOfIntervals(db52760e79bf9054).(); i++) {
213 while ((offset[s + 1]) <= il.locxx . . $ intervalList#lo(cbb7c2c208bf2972).(i))
214 s++;
215
216 char *S = A->getSequenceInCorecxx . . $ seqCache#getSequenceInCore(715c05706546271f).(s)->sequencecxx . . $ seqInCore#sequence(e7e5aa338b9d5147).();
217
218 uint64cxx . . $ uint64# lo = il.locxx . . $ intervalList#lo(cbb7c2c208bf2972).(i) - offset[s];
219 uint64cxx . . $ uint64# hi = il.hicxx . . $ intervalList#hi(cbb7c2c208bf2972).(i) - offset[s];
220
221 for (uint64cxx . . $ uint64# j=lo; j < hi; j++)
222 if (letterToBits[S[j]] != 0xff)
223 length++;
224 else
225 unknown[S[j]]++;
226 }
227
228 //fprintf(stderr, "tandemRepeatACGTLength: "uint64FMT"\n", length);
229 //for (uint32 i=0; i<256; i++)
230 // if (unknown[i] > 0)
231 // fprintf(stderr, "tandemRepeatACGTLength["uint32FMT"] = "uint64FMT" (%c)\n", i, unknown[i], i);
232
233 return(length);
234 }
235
236
237 uint64cxx . . $ uint64# *
238 buildOffsetcxx . . $ buildOffset(93f70e307e3803fc).(seqCachecxx . . $ seqCache# *F) {
239 uint64cxx . . $ uint64# *offset = new uint64cxx . . $ uint64# [F->getNumberOfSequencescxx . . $ seqCache#getNumberOfSequences(db52760e79bf9054).() + 1];
240 offset[0] = 1000000;
241 for (uint32cxx . . $ uint32# i=0; i<F->getNumberOfSequencescxx . . $ seqCache#getNumberOfSequences(db52760e79bf9054).(); i++)
242 offset[i+1] = offset[i] + F->getSequenceLengthcxx . . $ seqCache#getSequenceLength(2141b656ce2cc063).(i) + 1;
243 return(offset);
244 }
245
246
247 void
248 tandemRepeatStatscxx . . $ tandemRepeatStats(3950462bed0fe964).(atacFileStreamcxx . . $ atacFileStream# &featuresA,
249 atacFileStreamcxx . . $ atacFileStream# &featuresB,
250 atacFilecxx . . $ atacFile# &AF,
251 seqCachecxx . . $ seqCache# *A,
252 seqCachecxx . . $ seqCache# *B) {
253 intervalListcxx . . $ intervalList#<uint64cxx . . $ uint64#> ifacxx . . $ intervalList#intervalList(cb2f890c2fdad230)., ifbcxx . . $ intervalList#intervalList(cb2f890c2fdad230).;
254 intervalListcxx . . $ intervalList#<uint64cxx . . $ uint64#> imacxx . . $ intervalList#intervalList(cb2f890c2fdad230)., imbcxx . . $ intervalList#intervalList(cb2f890c2fdad230).;
255 intervalListcxx . . $ intervalList#<uint64cxx . . $ uint64#> mmacxx . . $ intervalList#intervalList(cb2f890c2fdad230)., mmbcxx . . $ intervalList#intervalList(cb2f890c2fdad230).;
256
257 atacMatchListcxx . . $ atacMatchList# &matches = *AF.matchescxx . . $ atacFile#matches(33e88ebc28d05bce).();
258
259 uint64cxx . . $ uint64# *offset1 = buildOffsetcxx . . $ buildOffset(93f70e307e3803fc).(A);
260 uint64cxx . . $ uint64# *offset2 = buildOffsetcxx . . $ buildOffset(93f70e307e3803fc).(B);
261
262 // ifa, ifb are intervalLists, storing the intervals labeled as
263 // tandem repeats. They are using the offset[] to encode the
264 // entire sequence as one consecutive string.
265 //
266 atacFeaturecxx . . $ atacFeature# *f = 0L;
267 while ((f = featuresA.nextFeaturecxx . . $ atacFileStream#nextFeature(89eb56ca9d01cd3f).("tr")) != 0L)
268 ifa.addcxx . . $ intervalList#add(4d3091562df4e52e).(offset1[f->iidcxx . . $ atacFeature#iid.] + f->poscxx . . $ atacFeature#pos., f->lencxx . . $ atacFeature#len.);
269 while ((f = featuresB.nextFeaturecxx . . $ atacFileStream#nextFeature(89eb56ca9d01cd3f).("tr")) != 0L)
270 ifb.addcxx . . $ intervalList#add(4d3091562df4e52e).(offset2[f->iidcxx . . $ atacFeature#iid.] + f->poscxx . . $ atacFeature#pos., f->lencxx . . $ atacFeature#len.);
271
272
273 // ima, imb, like if?, encode the matches in one string.
274 //
275 for (uint32cxx . . $ uint32# m=0; m<matches.numberOfMatchescxx . . $ atacMatchList#numberOfMatches(db52760e79bf9054).(); m++)
276 ima.addcxx . . $ intervalList#add(4d3091562df4e52e).(offset1[matches[cxx . . $ atacMatchList#`operator[]`(4b949e4d42dbfd78).m]->iid1cxx . . $ atacMatch#iid1.] + (uint64cxx . . $ uint64#)matches[cxx . . $ atacMatchList#`operator[]`(4b949e4d42dbfd78).m]->pos1cxx . . $ atacMatch#pos1., (uint64cxx . . $ uint64#)matches[cxx . . $ atacMatchList#`operator[]`(4b949e4d42dbfd78).m]->len1cxx . . $ atacMatch#len1.);
277 for (uint32cxx . . $ uint32# m=0; m<matches.numberOfMatchescxx . . $ atacMatchList#numberOfMatches(db52760e79bf9054).(); m++)
278 imb.addcxx . . $ intervalList#add(4d3091562df4e52e).(offset2[matches[cxx . . $ atacMatchList#`operator[]`(4b949e4d42dbfd78).m]->iid2cxx . . $ atacMatch#iid2.] + (uint64cxx . . $ uint64#)matches[cxx . . $ atacMatchList#`operator[]`(4b949e4d42dbfd78).m]->pos2cxx . . $ atacMatch#pos2., (uint64cxx . . $ uint64#)matches[cxx . . $ atacMatchList#`operator[]`(4b949e4d42dbfd78).m]->len2cxx . . $ atacMatch#len2.);
279
280
281 fprintf(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "\nTANDEM REPEATS in %s\n", AF.labelAcxx . . $ atacFileBase#labelA(41208ce6ca65dd58).());
282 fprintf(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "numberOfItems "uint64FMTcxx . . $ `libutil/util.h:55:10`!"\n", (uint64cxx . . $ uint64#)ifa.numberOfIntervalscxx . . $ intervalList#numberOfIntervals(db52760e79bf9054).());
283 fprintf(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "totalLength "uint64FMTcxx . . $ `libutil/util.h:55:10`!" # sum of lengths of all features\n", ifa.sumOfLengthscxx . . $ intervalList#sumOfLengths(5f357b03ed472e5e).());
284 ifa.mergecxx . . $ intervalList#merge(cb2f890c2fdad230).();
285 fprintf(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "numberOfItems "uint64FMTcxx . . $ `libutil/util.h:55:10`!" # after merging overlapping regions\n", (uint64cxx . . $ uint64#)ifa.numberOfIntervalscxx . . $ intervalList#numberOfIntervals(db52760e79bf9054).());
286 fprintf(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "coveredLength "uint64FMTcxx . . $ `libutil/util.h:55:10`!" # sequence covered by a feature, including N\n", ifa.sumOfLengthscxx . . $ intervalList#sumOfLengths(5f357b03ed472e5e).());
287 fprintf(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "coveredLength "uint64FMTcxx . . $ `libutil/util.h:55:10`!" # sequence covered by a feature, ACGT only\n", tandemRepeatACGTLengthcxx . . $ tandemRepeatACGTLength(7fbbe5fded0adf00).(ifa, offset1, A));
288 mma.intersectcxx . . $ intervalList#intersect(160b6613b69e38b3).(ifa, ima);
289 fprintf(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "numberOfItems "uint64FMTcxx . . $ `libutil/util.h:55:10`!" # after merging overlapping regions, only in matches\n", (uint64cxx . . $ uint64#)mma.numberOfIntervalscxx . . $ intervalList#numberOfIntervals(db52760e79bf9054).());
290 fprintf(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "inMatches "uint64FMTcxx . . $ `libutil/util.h:55:10`!" # sequence covered by a feature and in a match, including N\n", mma.sumOfLengthscxx . . $ intervalList#sumOfLengths(5f357b03ed472e5e).());
291 fprintf(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "inMatches "uint64FMTcxx . . $ `libutil/util.h:55:10`!" # sequence covered by a feature and in a match, ACGT only\n", tandemRepeatACGTLengthcxx . . $ tandemRepeatACGTLength(7fbbe5fded0adf00).(mma, offset1, A));
292
293
294 fprintf(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "\nTANDEM REPEATS in %s\n", AF.labelBcxx . . $ atacFileBase#labelB(41208ce6ca65dd58).());
295 fprintf(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "numberOfItems "uint64FMTcxx . . $ `libutil/util.h:55:10`!"\n", (uint64cxx . . $ uint64#)ifb.numberOfIntervalscxx . . $ intervalList#numberOfIntervals(db52760e79bf9054).());
296 fprintf(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "totalLength "uint64FMTcxx . . $ `libutil/util.h:55:10`!" # sum of lengths of all features\n", ifb.sumOfLengthscxx . . $ intervalList#sumOfLengths(5f357b03ed472e5e).());
297 ifb.mergecxx . . $ intervalList#merge(cb2f890c2fdad230).();
298 fprintf(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "numberOfItems "uint64FMTcxx . . $ `libutil/util.h:55:10`!" # after merging overlapping regions\n", (uint64cxx . . $ uint64#)ifb.numberOfIntervalscxx . . $ intervalList#numberOfIntervals(db52760e79bf9054).());
299 fprintf(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "coveredLength "uint64FMTcxx . . $ `libutil/util.h:55:10`!" # sequence covered by a feature, including N\n", ifb.sumOfLengthscxx . . $ intervalList#sumOfLengths(5f357b03ed472e5e).());
300 fprintf(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "coveredLength "uint64FMTcxx . . $ `libutil/util.h:55:10`!" # sequence covered by a feature, ACGT only\n", tandemRepeatACGTLengthcxx . . $ tandemRepeatACGTLength(7fbbe5fded0adf00).(ifb, offset2, B));
301 mmb.intersectcxx . . $ intervalList#intersect(160b6613b69e38b3).(ifb, imb);
302 fprintf(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "numberOfItems "uint64FMTcxx . . $ `libutil/util.h:55:10`!" # after merging overlapping regions, only in matches\n", (uint64cxx . . $ uint64#)mmb.numberOfIntervalscxx . . $ intervalList#numberOfIntervals(db52760e79bf9054).());
303 fprintf(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "inMatches "uint64FMTcxx . . $ `libutil/util.h:55:10`!" # sequence covered by a feature and in a match, including N\n", mmb.sumOfLengthscxx . . $ intervalList#sumOfLengths(5f357b03ed472e5e).());
304 fprintf(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "inMatches "uint64FMTcxx . . $ `libutil/util.h:55:10`!" # sequence covered by a feature and in a match, ACGT only\n", tandemRepeatACGTLengthcxx . . $ tandemRepeatACGTLength(7fbbe5fded0adf00).(mmb, offset2, B));
305
306 delete [] offset1;
307 delete [] offset2;
308 }
309
310
311
312 void
313 mappedLengthscxx . . $ mappedLengths(c30d539dd6c0e8a).(atacFilecxx . . $ atacFile# &AF, atacMatchListcxx . . $ atacMatchList# &matches, seqCachecxx . . $ seqCache# *A, seqCachecxx . . $ seqCache# *B, char *prefix) {
314 histogramcxx . . $ histogram# h1cxx . . $ histogram#histogram(6714b5f2551eea49).(100, 1000000);
315 histogramcxx . . $ histogram# h2cxx . . $ histogram#histogram(6714b5f2551eea49).(100, 1000000);
316
317 // For the coverage to work correctly, we need to either have one
318 // intervalList per input sequence, or build a table of the chained
319 // sequence positions.
320 //
321 uint64cxx . . $ uint64# *offset1 = buildOffsetcxx . . $ buildOffset(93f70e307e3803fc).(AF.fastaAcxx . . $ atacFileBase#fastaA(e73a05296fa21060).());
322 uint64cxx . . $ uint64# *offset2 = buildOffsetcxx . . $ buildOffset(93f70e307e3803fc).(AF.fastaBcxx . . $ atacFileBase#fastaB(e73a05296fa21060).());
323
324 intervalListcxx . . $ intervalList#<uint64cxx . . $ uint64#> intervalAcxx . . $ intervalList#intervalList(cb2f890c2fdad230).;
325 intervalListcxx . . $ intervalList#<uint64cxx . . $ uint64#> intervalBcxx . . $ intervalList#intervalList(cb2f890c2fdad230).;
326
327 for (uint32cxx . . $ uint32# m=0; m<matches.numberOfMatchescxx . . $ atacMatchList#numberOfMatches(db52760e79bf9054).(); m++) {
328 intervalA.addcxx . . $ intervalList#add(4d3091562df4e52e).(offset1[matches[cxx . . $ atacMatchList#`operator[]`(4b949e4d42dbfd78).m]->iid1cxx . . $ atacMatch#iid1.] + (uint64cxx . . $ uint64#)matches[cxx . . $ atacMatchList#`operator[]`(4b949e4d42dbfd78).m]->pos1cxx . . $ atacMatch#pos1., (uint64cxx . . $ uint64#)matches[cxx . . $ atacMatchList#`operator[]`(4b949e4d42dbfd78).m]->len1cxx . . $ atacMatch#len1.);
329 intervalB.addcxx . . $ intervalList#add(4d3091562df4e52e).(offset2[matches[cxx . . $ atacMatchList#`operator[]`(4b949e4d42dbfd78).m]->iid2cxx . . $ atacMatch#iid2.] + (uint64cxx . . $ uint64#)matches[cxx . . $ atacMatchList#`operator[]`(4b949e4d42dbfd78).m]->pos2cxx . . $ atacMatch#pos2., (uint64cxx . . $ uint64#)matches[cxx . . $ atacMatchList#`operator[]`(4b949e4d42dbfd78).m]->len2cxx . . $ atacMatch#len2.);
330
331 h1.addcxx . . $ histogram#add(2c44cd906ae4e829).(matches[cxx . . $ atacMatchList#`operator[]`(4b949e4d42dbfd78).m]->len1cxx . . $ atacMatch#len1.);
332 h2.addcxx . . $ histogram#add(2c44cd906ae4e829).(matches[cxx . . $ atacMatchList#`operator[]`(4b949e4d42dbfd78).m]->len2cxx . . $ atacMatch#len2.);
333 }
334
335 fprintf(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "numberOfItems "uint64FMTcxx . . $ `libutil/util.h:55:10`!"\n", (uint64cxx . . $ uint64#)matches.numberOfMatchescxx . . $ atacMatchList#numberOfMatches(db52760e79bf9054).());
336
337 fprintf(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "matchLength %s "uint64FMTcxx . . $ `libutil/util.h:55:10`!" %s "uint64FMTcxx . . $ `libutil/util.h:55:10`!" # Sum of lengths of sequence in matches\n",
338 AF.labelAcxx . . $ atacFileBase#labelA(41208ce6ca65dd58).(), (uint64cxx . . $ uint64#)intervalA.sumOfLengthscxx . . $ intervalList#sumOfLengths(5f357b03ed472e5e).(),
339 AF.labelBcxx . . $ atacFileBase#labelB(41208ce6ca65dd58).(), (uint64cxx . . $ uint64#)intervalB.sumOfLengthscxx . . $ intervalList#sumOfLengths(5f357b03ed472e5e).());
340
341 h1.showcxx . . $ histogram#show(85c52e162fed56f9).("AmatchLength");
342 h2.showcxx . . $ histogram#show(85c52e162fed56f9).("BmatchLength");
343 h1.dumpcxx . . $ histogram#dump(2fa786934fe80e24).(prefix, "AmatchLength"); h1.plotcxx . . $ histogram#plot(2fa786934fe80e24).(prefix, "AmatchLength");
344 h2.dumpcxx . . $ histogram#dump(2fa786934fe80e24).(prefix, "BmatchLength"); h2.plotcxx . . $ histogram#plot(2fa786934fe80e24).(prefix, "BmatchLength");
345
346 intervalA.mergecxx . . $ intervalList#merge(cb2f890c2fdad230).();
347 intervalB.mergecxx . . $ intervalList#merge(cb2f890c2fdad230).();
348
349 fprintf(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "coveredLength %s "uint64FMTcxx . . $ `libutil/util.h:55:10`!" %s "uint64FMTcxx . . $ `libutil/util.h:55:10`!" # sequence covered by a match, including N\n",
350 AF.labelAcxx . . $ atacFileBase#labelA(41208ce6ca65dd58).(), (uint64cxx . . $ uint64#)intervalA.sumOfLengthscxx . . $ intervalList#sumOfLengths(5f357b03ed472e5e).(),
351 AF.labelBcxx . . $ atacFileBase#labelB(41208ce6ca65dd58).(), (uint64cxx . . $ uint64#)intervalB.sumOfLengthscxx . . $ intervalList#sumOfLengths(5f357b03ed472e5e).());
352
353 fprintf(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "coveredLength %s "uint64FMTcxx . . $ `libutil/util.h:55:10`!" %s "uint64FMTcxx . . $ `libutil/util.h:55:10`!" # sequence covered by a match, ACGT only (new)\n",
354 AF.labelAcxx . . $ atacFileBase#labelA(41208ce6ca65dd58).(), tandemRepeatACGTLengthcxx . . $ tandemRepeatACGTLength(7fbbe5fded0adf00).(intervalA, offset1, A),
355 AF.labelBcxx . . $ atacFileBase#labelB(41208ce6ca65dd58).(), tandemRepeatACGTLengthcxx . . $ tandemRepeatACGTLength(7fbbe5fded0adf00).(intervalB, offset2, B));
356
357 delete [] offset1;
358 delete [] offset2;
359 }
360
361
362
363 // Generate an Nx plot
364 void
365 NxOfMappedcxx . . $ NxOfMapped(8373d9e8c81ce31c).(atacFilecxx . . $ atacFile# &AF,
366 atacMatchListcxx . . $ atacMatchList# &matches,
367 uint64cxx . . $ uint64# genomeSize,
368 char *prefix) {
369
370 uint32cxx . . $ uint32# *n50 = new uint32cxx . . $ uint32# [matches.numberOfMatchescxx . . $ atacMatchList#numberOfMatches(db52760e79bf9054).()];
371
372 for (uint32cxx . . $ uint32# i=0; i<matches.numberOfMatchescxx . . $ atacMatchList#numberOfMatches(db52760e79bf9054).(); i++)
373 n50[i] = matches[cxx . . $ atacMatchList#`operator[]`(4b949e4d42dbfd78).i]->len1cxx . . $ atacMatch#len1.;
374
375 // Compute the total length of the sequence
376 uint64cxx . . $ uint64# totalLength = 0;
377 switch (genomeSize) {
378 case 0:
379 for (uint32cxx . . $ uint32# i=0; i<AF.fastaAcxx . . $ atacFileBase#fastaA(e73a05296fa21060).()->getNumberOfSequencescxx . . $ seqCache#getNumberOfSequences(db52760e79bf9054).(); i++)
380 totalLength += AF.fastaAcxx . . $ atacFileBase#fastaA(e73a05296fa21060).()->getSequenceLengthcxx . . $ seqCache#getSequenceLength(2141b656ce2cc063).(i);
381 break;
382 case 1:
383 for (uint32cxx . . $ uint32# i=0; i<AF.fastaBcxx . . $ atacFileBase#fastaB(e73a05296fa21060).()->getNumberOfSequencescxx . . $ seqCache#getNumberOfSequences(db52760e79bf9054).(); i++)
384 totalLength += AF.fastaBcxx . . $ atacFileBase#fastaB(e73a05296fa21060).()->getSequenceLengthcxx . . $ seqCache#getSequenceLength(2141b656ce2cc063).(i);
385 break;
386 default:
387 totalLength = genomeSize;
388 break;
389 }
390
391 // Sort the n50 list of lengths
392 qsortcxx . . $ qsort(ebb60b13a65e77d7).(n50, matches.numberOfMatchescxx . . $ atacMatchList#numberOfMatches(db52760e79bf9054).(), sizeof(uint32cxx . . $ uint32#), uint32comparecxx . . $ uint32compare(9148c8c3ff42c9d8).);
393
394 // It's slow and obvious and, yes, there is a better way. Dump the
395 // Nx plot as it's being generated.
396 //
397 char filename[1024];
398 sprintf(filename, "%s.Nx", prefix);
399 FILE *out = fopen(filename, "w");
400
401 for (uint64cxx . . $ uint64# n=1; n<100; n++) {
402 uint64cxx . . $ uint64# limit = totalLength / 100 * n;
403 uint64cxx . . $ uint64# iter = 0;
404 uint64cxx . . $ uint64# sum = 0;
405
406 while ((sum < limit) && (iter < matches.numberOfMatchescxx . . $ atacMatchList#numberOfMatches(db52760e79bf9054).()))
407 sum += n50[iter++];
408
409 fprintf(out, uint64FMTcxx . . $ `libutil/util.h:55:10`!" "uint32FMTcxx . . $ `libutil/util.h:65:10`!"\n", n, n50[iter-1]);
410 }
411
412 fclose(out);
413
414 // Now plot it.
415 //
416 if (noHistogramPlotscxx . . $ noHistogramPlots. == false) {
417 sprintf(filename, "%s.Nx.gnuplot", prefix);
418 out = fopen(filename, "w");
419 fprintf(out, "set terminal postscript color\n");
420 fprintf(out, "set output \"%s.Nx.ps\"\n", prefix);
421 fprintf(out, "set xlabel \"N\"\n");
422 fprintf(out, "set ylabel \"match length\"\n");
423 fprintf(out, "plot \"%s.Nx\" using 2 with lines\n", prefix);
424 fclose(out);
425 sprintf(filename, "gnuplot < %s.Nx.gnuplot", prefix);
426 if (systemcxx . . $ system(5c4306d8553b3696).(filename))
427 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Failed to execute '%s'\n", filename);
428 }
429
430 delete [] n50;
431 }
432
433
434 // Computes the percentage of each chromosome (assumes chromosomes are A)
435 // that is mapped, with and without N's.
436 //
437 void
438 MappedByChromosomecxx . . $ MappedByChromosome(c30d539dd6c0e8a).(atacFilecxx . . $ atacFile# &AF,
439 atacMatchListcxx . . $ atacMatchList# &matches,
440 seqCachecxx . . $ seqCache# *A,
441 seqCachecxx . . $ seqCache# *B,
442 char *prefix) {
443
444 uint32cxx . . $ uint32# maxIID1 = A->getNumberOfSequencescxx . . $ seqCache#getNumberOfSequences(db52760e79bf9054).();
445 intervalListcxx . . $ intervalList#<uint64cxx . . $ uint64#> *il1full;
446 intervalListcxx . . $ intervalList#<uint64cxx . . $ uint64#> *il1acgt;
447 histogramcxx . . $ histogram# **hist1full;
448 histogramcxx . . $ histogram# **hist1acgt;
449
450 if (A->getNumberOfSequencescxx . . $ seqCache#getNumberOfSequences(db52760e79bf9054).() > 24) {
451 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "WARNING: too many sequences to be chromosomes, only using the first 24.\n");
452 maxIID1 = 24;
453 }
454
455 // We could cache this when we compute the totalLength() above
456 uint64cxx . . $ uint64# *nonNlength = new uint64cxx . . $ uint64# [maxIID1+1];
457 for (uint32cxx . . $ uint32# i=0; i<maxIID1; i++) {
458 seqInCorecxx . . $ seqInCore# *S = A->getSequenceInCorecxx . . $ seqCache#getSequenceInCore(715c05706546271f).(i);
459 char *s = S->sequencecxx . . $ seqInCore#sequence(e7e5aa338b9d5147).();
460 nonNlength[i] = 0;
461 for (uint32cxx . . $ uint32# j=0; j<S->sequenceLengthcxx . . $ seqInCore#sequenceLength(ddd8539a2fcdd4ce).(); j++)
462 if (letterToBits[s[j]] != 0xff)
463 nonNlength[i]++;
464 }
465
466 il1full = new intervalListcxx . . $ intervalList#<uint64cxx . . $ uint64#> [maxIID1 + 1];
467 il1acgt = new intervalListcxx . . $ intervalList#<uint64cxx . . $ uint64#> [maxIID1 + 1];
468
469 hist1full = new histogramcxx . . $ histogram# * [maxIID1 + 1];
470 hist1acgt = new histogramcxx . . $ histogram# * [maxIID1 + 1];
471
472 for (uint32cxx . . $ uint32# i=0; i<maxIID1; i++) {
473 hist1full[i] = new histogramcxx . . $ histogram#(100, 1000000);
474 hist1acgt[i] = new histogramcxx . . $ histogram#(100, 1000000);
475 }
476
477 for (uint32cxx . . $ uint32# m=0; m<matches.numberOfMatchescxx . . $ atacMatchList#numberOfMatches(db52760e79bf9054).(); m++) {
478 if (matches[cxx . . $ atacMatchList#`operator[]`(4b949e4d42dbfd78).m]->iid1cxx . . $ atacMatch#iid1. < maxIID1) {
479 il1full[matches[cxx . . $ atacMatchList#`operator[]`(4b949e4d42dbfd78).m]->iid1cxx . . $ atacMatch#iid1.].addcxx . . $ intervalList#add(4d3091562df4e52e).(matches[cxx . . $ atacMatchList#`operator[]`(4b949e4d42dbfd78).m]->pos1cxx . . $ atacMatch#pos1., matches[cxx . . $ atacMatchList#`operator[]`(4b949e4d42dbfd78).m]->len1cxx . . $ atacMatch#len1.);
480 hist1full[matches[cxx . . $ atacMatchList#`operator[]`(4b949e4d42dbfd78).m]->iid1cxx . . $ atacMatch#iid1.]->addcxx . . $ histogram#add(2c44cd906ae4e829).(matches[cxx . . $ atacMatchList#`operator[]`(4b949e4d42dbfd78).m]->len1cxx . . $ atacMatch#len1.);
481
482 seqInCorecxx . . $ seqInCore# *Sa = A->getSequenceInCorecxx . . $ seqCache#getSequenceInCore(715c05706546271f).(matches[cxx . . $ atacMatchList#`operator[]`(4b949e4d42dbfd78).m]->iid1cxx . . $ atacMatch#iid1.);
483 char *sa = Sa->sequencecxx . . $ seqInCore#sequence(e7e5aa338b9d5147).() + matches[cxx . . $ atacMatchList#`operator[]`(4b949e4d42dbfd78).m]->pos1cxx . . $ atacMatch#pos1.;
484
485 uint32cxx . . $ uint32# length = 0;
486
487 for (uint32cxx . . $ uint32# j=0; j<matches[cxx . . $ atacMatchList#`operator[]`(4b949e4d42dbfd78).m]->len1cxx . . $ atacMatch#len1.; j++) {
488 bool invalid = (letterToBits[sa[j]] == 0xff);
489
490 if (!invalid)
491 length++;
492
493 if (length && invalid) { // Last time we were ACGT, this time not.
494 il1acgt[matches[cxx . . $ atacMatchList#`operator[]`(4b949e4d42dbfd78).m]->iid1cxx . . $ atacMatch#iid1.].addcxx . . $ intervalList#add(4d3091562df4e52e).(matches[cxx . . $ atacMatchList#`operator[]`(4b949e4d42dbfd78).m]->pos1cxx . . $ atacMatch#pos1. + j - length, length);
495 hist1acgt[matches[cxx . . $ atacMatchList#`operator[]`(4b949e4d42dbfd78).m]->iid1cxx . . $ atacMatch#iid1.]->addcxx . . $ histogram#add(2c44cd906ae4e829).(length);
496 length = 0;
497 }
498 }
499 if (length) {
500 il1acgt[matches[cxx . . $ atacMatchList#`operator[]`(4b949e4d42dbfd78).m]->iid1cxx . . $ atacMatch#iid1.].addcxx . . $ intervalList#add(4d3091562df4e52e).(matches[cxx . . $ atacMatchList#`operator[]`(4b949e4d42dbfd78).m]->pos1cxx . . $ atacMatch#pos1. + matches[cxx . . $ atacMatchList#`operator[]`(4b949e4d42dbfd78).m]->len1cxx . . $ atacMatch#len1. - length, length);
501 hist1acgt[matches[cxx . . $ atacMatchList#`operator[]`(4b949e4d42dbfd78).m]->iid1cxx . . $ atacMatch#iid1.]->addcxx . . $ histogram#add(2c44cd906ae4e829).(length);
502 }
503 }
504 }
505
506 for (uint32cxx . . $ uint32# c=0; c<maxIID1; c++) {
507 fprintf(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "chrCoveredLength["uint32FMTWcxx . . $ `libutil/util.h:64:10`!(2)"] %s "uint64FMTcxx . . $ `libutil/util.h:55:10`!" "uint64FMTcxx . . $ `libutil/util.h:55:10`!" %6.2f%% "uint64FMTcxx . . $ `libutil/util.h:55:10`!" "uint64FMTcxx . . $ `libutil/util.h:55:10`!" %6.2f%% # seqCov, totalSeq for both ALL and ACGTonly\n",
508 c, AF.labelAcxx . . $ atacFileBase#labelA(41208ce6ca65dd58).(),
509 il1full[c].sumOfLengthscxx . . $ intervalList#sumOfLengths(5f357b03ed472e5e).(), (uint64cxx . . $ uint64#)A->getSequenceLengthcxx . . $ seqCache#getSequenceLength(2141b656ce2cc063).(c), 100.0 * il1full[c].sumOfLengthscxx . . $ intervalList#sumOfLengths(5f357b03ed472e5e).() / A->getSequenceLengthcxx . . $ seqCache#getSequenceLength(2141b656ce2cc063).(c),
510 il1acgt[c].sumOfLengthscxx . . $ intervalList#sumOfLengths(5f357b03ed472e5e).(), nonNlength[c], 100.0 * il1acgt[c].sumOfLengthscxx . . $ intervalList#sumOfLengths(5f357b03ed472e5e).() / nonNlength[c]);
511 }
512
513 for (uint32cxx . . $ uint32# c=0; c<maxIID1; c++) {
514 char label[1024];
515
516 sprintf(label, "chr"uint32FMTWcxx . . $ `libutil/util.h:64:10`!(02)"full", c);
517 hist1full[c]->dumpcxx . . $ histogram#dump(2fa786934fe80e24).(prefix, label);
518 hist1full[c]->plotcxx . . $ histogram#plot(2fa786934fe80e24).(prefix, label);
519
520 sprintf(label, "chr"uint32FMTWcxx . . $ `libutil/util.h:64:10`!(02)"acgt", c);
521 hist1acgt[c]->dumpcxx . . $ histogram#dump(2fa786934fe80e24).(prefix, label);
522 hist1acgt[c]->plotcxx . . $ histogram#plot(2fa786934fe80e24).(prefix, label);
523 }
524
525 delete [] il1full;
526 delete [] il1acgt;
527 for (uint32cxx . . $ uint32# i=0; i<maxIID1; i++) {
528 delete hist1full[i];
529 delete hist1acgt[i];
530 }
531 delete [] hist1full;
532 delete [] hist1acgt;
533 delete [] nonNlength;
534 }
535
536
537
538
539
540
541 void
542 statsInACGTcxx . . $ statsInACGT(f9929111816030f8).(seqInCorecxx . . $ seqInCore# *S,
543 uint32cxx . . $ uint32# beg,
544 uint32cxx . . $ uint32# len,
545 intervalListcxx . . $ intervalList#<uint64cxx . . $ uint64#> *IL,
546 histogramcxx . . $ histogram# *HI) {
547 char *s = S->sequencecxx . . $ seqInCore#sequence(e7e5aa338b9d5147).() + beg;
548 uint32cxx . . $ uint32# length = 0;
549
550 for (uint32cxx . . $ uint32# j=0; j<len; j++) {
551 bool invalid = (letterToBits[s[j]] == 0xff);
552
553 if (!invalid)
554 length++;
555
556 if (length && invalid) { // Last time we were ACGT, this time not.
557 if (IL) IL->addcxx . . $ intervalList#add(4d3091562df4e52e).(beg + j - length, length);
558 if (HI) HI->addcxx . . $ histogram#add(2c44cd906ae4e829).(length);
559 length = 0;
560 }
561 }
562 if (length) {
563 if (IL) IL->addcxx . . $ intervalList#add(4d3091562df4e52e).(beg + len - length, length);
564 if (HI) HI->addcxx . . $ histogram#add(2c44cd906ae4e829).(length);
565 }
566 }
567
568
569
570
571 // Computes the amount of ACGT in runs that is unmapped
572 //
573 void
574 unmappedInRunscxx . . $ unmappedInRuns(be726ad975d118fc).(atacFilecxx . . $ atacFile# &AF, seqCachecxx . . $ seqCache# *A, seqCachecxx . . $ seqCache# *B, char *prefix) {
575
576 atacMatchListcxx . . $ atacMatchList# &matches = *AF.matchescxx . . $ atacFile#matches(33e88ebc28d05bce).();
577
578 // We must sort by the location and not the parentID; when we
579 // stream through, we check that the pair of matches are in the
580 // same parent.
581 //
582 atacMatchOrdercxx . . $ atacMatchOrder# MOcxx . . $ atacMatchOrder#atacMatchOrder(f3ef1525738b52af).(matches);
583 MO.sortAcxx . . $ atacMatchOrder#sortA(b4d55b1286ff73e8).();
584
585 intervalListcxx . . $ intervalList#<uint64cxx . . $ uint64#> il1fullcxx . . $ intervalList#intervalList(cb2f890c2fdad230)., il2fullcxx . . $ intervalList#intervalList(cb2f890c2fdad230).;
586 intervalListcxx . . $ intervalList#<uint64cxx . . $ uint64#> il1acgtcxx . . $ intervalList#intervalList(cb2f890c2fdad230)., il2acgtcxx . . $ intervalList#intervalList(cb2f890c2fdad230).;
587
588 histogramcxx . . $ histogram# hist1fullcxx . . $ histogram#histogram(6714b5f2551eea49).(100, 1000000), hist2fullcxx . . $ histogram#histogram(6714b5f2551eea49).(100, 1000000);
589 histogramcxx . . $ histogram# hist1acgtcxx . . $ histogram#histogram(6714b5f2551eea49).(100, 1000000), hist2acgtcxx . . $ histogram#histogram(6714b5f2551eea49).(100, 1000000);
590
591 for (uint32cxx . . $ uint32# i=1; i<MO.numberOfMatchescxx . . $ atacMatchOrder#numberOfMatches(db52760e79bf9054).(); i++) {
592 if (strcmp(MO[cxx . . $ atacMatchOrder#`operator[]`(4b949e4d42dbfd78).i-1]->parentuidcxx . . $ atacMatch#parentuid., MO[cxx . . $ atacMatchOrder#`operator[]`(4b949e4d42dbfd78).i]->parentuidcxx . . $ atacMatch#parentuid.) == 0) {
593 uint32cxx . . $ uint32# l1, r1, l2, r2;
594
595 if (MO[cxx . . $ atacMatchOrder#`operator[]`(4b949e4d42dbfd78).i]->fwd2cxx . . $ atacMatch#fwd2. == 1) {
596 l1 = MO[cxx . . $ atacMatchOrder#`operator[]`(4b949e4d42dbfd78).i-1]->pos1cxx . . $ atacMatch#pos1. + MO[cxx . . $ atacMatchOrder#`operator[]`(4b949e4d42dbfd78).i-1]->len1cxx . . $ atacMatch#len1.;
597 r1 = MO[cxx . . $ atacMatchOrder#`operator[]`(4b949e4d42dbfd78).i]->pos1cxx . . $ atacMatch#pos1.;
598 l2 = MO[cxx . . $ atacMatchOrder#`operator[]`(4b949e4d42dbfd78).i-1]->pos2cxx . . $ atacMatch#pos2. + MO[cxx . . $ atacMatchOrder#`operator[]`(4b949e4d42dbfd78).i-1]->len2cxx . . $ atacMatch#len2.;
599 r2 = MO[cxx . . $ atacMatchOrder#`operator[]`(4b949e4d42dbfd78).i]->pos2cxx . . $ atacMatch#pos2.;
600 } else {
601 l1 = MO[cxx . . $ atacMatchOrder#`operator[]`(4b949e4d42dbfd78).i-1]->pos1cxx . . $ atacMatch#pos1. + MO[cxx . . $ atacMatchOrder#`operator[]`(4b949e4d42dbfd78).i-1]->len1cxx . . $ atacMatch#len1.;
602 r1 = MO[cxx . . $ atacMatchOrder#`operator[]`(4b949e4d42dbfd78).i]->pos1cxx . . $ atacMatch#pos1.;
603 l2 = MO[cxx . . $ atacMatchOrder#`operator[]`(4b949e4d42dbfd78).i]->pos2cxx . . $ atacMatch#pos2. + MO[cxx . . $ atacMatchOrder#`operator[]`(4b949e4d42dbfd78).i]->len2cxx . . $ atacMatch#len2.;
604 r2 = MO[cxx . . $ atacMatchOrder#`operator[]`(4b949e4d42dbfd78).i-1]->pos2cxx . . $ atacMatch#pos2.;
605 }
606
607 il1full.addcxx . . $ intervalList#add(4d3091562df4e52e).(l1, r1-l1);
608 il2full.addcxx . . $ intervalList#add(4d3091562df4e52e).(l2, r2-l2);
609
610 hist1full.addcxx . . $ histogram#add(2c44cd906ae4e829).(r1-l1);
611 hist2full.addcxx . . $ histogram#add(2c44cd906ae4e829).(r2-l2);
612
613 statsInACGTcxx . . $ statsInACGT(f9929111816030f8).(A->getSequenceInCorecxx . . $ seqCache#getSequenceInCore(715c05706546271f).(MO[cxx . . $ atacMatchOrder#`operator[]`(4b949e4d42dbfd78).i]->iid1cxx . . $ atacMatch#iid1.),
614 l1,
615 r1-l1,
616 &il1acgt,
617 &hist1acgt);
618 statsInACGTcxx . . $ statsInACGT(f9929111816030f8).(B->getSequenceInCorecxx . . $ seqCache#getSequenceInCore(715c05706546271f).(MO[cxx . . $ atacMatchOrder#`operator[]`(4b949e4d42dbfd78).i]->iid2cxx . . $ atacMatch#iid2.),
619 l2,
620 r2-l2,
621 &il2acgt,
622 &hist2acgt);
623 }
624 }
625
626 // Dump the stats
627
628 fprintf(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "runMissingFull %s "uint64FMTcxx . . $ `libutil/util.h:55:10`!" %s "uint64FMTcxx . . $ `libutil/util.h:55:10`!" # sequence in run, not covered, including N\n",
629 AF.labelAcxx . . $ atacFileBase#labelA(41208ce6ca65dd58).(), (uint64cxx . . $ uint64#)il1full.sumOfLengthscxx . . $ intervalList#sumOfLengths(5f357b03ed472e5e).(),
630 AF.labelBcxx . . $ atacFileBase#labelB(41208ce6ca65dd58).(), (uint64cxx . . $ uint64#)il2full.sumOfLengthscxx . . $ intervalList#sumOfLengths(5f357b03ed472e5e).());
631 fprintf(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "runMissingFull %s "uint64FMTcxx . . $ `libutil/util.h:55:10`!" %s "uint64FMTcxx . . $ `libutil/util.h:55:10`!" # sequence in run, not covered, ACGT only\n",
632 AF.labelAcxx . . $ atacFileBase#labelA(41208ce6ca65dd58).(), (uint64cxx . . $ uint64#)il1acgt.sumOfLengthscxx . . $ intervalList#sumOfLengths(5f357b03ed472e5e).(),
633 AF.labelBcxx . . $ atacFileBase#labelB(41208ce6ca65dd58).(), (uint64cxx . . $ uint64#)il2acgt.sumOfLengthscxx . . $ intervalList#sumOfLengths(5f357b03ed472e5e).());
634
635 hist1full.dumpcxx . . $ histogram#dump(2fa786934fe80e24).(prefix, "ARunMissingFull");
636 hist1full.plotcxx . . $ histogram#plot(2fa786934fe80e24).(prefix, "ARunMissingFull");
637
638 hist2full.dumpcxx . . $ histogram#dump(2fa786934fe80e24).(prefix, "BRunMissingFull");
639 hist2full.plotcxx . . $ histogram#plot(2fa786934fe80e24).(prefix, "BRunMissingFull");
640
641 hist1acgt.dumpcxx . . $ histogram#dump(2fa786934fe80e24).(prefix, "ARunMissingACGT");
642 hist1acgt.plotcxx . . $ histogram#plot(2fa786934fe80e24).(prefix, "ARunMissingACGT");
643
644 hist2acgt.dumpcxx . . $ histogram#dump(2fa786934fe80e24).(prefix, "BRunMissingACGT");
645 hist2acgt.plotcxx . . $ histogram#plot(2fa786934fe80e24).(prefix, "BRunMissingACGT");
646 }
647
648
649
650 int
651 maincxx . . $ main(afcd3168fc1188a4).(int argc, char **argv) {
652 uint64cxx . . $ uint64# genomeSize = 0;
653 char *atacFileName = 0L;
654 char *prefix = 0L;
655 char *trFile1 = 0L;
656 char *trFile2 = 0L;
657 char prefixFull[1024];
658 bool error = false;
659
660 int arg=1;
661 while (arg < argc) {
662 if (strcmp(argv[arg], "-g") == 0) {
663 ++arg;
664 if (argv[arg][0] == 'A') {
665 genomeSize = 0;
666 } else if (argv[arg][0] == 'B') {
667 genomeSize = 1;
668 } else {
669 genomeSize = strtouint64cxx . . $ `libutil/util.h:83:10`!(argv[arg], 0L);
670 }
671 } else if (strcmp(argv[arg], "-a") == 0) {
672 atacFileName = argv[++arg];
673 } else if (strcmp(argv[arg], "-p") == 0) {
674 prefix = argv[++arg];
675 } else if (strcmp(argv[arg], "-ta") == 0) {
676 trFile1 = argv[++arg];
677 } else if (strcmp(argv[arg], "-tb") == 0) {
678 trFile2 = argv[++arg];
679 } else {
680 error = true;
681 }
682 arg++;
683 }
684
685 if (!atacFileName || !prefix || error) {
686 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "usage: %s -a <file.atac> -p <outprefix> [-ta trfile] [-tb trfile] [-g {A | B | g}]\n", argv[0]);
687 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " -a read input from 'file.atac'\n");
688 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " -p write stats to files prefixed with 'outprefix'\n");
689 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " -g use a genome size of g for the Nx computation, defaults to\n");
690 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " the length of the A sequence. Or use the actual length\n");
691 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " of sequence A or B.\n");
692 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " -ta read tandem repeats for A from trfile\n");
693 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " -tb read tandem repeats for B from trfile\n");
694 exitcxx . . $ exit(44ed87f96534fad7).(1);
695 }
696
697 atacFilecxx . . $ atacFile# AFcxx . . $ atacFile#atacFile(85c52e162fed56f9).(atacFileName);
698 atacMatchListcxx . . $ atacMatchList# &matches = *AF.matchescxx . . $ atacFile#matches(33e88ebc28d05bce).();
699 atacMatchListcxx . . $ atacMatchList# &runs = *AF.runscxx . . $ atacFile#runs(33e88ebc28d05bce).();
700 atacMatchListcxx . . $ atacMatchList# &clumps = *AF.clumpscxx . . $ atacFile#clumps(33e88ebc28d05bce).();
701
702 // We end up using sequences a lot here, so just bite it and load them in a cache.
703 //
704 seqCachecxx . . $ seqCache# *A = new seqCachecxx . . $ seqCache#seqCache(cc76bd1196c143a3).(AF.assemblyFileAcxx . . $ atacFileBase#assemblyFileA(41208ce6ca65dd58).(), 0, true);
705 seqCachecxx . . $ seqCache# *B = new seqCachecxx . . $ seqCache#seqCache(cc76bd1196c143a3).(AF.assemblyFileBcxx . . $ atacFileBase#assemblyFileB(41208ce6ca65dd58).(), 0, true);
706
707 A->loadAllSequencescxx . . $ seqCache#loadAllSequences(49f6e7a06ebc5aa8).();
708 B->loadAllSequencescxx . . $ seqCache#loadAllSequences(49f6e7a06ebc5aa8).();
709
710 fprintf(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "\nSEQUENCE\n");
711 totalLengthcxx . . $ totalLength(2d5fc859995a3fb5).(AF, A, B);
712
713 if (trFile1 && trFile2) {
714 atacFileStreamcxx . . $ atacFileStream# tr1cxx . . $ atacFileStream#atacFileStream(85c52e162fed56f9).(trFile1);
715 atacFileStreamcxx . . $ atacFileStream# tr2cxx . . $ atacFileStream#atacFileStream(85c52e162fed56f9).(trFile2);
716 tandemRepeatStatscxx . . $ tandemRepeatStats(3950462bed0fe964).(tr1, tr2, AF, A, B);
717 }
718
719 // XXX unmappedInRuns only works on runs, and if we have clumps in
720 // the input it fails.
721 //
722 if ((runs.numberOfMatchescxx . . $ atacMatchList#numberOfMatches(db52760e79bf9054).() > 0) && (clumps.numberOfMatchescxx . . $ atacMatchList#numberOfMatches(db52760e79bf9054).() == 0)) {
723 fprintf(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "\nMATCHES IN RUNS\n");
724 unmappedInRunscxx . . $ unmappedInRuns(be726ad975d118fc).(AF, A, B, prefix);
725 }
726
727 if (matches.numberOfMatchescxx . . $ atacMatchList#numberOfMatches(db52760e79bf9054).() > 0) {
728 fprintf(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "\nMATCHES\n");
729 sprintf(prefixFull, "%s-matches", prefix);
730 mappedLengthscxx . . $ mappedLengths(c30d539dd6c0e8a).(AF, matches, A, B, prefixFull);
731 NxOfMappedcxx . . $ NxOfMapped(8373d9e8c81ce31c).(AF, matches, genomeSize, prefixFull);
732 MappedByChromosomecxx . . $ MappedByChromosome(c30d539dd6c0e8a).(AF, matches, A, B, prefixFull);
733 }
734
735 if (runs.numberOfMatchescxx . . $ atacMatchList#numberOfMatches(db52760e79bf9054).() > 0) {
736 fprintf(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "\nRUNS\n");
737 sprintf(prefixFull, "%s-runs", prefix);
738 mappedLengthscxx . . $ mappedLengths(c30d539dd6c0e8a).(AF, runs, A, B, prefixFull);
739 NxOfMappedcxx . . $ NxOfMapped(8373d9e8c81ce31c).(AF, runs, genomeSize, prefixFull);
740 MappedByChromosomecxx . . $ MappedByChromosome(c30d539dd6c0e8a).(AF, runs, A, B, prefixFull);
741 }
742
743 if (clumps.numberOfMatchescxx . . $ atacMatchList#numberOfMatches(db52760e79bf9054).() > 0) {
744 fprintf(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "\nCLUMPS\n");
745 sprintf(prefixFull, "%s-clumps", prefix);
746 mappedLengthscxx . . $ mappedLengths(c30d539dd6c0e8a).(AF, clumps, A, B, prefixFull);
747 NxOfMappedcxx . . $ NxOfMapped(8373d9e8c81ce31c).(AF, clumps, genomeSize, prefixFull);
748 MappedByChromosomecxx . . $ MappedByChromosome(c30d539dd6c0e8a).(AF, clumps, A, B, prefixFull);
749 }
750
751 delete A;
752 delete B;
753
754 return(0);
755 }