Debian Codegraph @

atac-driver/alignOverlap/overlap.C

raw symbols SCIP
1 // This file is part of A2Amapper.cxx . . $ `<file>/atac-driver/alignOverlap/overlap.C`/
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 "overlap.H"cxx . . $ `<file>/atac-driver/alignOverlap/overlap.H`/
20
21
22 int
23 maincxx . . $ main(afcd3168fc1188a4).(int argc, char **argv) {
24
25 if (argc != 4) {
26 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "usage: %s <matches-1> <matches-2> <out-prefix>\n", argv[0]);
27 exitcxx . . $ exit(44ed87f96534fad7).(1);
28 }
29 atacFilecxx . . $ atacFile# *AF1 = new atacFilecxx . . $ atacFile#(argv[1]);
30 atacFilecxx . . $ atacFile# *AF2 = new atacFilecxx . . $ atacFile#(argv[2]);
31
32 atacMatchListcxx . . $ atacMatchList# *M1 = AF1->matchescxx . . $ atacFile#matches(33e88ebc28d05bce).();
33 atacMatchListcxx . . $ atacMatchList# *M2 = AF2->matchescxx . . $ atacFile#matches(33e88ebc28d05bce).();
34
35 char *OP = argv[3];
36
37
38 // We want to annotate the two assembies with:
39 // a) mapped by both, the same
40 // b) mapped by both, differently
41 // c) mapped by the first, unmapped by the second
42 // d) mapped by the second, unmapped by the first
43 // e) unmapped by both
44 //
45 // If unmapped, we could further annotate with the reason it was
46 // unmapped -- not found, or found multiple times.
47 //
48 // Our annotation datastructure is a tree of spans. Each span is a
49 // sequence, and an interval on that sequence. We assume that the
50 // tree contains the spans for the whole sequence, that is, that we
51 // never need to increase a span, just split.
52 //
53 spanTreecxx . . $ spanTree# *S1 = new spanTreecxx . . $ spanTree#();
54 spanTreecxx . . $ spanTree# *S2 = new spanTreecxx . . $ spanTree#();
55
56 // Initialize the tree of spans by inserting a single span for each
57 // sequence in the file.
58 //
59 for (uint32cxx . . $ uint32# i=0; i<AF1->fastaAcxx . . $ atacFileBase#fastaA(e73a05296fa21060).()->getNumberOfSequencescxx . . $ seqCache#getNumberOfSequences(db52760e79bf9054).(); i++)
60 S1->addNewSpancxx . . $ spanTree#addNewSpan(b4d55b1286ff73e8).(i, AF1->fastaAcxx . . $ atacFileBase#fastaA(e73a05296fa21060).()->getSequenceLengthcxx . . $ seqCache#getSequenceLength(2141b656ce2cc063).(i));
61 for (uint32cxx . . $ uint32# i=0; i<AF1->fastaBcxx . . $ atacFileBase#fastaB(e73a05296fa21060).()->getNumberOfSequencescxx . . $ seqCache#getNumberOfSequences(db52760e79bf9054).(); i++)
62 S2->addNewSpancxx . . $ spanTree#addNewSpan(b4d55b1286ff73e8).(i, AF1->fastaBcxx . . $ atacFileBase#fastaB(e73a05296fa21060).()->getSequenceLengthcxx . . $ seqCache#getSequenceLength(2141b656ce2cc063).(i));
63
64 // Add every match to the spanTrees.
65
66 for (uint32cxx . . $ uint32# i=0; i<M1->numberOfMatchescxx . . $ atacMatchList#numberOfMatches(db52760e79bf9054).(); i++) {
67 S1->addMatchcxx . . $ spanTree#addMatch(c37c57dc8a530d2f).(M1->getMatchcxx . . $ atacMatchList#getMatch(4b949e4d42dbfd78).(i), 0, 0);
68 S2->addMatchcxx . . $ spanTree#addMatch(c37c57dc8a530d2f).(M1->getMatchcxx . . $ atacMatchList#getMatch(4b949e4d42dbfd78).(i), 1, 0);
69 }
70 for (uint32cxx . . $ uint32# i=0; i<M2->numberOfMatchescxx . . $ atacMatchList#numberOfMatches(db52760e79bf9054).(); i++) {
71 S1->addMatchcxx . . $ spanTree#addMatch(c37c57dc8a530d2f).(M2->getMatchcxx . . $ atacMatchList#getMatch(4b949e4d42dbfd78).(i), 0, 1);
72 S2->addMatchcxx . . $ spanTree#addMatch(c37c57dc8a530d2f).(M2->getMatchcxx . . $ atacMatchList#getMatch(4b949e4d42dbfd78).(i), 1, 1);
73 }
74
75 // Dump each spanTree: For each span, we need to check that
76 // it has matches?
77 // only one match, or only matches from one mapping?
78 // matches from both mappings? need to check that
79 // the span in the other tree also has the same matches
80 //
81 // Doesn't handle weird stuff like this span (on sequence 1)
82 // mapping onto seq2 correctly, but the span in seq2 having an
83 // extra match to somewhere else in seq1.
84 //
85 // we want to find the single span in the other spanTree that
86 // corresponds to this span. once we do that, we can verify that
87 // all the matches are the same.
88 //
89 // because we are gapless matches, we can, for each match,
90 // compute the exact location this span should occur on the other
91 // sequence. then, do a lookup() to get that span, or just
92 // verify that everybody is the same location.
93
94 char outname[1024];
95 FILE *outfile;
96
97 overlapStatscxx . . $ overlapStats# statsA;
98 uint32cxx . . $ uint32# ALmax = (uint32cxx . . $ uint32#)dict_countcxx . . $ `libutil/kazlib/dict.h:131:9`!(S1->_tree);
99 uint32cxx . . $ uint32# ALlen = 0;
100 annoListcxx . . $ annoList# *AL = new annoListcxx . . $ annoList# [ ALmax ];
101
102 sprintf(outname, "%s.map1annotation", OP);
103 errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = 0;
104 outfile = fopen(outname, "w");
105 if (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)
106 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Failed to open '%s': %s\n", outname, strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
107 process1cxx . . $ process1(681c937729fcfb5b).(outfile, S1, M1, M2, statsA, AL, ALlen, ALmax);
108 fclose(outfile);
109
110 overlapStatscxx . . $ overlapStats# statsB;
111 uint32cxx . . $ uint32# BLmax = (uint32cxx . . $ uint32#)dict_countcxx . . $ `libutil/kazlib/dict.h:131:9`!(S1->_tree);
112 uint32cxx . . $ uint32# BLlen = 0;
113 annoListcxx . . $ annoList# *BL = new annoListcxx . . $ annoList# [ ALmax ];
114
115 sprintf(outname, "%s.map2annotation", OP);
116 errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = 0;
117 outfile = fopen(outname, "w");
118 if (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)
119 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Failed to open '%s': %s\n", outname, strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
120 process2cxx . . $ process2(681c937729fcfb5b).(outfile, S2, M1, M2, statsB, BL, BLlen, BLmax);
121 fclose(outfile);
122
123 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "unmapped: A:"uint32FMTWcxx . . $ `libutil/util.h:64:10`!(10)" B:"uint32FMTWcxx . . $ `libutil/util.h:64:10`!(10)"\n", statsA.unmappedcxx . . $ overlapStats#unmapped..getSumcxx . . $ histogram#getSum(db52760e79bf9054).(), statsB.unmappedcxx . . $ overlapStats#unmapped..getSumcxx . . $ histogram#getSum(db52760e79bf9054).());
124 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "unique mapping 1: A:"uint32FMTWcxx . . $ `libutil/util.h:64:10`!(10)" B:"uint32FMTWcxx . . $ `libutil/util.h:64:10`!(10)"\n", statsA.map1uniquecxx . . $ overlapStats#map1unique..getSumcxx . . $ histogram#getSum(db52760e79bf9054).(), statsB.map1uniquecxx . . $ overlapStats#map1unique..getSumcxx . . $ histogram#getSum(db52760e79bf9054).());
125 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "unique mapping 2: A:"uint32FMTWcxx . . $ `libutil/util.h:64:10`!(10)" B:"uint32FMTWcxx . . $ `libutil/util.h:64:10`!(10)"\n", statsA.map2uniquecxx . . $ overlapStats#map2unique..getSumcxx . . $ histogram#getSum(db52760e79bf9054).(), statsB.map2uniquecxx . . $ overlapStats#map2unique..getSumcxx . . $ histogram#getSum(db52760e79bf9054).());
126 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "different: A:"uint32FMTWcxx . . $ `libutil/util.h:64:10`!(10)" B:"uint32FMTWcxx . . $ `libutil/util.h:64:10`!(10)"\n", statsA.differentcxx . . $ overlapStats#different..getSumcxx . . $ histogram#getSum(db52760e79bf9054).(), statsB.differentcxx . . $ overlapStats#different..getSumcxx . . $ histogram#getSum(db52760e79bf9054).());
127 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "wild diff: A:"uint32FMTWcxx . . $ `libutil/util.h:64:10`!(10)" B:"uint32FMTWcxx . . $ `libutil/util.h:64:10`!(10)"\n", statsA.wilddiffcxx . . $ overlapStats#wilddiff..getSumcxx . . $ histogram#getSum(db52760e79bf9054).(), statsB.wilddiffcxx . . $ overlapStats#wilddiff..getSumcxx . . $ histogram#getSum(db52760e79bf9054).());
128 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "same: A:"uint32FMTWcxx . . $ `libutil/util.h:64:10`!(10)" B:"uint32FMTWcxx . . $ `libutil/util.h:64:10`!(10)"\n", statsA.samecxx . . $ overlapStats#same..getSumcxx . . $ histogram#getSum(db52760e79bf9054).(), statsB.samecxx . . $ overlapStats#same..getSumcxx . . $ histogram#getSum(db52760e79bf9054).());
129 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "inconsistent: A:"uint32FMTWcxx . . $ `libutil/util.h:64:10`!(10)" B:"uint32FMTWcxx . . $ `libutil/util.h:64:10`!(10)"\n", statsA.inconsistentcxx . . $ overlapStats#inconsistent..getSumcxx . . $ histogram#getSum(db52760e79bf9054).(), statsB.inconsistentcxx . . $ overlapStats#inconsistent..getSumcxx . . $ histogram#getSum(db52760e79bf9054).());
130
131 // Dump the histograms for each of the labelings
132 //
133 sprintf(outname, "%s.asm1histogram", OP);
134 statsA.writeHistogramcxx . . $ overlapStats#writeHistogram(85c52e162fed56f9).(outname);
135 sprintf(outname, "%s.asm2histogram", OP);
136 statsB.writeHistogramcxx . . $ overlapStats#writeHistogram(85c52e162fed56f9).(outname);
137
138 // Draw some pretty pictures
139 //
140 sprintf(outname, "%s.histogram.gnuplot", OP);
141 errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = 0;
142 outfile = fopen(outname, "w");
143 if (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)
144 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "failed to open '%s': %s\n", outname, strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)), exitcxx . . $ exit(44ed87f96534fad7).(1);
145 fprintf(outfile, "set terminal postscript color\n");
146 fprintf(outfile, "set output \"%s.unmapped.histogram.ps\"\n", OP);
147 fprintf(outfile, "set ylabel \"number of regions\"\n");
148 fprintf(outfile, "set xlabel \"length of region\"\n");
149 fprintf(outfile, "plot [0:10000][0:400] \\\n");
150 fprintf(outfile, " \"%s.asm1histogram.unmapped\" using 2 title \"assembly 1 unmapped\" with lines, \\\n", OP);
151 fprintf(outfile, " \"%s.asm2histogram.unmapped\" using 2 title \"assembly 2 unmapped\" with lines\n", OP);
152 fprintf(outfile, "set output \"%s.same.histogram.ps\"\n", OP);
153 fprintf(outfile, "plot [0:20000][0:2000] \\\n");
154 fprintf(outfile, " \"%s.asm1histogram.same\" using 2 title \"assembly 1 same\" with lines, \\\n", OP);
155 fprintf(outfile, " \"%s.asm2histogram.same\" using 2 title \"assembly 2 same\" with lines\n", OP);
156 fprintf(outfile, "set output \"%s.histogram.ps\"\n", OP);
157 fprintf(outfile, "plot [0:2000][0:100] \\\n");
158 fprintf(outfile, " \"%s.asm1histogram.different\" using 2 title \"assembly 1 different\" with lines, \\\n", OP);
159 fprintf(outfile, " \"%s.asm2histogram.different\" using 2 title \"assembly 2 different\" with lines, \\\n", OP);
160 fprintf(outfile, " \"%s.asm1histogram.wilddiff\" using 2 title \"assembly 1 wildly diff\" with lines, \\\n", OP);
161 fprintf(outfile, " \"%s.asm2histogram.wilddiff\" using 2 title \"assembly 2 wildly diff\" with lines\n", OP);
162 fprintf(outfile, "set output \"%s.unique.histogram.ps\"\n", OP);
163 fprintf(outfile, "plot [0:2000][0:100] \\\n");
164 fprintf(outfile, " \"%s.asm1histogram.map1unique\" using 2 title \"map 1, assembly 1 unique\" with lines, \\\n", OP);
165 fprintf(outfile, " \"%s.asm1histogram.map2unique\" using 2 title \"map 2, assembly 1 unique\" with lines, \\\n", OP);
166 fprintf(outfile, " \"%s.asm2histogram.map1unique\" using 2 title \"map 1, assembly 2 unique\" with lines, \\\n", OP);
167 fprintf(outfile, " \"%s.asm2histogram.map2unique\" using 2 title \"map 2, assembly 2 unique\" with lines\n", OP);
168 fclose(outfile);
169
170 sprintf(outname, "gnuplot < %s.histogram.gnuplot", OP);
171 if (systemcxx . . $ system(5c4306d8553b3696).(outname))
172 fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Failed to '%s'\n", outname);
173
174 #if 0
175 findIsolatedUnique(AL, ALlen);
176 findExtended(AL, ALlen);
177 #endif
178
179 // Deleting the spanTrees takes a long time, so we don't bother with any cleanup.
180 return(0);
181 }