| 1 | // This file is part of A2Amapper.cxx . . $ `<file>/atac-driver/gapShifter/projectFeatures.C`/ |
| 2 | // Copyright (c) 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"cxx . . $ `<file>/libbio/bio++.H`/ |
| 24 | #include "atac.H"cxx . . $ `<file>/atac-driver/libatac/atac.H`/ |
| 25 | |
| 26 | void |
| 27 | usagecxx . . $ usage(fda57c8427c60377).(char *name) { |
| 28 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "usage: %s [] -m matches -l log\n", name); |
| 29 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " When it works, fill this in...\n"); |
| 30 | } |
| 31 | |
| 32 | // Reads an atac mapping, and a list of features. Features on one |
| 33 | // axis are projected to the other axis using the atac map. |
| 34 | |
| 35 | int |
| 36 | maincxx . . $ main(afcd3168fc1188a4).(int argc, char **argv) { |
| 37 | char *matchesFile = 0L; |
| 38 | char *featureFile = 0L; |
| 39 | FILE *logFile = 0L; |
| 40 | |
| 41 | int arg=1; |
| 42 | while (arg < argc) { |
| 43 | if (strcmp(argv[arg], "-m") == 0) { |
| 44 | matchesFile = argv[++arg]; |
| 45 | } else if (strcmp(argv[arg], "-f") == 0) { |
| 46 | featureFile = argv[++arg]; |
| 47 | } else if (strcmp(argv[arg], "-l") == 0) { |
| 48 | errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = 0; |
| 49 | logFile = fopen(argv[++arg], "w"); |
| 50 | if (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!) |
| 51 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Failed to open logfile '%s': %s\n", strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!), argv[arg]), exitcxx . . $ exit(44ed87f96534fad7).(1); |
| 52 | } else { |
| 53 | usagecxx . . $ usage(fda57c8427c60377).(argv[0]); |
| 54 | exitcxx . . $ exit(44ed87f96534fad7).(1); |
| 55 | } |
| 56 | arg++; |
| 57 | } |
| 58 | |
| 59 | if (matchesFile == 0L) |
| 60 | usagecxx . . $ usage(fda57c8427c60377).(argv[0]), exitcxx . . $ exit(44ed87f96534fad7).(1); |
| 61 | if (featureFile == 0L) |
| 62 | usagecxx . . $ usage(fda57c8427c60377).(argv[0]), exitcxx . . $ exit(44ed87f96534fad7).(1); |
| 63 | if (logFile == 0L) |
| 64 | usagecxx . . $ usage(fda57c8427c60377).(argv[0]), exitcxx . . $ exit(44ed87f96534fad7).(1); |
| 65 | |
| 66 | atacFilecxx . . $ atacFile# AFcxx . . $ atacFile#atacFile(85c52e162fed56f9).(matchesFile); |
| 67 | atacMatchListcxx . . $ atacMatchList# &ML = *AF.matchescxx . . $ atacFile#matches(33e88ebc28d05bce).(); |
| 68 | atacMatchOrdercxx . . $ atacMatchOrder# MOcxx . . $ atacMatchOrder#atacMatchOrder(f3ef1525738b52af).(ML); |
| 69 | |
| 70 | |
| 71 | // XXXX extrabroken! |
| 72 | #warning BROKEN |
| 73 | atacFeatureListcxx . . $ atacFeatureList# FLcxx . . $ atacFeatureList#atacFeatureList(49f6e7a06ebc5aa8).; |
| 74 | |
| 75 | // Project features from A to B. |
| 76 | MO.sortAcxx . . $ atacMatchOrder#sortA(b4d55b1286ff73e8).(); |
| 77 | FL.sortcxx . . $ atacFeatureList#sort(b4d55b1286ff73e8).(); |
| 78 | |
| 79 | uint32cxx . . $ uint32# mid = 0; |
| 80 | uint32cxx . . $ uint32# fid = 0; |
| 81 | uint32cxx . . $ uint32# pid = 0; |
| 82 | |
| 83 | while ((mid < MO.numberOfMatchescxx . . $ atacMatchOrder#numberOfMatches(db52760e79bf9054).()) && |
| 84 | (fid < FL.numberOfFeaturescxx . . $ atacFeatureList#numberOfFeatures(db52760e79bf9054).())) { |
| 85 | atacMatchcxx . . $ atacMatch# *m = MO[cxx . . $ atacMatchOrder#`operator[]`(4b949e4d42dbfd78).mid]; |
| 86 | atacFeaturecxx . . $ atacFeature# *f = FL[cxx . . $ atacFeatureList#`operator[]`(635fde6fe8151c7a).fid]; |
| 87 | |
| 88 | if (m->iid1cxx . . $ atacMatch#iid1. < f->iidcxx . . $ atacFeature#iid.) { |
| 89 | mid++; |
| 90 | continue; |
| 91 | } |
| 92 | if (f->iidcxx . . $ atacFeature#iid. < m->iid1cxx . . $ atacMatch#iid1.) { |
| 93 | fid++; |
| 94 | continue; |
| 95 | } |
| 96 | |
| 97 | // Same sequences now! |
| 98 | |
| 99 | if (m->pos1cxx . . $ atacMatch#pos1. + m->len1cxx . . $ atacMatch#len1. < f->poscxx . . $ atacFeature#pos.) { |
| 100 | // match ends before the feature |
| 101 | mid++; |
| 102 | continue; |
| 103 | } |
| 104 | |
| 105 | if (f->poscxx . . $ atacFeature#pos. + f->lencxx . . $ atacFeature#len. < m->pos1cxx . . $ atacMatch#pos1.) { |
| 106 | // Feature begins before match |
| 107 | fid++; |
| 108 | continue; |
| 109 | } |
| 110 | |
| 111 | // Feature and match now overlap! |
| 112 | |
| 113 | |
| 114 | // |
| 115 | // This does A -> B -- ONLY. |
| 116 | // |
| 117 | |
| 118 | |
| 119 | |
| 120 | // If feature is completely in match, this is easy. |
| 121 | // |
| 122 | if ((m->pos1cxx . . $ atacMatch#pos1. <= f->poscxx . . $ atacFeature#pos.) && ((f->poscxx . . $ atacFeature#pos. + f->lencxx . . $ atacFeature#len.) <= (m->pos1cxx . . $ atacMatch#pos1. + m->len1cxx . . $ atacMatch#len1.))) { |
| 123 | uint32cxx . . $ uint32# beg; |
| 124 | |
| 125 | if (m->fwd2cxx . . $ atacMatch#fwd2. == true) { |
| 126 | beg = m->pos2cxx . . $ atacMatch#pos2. + f->poscxx . . $ atacFeature#pos. - m->pos1cxx . . $ atacMatch#pos1.; |
| 127 | } else { |
| 128 | beg = m->pos2cxx . . $ atacMatch#pos2. + m->len2cxx . . $ atacMatch#len2. - (f->poscxx . . $ atacFeature#pos. - m->pos1cxx . . $ atacMatch#pos1.) - f->lencxx . . $ atacFeature#len.; |
| 129 | } |
| 130 | |
| 131 | if (f->lencxx . . $ atacFeature#len. > 0) |
| 132 | fprintf(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "M u Aprojected"uint32FMTcxx . . $ `libutil/util.h:65:10`!" %s.%s %s:"uint32FMTcxx . . $ `libutil/util.h:65:10`!" "uint32FMTcxx . . $ `libutil/util.h:65:10`!" "uint32FMTcxx . . $ `libutil/util.h:65:10`!" 1 %s:"uint32FMTcxx . . $ `libutil/util.h:65:10`!" "uint32FMTcxx . . $ `libutil/util.h:65:10`!" "uint32FMTcxx . . $ `libutil/util.h:65:10`!" %d\n", |
| 133 | pid, |
| 134 | f->featureuidcxx . . $ atacFeature#featureuid., m->matchuidcxx . . $ atacMatch#matchuid., |
| 135 | AF.labelAcxx . . $ atacFileBase#labelA(41208ce6ca65dd58).(), f->iidcxx . . $ atacFeature#iid., f->poscxx . . $ atacFeature#pos., f->lencxx . . $ atacFeature#len., |
| 136 | AF.labelBcxx . . $ atacFileBase#labelB(41208ce6ca65dd58).(), m->iid2cxx . . $ atacMatch#iid2., beg, f->lencxx . . $ atacFeature#len., (m->fwd2cxx . . $ atacMatch#fwd2.) ? 1 : -1); |
| 137 | pid++; |
| 138 | fid++; |
| 139 | continue; |
| 140 | } |
| 141 | |
| 142 | // If match is completely within feature, super easy! |
| 143 | // |
| 144 | if ((f->poscxx . . $ atacFeature#pos. < m->pos1cxx . . $ atacMatch#pos1.) && (m->pos1cxx . . $ atacMatch#pos1. + m->len1cxx . . $ atacMatch#len1.) < (f->poscxx . . $ atacFeature#pos. + f->lencxx . . $ atacFeature#len.)) { |
| 145 | if (m->len1cxx . . $ atacMatch#len1. > 0) |
| 146 | fprintf(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "M u Bprojected"uint32FMTcxx . . $ `libutil/util.h:65:10`!" %s.%s %s:"uint32FMTcxx . . $ `libutil/util.h:65:10`!" "uint32FMTcxx . . $ `libutil/util.h:65:10`!" "uint32FMTcxx . . $ `libutil/util.h:65:10`!" 1 %s:"uint32FMTcxx . . $ `libutil/util.h:65:10`!" "uint32FMTcxx . . $ `libutil/util.h:65:10`!" "uint32FMTcxx . . $ `libutil/util.h:65:10`!" %d\n", |
| 147 | pid, |
| 148 | f->featureuidcxx . . $ atacFeature#featureuid., m->matchuidcxx . . $ atacMatch#matchuid., |
| 149 | AF.labelAcxx . . $ atacFileBase#labelA(41208ce6ca65dd58).(), m->iid1cxx . . $ atacMatch#iid1., m->pos1cxx . . $ atacMatch#pos1., m->len1cxx . . $ atacMatch#len1., |
| 150 | AF.labelBcxx . . $ atacFileBase#labelB(41208ce6ca65dd58).(), m->iid2cxx . . $ atacMatch#iid2., m->pos2cxx . . $ atacMatch#pos2., m->len2cxx . . $ atacMatch#len2., (m->fwd2cxx . . $ atacMatch#fwd2.) ? 1 : -1); |
| 151 | pid++; |
| 152 | fid++; |
| 153 | continue; |
| 154 | } |
| 155 | |
| 156 | |
| 157 | // Dang, feature isn't completely in match. Guess where feature |
| 158 | // could be ending? Or just project as much as possible? |
| 159 | |
| 160 | if (f->poscxx . . $ atacFeature#pos. < m->pos1cxx . . $ atacMatch#pos1.) { |
| 161 | uint32cxx . . $ uint32# len = f->lencxx . . $ atacFeature#len. - (m->pos1cxx . . $ atacMatch#pos1. - f->poscxx . . $ atacFeature#pos.); |
| 162 | uint32cxx . . $ uint32# beg; |
| 163 | |
| 164 | if (m->fwd2cxx . . $ atacMatch#fwd2. == true) { |
| 165 | beg = m->pos2cxx . . $ atacMatch#pos2.; |
| 166 | } else { |
| 167 | beg = m->pos2cxx . . $ atacMatch#pos2. + m->len2cxx . . $ atacMatch#len2. - len; |
| 168 | } |
| 169 | |
| 170 | if (len > 0) |
| 171 | fprintf(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "M u Cprojected"uint32FMTcxx . . $ `libutil/util.h:65:10`!" %s.%s %s:"uint32FMTcxx . . $ `libutil/util.h:65:10`!" "uint32FMTcxx . . $ `libutil/util.h:65:10`!" "uint32FMTcxx . . $ `libutil/util.h:65:10`!" 1 %s:"uint32FMTcxx . . $ `libutil/util.h:65:10`!" "uint32FMTcxx . . $ `libutil/util.h:65:10`!" "uint32FMTcxx . . $ `libutil/util.h:65:10`!" %d\n", |
| 172 | pid, |
| 173 | f->featureuidcxx . . $ atacFeature#featureuid., m->matchuidcxx . . $ atacMatch#matchuid., |
| 174 | AF.labelAcxx . . $ atacFileBase#labelA(41208ce6ca65dd58).(), f->iidcxx . . $ atacFeature#iid., m->pos1cxx . . $ atacMatch#pos1., len, |
| 175 | AF.labelBcxx . . $ atacFileBase#labelB(41208ce6ca65dd58).(), m->iid2cxx . . $ atacMatch#iid2., beg, len, (m->fwd2cxx . . $ atacMatch#fwd2.) ? 1 : -1); |
| 176 | pid++; |
| 177 | fid++; |
| 178 | continue; |
| 179 | } |
| 180 | |
| 181 | if (m->pos1cxx . . $ atacMatch#pos1. + m->len1cxx . . $ atacMatch#len1. < f->poscxx . . $ atacFeature#pos. + f->lencxx . . $ atacFeature#len.) { |
| 182 | uint32cxx . . $ uint32# len = m->pos1cxx . . $ atacMatch#pos1. + m->len1cxx . . $ atacMatch#len1. - f->poscxx . . $ atacFeature#pos.; |
| 183 | uint32cxx . . $ uint32# beg; |
| 184 | |
| 185 | if (m->fwd2cxx . . $ atacMatch#fwd2. == true) { |
| 186 | beg = m->pos2cxx . . $ atacMatch#pos2. + m->len2cxx . . $ atacMatch#len2. - len; |
| 187 | } else { |
| 188 | beg = m->pos2cxx . . $ atacMatch#pos2.; |
| 189 | } |
| 190 | |
| 191 | if (len > 0) |
| 192 | fprintf(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "M u Dprojected"uint32FMTcxx . . $ `libutil/util.h:65:10`!" %s.%s %s:"uint32FMTcxx . . $ `libutil/util.h:65:10`!" "uint32FMTcxx . . $ `libutil/util.h:65:10`!" "uint32FMTcxx . . $ `libutil/util.h:65:10`!" 1 %s:"uint32FMTcxx . . $ `libutil/util.h:65:10`!" "uint32FMTcxx . . $ `libutil/util.h:65:10`!" "uint32FMTcxx . . $ `libutil/util.h:65:10`!" %d\n", |
| 193 | pid, |
| 194 | f->featureuidcxx . . $ atacFeature#featureuid., m->matchuidcxx . . $ atacMatch#matchuid., |
| 195 | AF.labelAcxx . . $ atacFileBase#labelA(41208ce6ca65dd58).(), f->iidcxx . . $ atacFeature#iid., f->poscxx . . $ atacFeature#pos., len, |
| 196 | AF.labelBcxx . . $ atacFileBase#labelB(41208ce6ca65dd58).(), m->iid2cxx . . $ atacMatch#iid2., beg, len, (m->fwd2cxx . . $ atacMatch#fwd2.) ? 1 : -1); |
| 197 | pid++; |
| 198 | fid++; |
| 199 | continue; |
| 200 | } |
| 201 | |
| 202 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "projectFeatures: Unhandled case?\n"); |
| 203 | m->printcxx . . $ atacMatch#print(f61d327ebbdda89f).(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "A", "B"); |
| 204 | f->printcxx . . $ atacFeature#print(22db7a1e1ef6be78).(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "A"); |
| 205 | |
| 206 | assertcxx . . $ `/usr/include/assert.h:102:11`!(0); |
| 207 | } |
| 208 | } |