| 1 | // This file is part of A2Amapper.cxx . . $ `<file>/seatac/filter-heavychains.C`/ |
| 2 | // Copyright (c) 2004 Applera Corporation |
| 3 | // Copyright (c) 2005 The J. Craig Venter Institute |
| 4 | // Author: Clark Mobarry |
| 5 | // Author: Brian Walenz |
| 6 | // |
| 7 | // This program is free software; you can redistribute it and/or modify |
| 8 | // it under the terms of the GNU General Public License as published by |
| 9 | // the Free Software Foundation; either version 2 of the License, or |
| 10 | // (at your option) any later version. |
| 11 | // |
| 12 | // This program is distributed in the hope that it will be useful, |
| 13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | // GNU General Public License for more details. |
| 16 | // |
| 17 | // You should have received (LICENSE.txt) a copy of the GNU General Public |
| 18 | // License along with this program; if not, write to the Free Software |
| 19 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 20 | |
| 21 | #include <stdio.h> |
| 22 | #include <stdlib.h> |
| 23 | |
| 24 | #include "util++.H"cxx . . $ `<file>/libutil/util++.H`/ |
| 25 | #include "heavychains.H"cxx . . $ `<file>/seatac/heavychains.H`/ |
| 26 | |
| 27 | |
| 28 | extern "C" { |
| 29 | void *construct(char *options); |
| 30 | void destruct(void *handle); |
| 31 | void addHit(void *handle, |
| 32 | char orientation, |
| 33 | uint32cxx . . $ uint32# id1, |
| 34 | uint32cxx . . $ uint32# pos1, |
| 35 | uint32cxx . . $ uint32# len1, |
| 36 | uint32cxx . . $ uint32# id2, |
| 37 | uint32cxx . . $ uint32# pos2, |
| 38 | uint32cxx . . $ uint32# len2, |
| 39 | uint32cxx . . $ uint32# filled); |
| 40 | void filter(void *handle); |
| 41 | uint64cxx . . $ uint64# output(void *handle, FILE *file, uint64cxx . . $ uint64# matchid); |
| 42 | |
| 43 | void *constructStats(char *options); |
| 44 | void destructStats(void *handle); |
| 45 | void addStats(void *handle, void *sp); |
| 46 | void showStats(void *handle, FILE *file); |
| 47 | } |
| 48 | |
| 49 | |
| 50 | |
| 51 | // HeavyChains is implemented in the StrandPair class. It takes all |
| 52 | // hits for a single pair of sequences and....does something. Seatac |
| 53 | // gives the filterObj interface (aka, the interface in this file) |
| 54 | // all hits for a single sequence to the whole genome (or part of). |
| 55 | // So, the StrandPairManager acts as the, uhhh, manager for a bunch |
| 56 | // of StrandPairs, ensuring that each StrandPair is in fact a pair. |
| 57 | // |
| 58 | // It is interface compatible with a StrandPair. |
| 59 | // |
| 60 | class StrandPairManagercxx . . $ StrandPairManager# { |
| 61 | private: |
| 62 | int beVerbosecxx . . $ StrandPairManager#beVerbose.; |
| 63 | char assemblyId1cxx . . $ StrandPairManager#assemblyId1.[32]; |
| 64 | char assemblyId2cxx . . $ StrandPairManager#assemblyId2.[32]; |
| 65 | int maxJumpcxx . . $ StrandPairManager#maxJump.; // Default maximum intra-run jump allowed in a good run. |
| 66 | double minScorecxx . . $ StrandPairManager#minScore.; // Default minimum of bp filled in a good run. |
| 67 | |
| 68 | bool isForwardcxx . . $ StrandPairManager#isForward.; |
| 69 | |
| 70 | StrandPaircxx . . $ StrandPair# *Pcxx . . $ StrandPairManager#P.; |
| 71 | StrandPaircxx . . $ StrandPair# *Prootcxx . . $ StrandPairManager#Proot.; |
| 72 | public: |
| 73 | StrandPairManagercxx . . $ StrandPairManager#StrandPairManager(4a15d145234c1b0a).(bool verbose, |
| 74 | char *assemblyid1, |
| 75 | char *assemblyid2, |
| 76 | int maxjump, |
| 77 | double minscore) { |
| 78 | beVerbosecxx . . $ StrandPairManager#beVerbose. = verbose; |
| 79 | strncpy(assemblyId1cxx . . $ StrandPairManager#assemblyId1., assemblyid1, 31); |
| 80 | strncpy(assemblyId2cxx . . $ StrandPairManager#assemblyId2., assemblyid2, 31); |
| 81 | maxJumpcxx . . $ StrandPairManager#maxJump. = maxjump; |
| 82 | minScorecxx . . $ StrandPairManager#minScore. = minscore; |
| 83 | |
| 84 | isForwardcxx . . $ StrandPairManager#isForward. = true; |
| 85 | |
| 86 | Prootcxx . . $ StrandPairManager#Proot. = 0L; |
| 87 | Pcxx . . $ StrandPairManager#P. = 0L; |
| 88 | }; |
| 89 | |
| 90 | ~cxx . . $ StrandPairManager#`~StrandPairManager`(ced63f7c635d850d).StrandPairManagercxx . . $ StrandPairManager#(void) { |
| 91 | Pcxx . . $ StrandPairManager#P. = Prootcxx . . $ StrandPairManager#Proot.; |
| 92 | while (Prootcxx . . $ StrandPairManager#Proot.) { |
| 93 | Prootcxx . . $ StrandPairManager#Proot. = Prootcxx . . $ StrandPairManager#Proot.->nextcxx . . $ StrandPair#next(a28089bb81c67400).(); |
| 94 | delete Pcxx . . $ StrandPairManager#P.; |
| 95 | Pcxx . . $ StrandPairManager#P. = Prootcxx . . $ StrandPairManager#Proot.; |
| 96 | } |
| 97 | }; |
| 98 | |
| 99 | void addHitcxx . . $ StrandPairManager#addHit(a209694d0a1a92e0).(char direction, |
| 100 | uint32cxx . . $ uint32# id1, |
| 101 | uint32cxx . . $ uint32# xlo, |
| 102 | uint32cxx . . $ uint32# xln, |
| 103 | uint32cxx . . $ uint32# id2, |
| 104 | uint32cxx . . $ uint32# ylo, |
| 105 | uint32cxx . . $ uint32# yln, |
| 106 | uint32cxx . . $ uint32# filled) { |
| 107 | |
| 108 | // We're given hits for exactly one id2 and all id1, forward hits |
| 109 | // followed by reverse hits. Which means that id1 makes two |
| 110 | // passes through, both passes are increasing (enforced by the |
| 111 | // seqStream used in seatac). |
| 112 | // |
| 113 | // A linked list of strand pairs is kept (the links are built |
| 114 | // into StrandPair for convenience), each strand pair knows it's |
| 115 | // pair of ids. |
| 116 | // |
| 117 | |
| 118 | // No root? Make one and add the hit. |
| 119 | // |
| 120 | if (Prootcxx . . $ StrandPairManager#Proot. == 0L) { |
| 121 | Pcxx . . $ StrandPairManager#P. = Prootcxx . . $ StrandPairManager#Proot. = new StrandPaircxx . . $ StrandPair#(beVerbosecxx . . $ StrandPairManager#beVerbose., assemblyId1cxx . . $ StrandPairManager#assemblyId1., assemblyId2cxx . . $ StrandPairManager#assemblyId2., maxJumpcxx . . $ StrandPairManager#maxJump., minScorecxx . . $ StrandPairManager#minScore.); |
| 122 | Pcxx . . $ StrandPairManager#P.->addHitcxx . . $ StrandPair#addHit(a209694d0a1a92e0).(direction, id1, xlo, xln, id2, ylo, yln, filled); |
| 123 | return; |
| 124 | } |
| 125 | |
| 126 | // Reset to the start if we just switched from forward to |
| 127 | // reverse. This is also the only time that the sequence id can |
| 128 | // decrease, and we might have to make a new root. |
| 129 | // |
| 130 | if (isForwardcxx . . $ StrandPairManager#isForward. && (direction == 'r')) { |
| 131 | isForwardcxx . . $ StrandPairManager#isForward. = false; |
| 132 | |
| 133 | if (id1 < Prootcxx . . $ StrandPairManager#Proot.->sequenceIID1cxx . . $ StrandPair#sequenceIID1(db52760e79bf9054).()) { |
| 134 | StrandPaircxx . . $ StrandPair# *N = new StrandPaircxx . . $ StrandPair#(beVerbosecxx . . $ StrandPairManager#beVerbose., assemblyId1cxx . . $ StrandPairManager#assemblyId1., assemblyId2cxx . . $ StrandPairManager#assemblyId2., maxJumpcxx . . $ StrandPairManager#maxJump., minScorecxx . . $ StrandPairManager#minScore.); |
| 135 | N->addHitcxx . . $ StrandPair#addHit(a209694d0a1a92e0).(direction, id1, xlo, xln, id2, ylo, yln, filled); |
| 136 | N->addNextcxx . . $ StrandPair#addNext(b43a089d41c6f7f7).(Prootcxx . . $ StrandPairManager#Proot.); |
| 137 | Pcxx . . $ StrandPairManager#P. = Prootcxx . . $ StrandPairManager#Proot. = N; |
| 138 | return; |
| 139 | } |
| 140 | |
| 141 | Pcxx . . $ StrandPairManager#P. = Prootcxx . . $ StrandPairManager#Proot.; |
| 142 | } |
| 143 | |
| 144 | // Verify that id1 didn't decrease. |
| 145 | // |
| 146 | if (id1 < Pcxx . . $ StrandPairManager#P.->sequenceIID1cxx . . $ StrandPair#sequenceIID1(db52760e79bf9054).()) { |
| 147 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Why did the sequence id just decrease? This should not have happened.\n"); |
| 148 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Crash. %s at line %d\n", __FILE__, __LINE__ - 2); |
| 149 | exitcxx . . $ exit(44ed87f96534fad7).(1); |
| 150 | } |
| 151 | |
| 152 | // Move to the node just before, or exactly at, the one we want |
| 153 | // to add to. Remember, id1 never decreases. |
| 154 | // |
| 155 | while ((Pcxx . . $ StrandPairManager#P.->nextcxx . . $ StrandPair#next(a28089bb81c67400).()) && (Pcxx . . $ StrandPairManager#P.->nextcxx . . $ StrandPair#next(a28089bb81c67400).()->sequenceIID1cxx . . $ StrandPair#sequenceIID1(db52760e79bf9054).() <= id1)) |
| 156 | Pcxx . . $ StrandPairManager#P. = Pcxx . . $ StrandPairManager#P.->nextcxx . . $ StrandPair#next(a28089bb81c67400).(); |
| 157 | |
| 158 | // If we're not at the correct node, insert one after the |
| 159 | // current, and make it the correct one. |
| 160 | // |
| 161 | if (Pcxx . . $ StrandPairManager#P.->sequenceIID1cxx . . $ StrandPair#sequenceIID1(db52760e79bf9054).() != id1) { |
| 162 | StrandPaircxx . . $ StrandPair# *NP = new StrandPaircxx . . $ StrandPair#(beVerbosecxx . . $ StrandPairManager#beVerbose., assemblyId1cxx . . $ StrandPairManager#assemblyId1., assemblyId2cxx . . $ StrandPairManager#assemblyId2., maxJumpcxx . . $ StrandPairManager#maxJump., minScorecxx . . $ StrandPairManager#minScore.); |
| 163 | NP->addNextcxx . . $ StrandPair#addNext(b43a089d41c6f7f7).(Pcxx . . $ StrandPairManager#P.->nextcxx . . $ StrandPair#next(a28089bb81c67400).()); |
| 164 | Pcxx . . $ StrandPairManager#P.->addNextcxx . . $ StrandPair#addNext(b43a089d41c6f7f7).(NP); |
| 165 | Pcxx . . $ StrandPairManager#P. = NP; // Hooray! |
| 166 | } |
| 167 | |
| 168 | // And now we can just add the hit. |
| 169 | // |
| 170 | Pcxx . . $ StrandPairManager#P.->addHitcxx . . $ StrandPair#addHit(a209694d0a1a92e0).(direction, id1, xlo, xln, id2, ylo, yln, filled); |
| 171 | }; |
| 172 | |
| 173 | void processcxx . . $ StrandPairManager#process(49f6e7a06ebc5aa8).(void) { |
| 174 | for (StrandPaircxx . . $ StrandPair# *SP=Prootcxx . . $ StrandPairManager#Proot.; SP; SP=SP->nextcxx . . $ StrandPair#next(a28089bb81c67400).()) |
| 175 | SP->processcxx . . $ StrandPair#process(49f6e7a06ebc5aa8).(); |
| 176 | }; |
| 177 | |
| 178 | uint64cxx . . $ uint64# printcxx . . $ StrandPairManager#print(9bd1d5b934681de1).(FILE *outF, uint64cxx . . $ uint64# matchid) { |
| 179 | for (StrandPaircxx . . $ StrandPair# *SP=Prootcxx . . $ StrandPairManager#Proot.; SP; SP=SP->nextcxx . . $ StrandPair#next(a28089bb81c67400).()) |
| 180 | matchid = SP->printcxx . . $ StrandPair#print(9bd1d5b934681de1).(outF, matchid); |
| 181 | return(matchid); |
| 182 | }; |
| 183 | |
| 184 | void addStatscxx . . $ StrandPairManager#addStats(7e4cc58128767af3).(TheStatscxx . . $ TheStats# *ST) { |
| 185 | for (StrandPaircxx . . $ StrandPair# *SP=Prootcxx . . $ StrandPairManager#Proot.; SP; SP=SP->nextcxx . . $ StrandPair#next(a28089bb81c67400).()) |
| 186 | ST->addcxx . . $ TheStats#add(b43a089d41c6f7f7).(SP); |
| 187 | }; |
| 188 | }; |
| 189 | |
| 190 | |
| 191 | |
| 192 | |
| 193 | |
| 194 | |
| 195 | |
| 196 | |
| 197 | void* |
| 198 | constructcxx . . $ construct(8176fcad44ba9a1b).(char *options) { |
| 199 | int beVerbose = 0; |
| 200 | char assemblyIdD[4] = { 'U', 'N', 'K', 0 }; |
| 201 | char *assemblyId1 = assemblyIdD; |
| 202 | char *assemblyId2 = assemblyIdD; |
| 203 | double minScore = 100.0; // Default minimum of bp filled in a good run. |
| 204 | int maxJump = 100000; // Default maximum intra-run jump allowed in a good run. |
| 205 | |
| 206 | // Parse the options to find the parameters |
| 207 | // |
| 208 | splitToWordscxx . . $ splitToWords# Wcxx . . $ splitToWords#splitToWords(fda57c8427c60377).(options); |
| 209 | |
| 210 | uint32cxx . . $ uint32# arg = 0; |
| 211 | while (arg < W.numWordscxx . . $ splitToWords#numWords(db52760e79bf9054).()) { |
| 212 | if (strcmp(W.getWordcxx . . $ splitToWords#getWord(f109d7e0a0ca42b3).(arg), "-v") == 0) { |
| 213 | beVerbose++; |
| 214 | } else if (strcmp(W.getWordcxx . . $ splitToWords#getWord(f109d7e0a0ca42b3).(arg), "-s") == 0) { |
| 215 | minScore = atofcxx . . $ atof(9b0361fcbc284e4f).(W.getWordcxx . . $ splitToWords#getWord(f109d7e0a0ca42b3).(++arg)); |
| 216 | } else if (strcmp(W.getWordcxx . . $ splitToWords#getWord(f109d7e0a0ca42b3).(arg), "-j") == 0) { |
| 217 | maxJump = atoicxx . . $ atoi(f5ecf3191ed0cd93).(W.getWordcxx . . $ splitToWords#getWord(f109d7e0a0ca42b3).(++arg)); |
| 218 | } else if (strcmp(W.getWordcxx . . $ splitToWords#getWord(f109d7e0a0ca42b3).(arg), "-1") == 0) { |
| 219 | assemblyId1 = W.getWordcxx . . $ splitToWords#getWord(f109d7e0a0ca42b3).(++arg); |
| 220 | } else if (strcmp(W.getWordcxx . . $ splitToWords#getWord(f109d7e0a0ca42b3).(arg), "-2") == 0) { |
| 221 | assemblyId2 = W.getWordcxx . . $ splitToWords#getWord(f109d7e0a0ca42b3).(++arg); |
| 222 | } |
| 223 | |
| 224 | arg++; |
| 225 | } |
| 226 | |
| 227 | return((void *)(new StrandPairManagercxx . . $ StrandPairManager#(beVerbose, assemblyId1, assemblyId2, maxJump, minScore))); |
| 228 | } |
| 229 | |
| 230 | void |
| 231 | destructcxx . . $ destruct(5d22bdacc48458e8).(void *handle) { |
| 232 | delete (StrandPairManagercxx . . $ StrandPairManager# *)handle; |
| 233 | } |
| 234 | |
| 235 | void |
| 236 | addHitcxx . . $ addHit(460980392104da20).(void *handle, |
| 237 | char orientation, |
| 238 | uint32cxx . . $ uint32# id1, |
| 239 | uint32cxx . . $ uint32# pos1, |
| 240 | uint32cxx . . $ uint32# len1, |
| 241 | uint32cxx . . $ uint32# id2, |
| 242 | uint32cxx . . $ uint32# pos2, |
| 243 | uint32cxx . . $ uint32# len2, |
| 244 | uint32cxx . . $ uint32# filled) { |
| 245 | ((StrandPairManagercxx . . $ StrandPairManager# *)handle)->addHitcxx . . $ StrandPairManager#addHit(a209694d0a1a92e0).(orientation, id1, pos1, len1, id2, pos2, len2, filled); |
| 246 | } |
| 247 | |
| 248 | void |
| 249 | filtercxx . . $ filter(5d22bdacc48458e8).(void *handle) { |
| 250 | ((StrandPairManagercxx . . $ StrandPairManager# *)handle)->processcxx . . $ StrandPairManager#process(49f6e7a06ebc5aa8).(); |
| 251 | } |
| 252 | |
| 253 | |
| 254 | uint64cxx . . $ uint64# |
| 255 | outputcxx . . $ output(8d1d8843ae0f6bd5).(void *handle, FILE *file, uint64cxx . . $ uint64# matchid) { |
| 256 | return(((StrandPairManagercxx . . $ StrandPairManager# *)handle)->printcxx . . $ StrandPairManager#print(9bd1d5b934681de1).(file, matchid)); |
| 257 | } |
| 258 | |
| 259 | |
| 260 | |
| 261 | |
| 262 | |
| 263 | |
| 264 | void* |
| 265 | constructStatscxx . . $ constructStats(8176fcad44ba9a1b).(char *options) { |
| 266 | int beVerbose = 0; |
| 267 | char assemblyIdD[4] = { 'U', 'N', 'K', 0 }; |
| 268 | char *assemblyId1 = assemblyIdD; |
| 269 | char *assemblyId2 = assemblyIdD; |
| 270 | double minScore = 100.0; // Default minimum of bp filled in a good run. |
| 271 | int maxJump = 100000; // Default maximum intra-run jump allowed in a good run. |
| 272 | |
| 273 | // Parse the options to find the parameters |
| 274 | // |
| 275 | splitToWordscxx . . $ splitToWords# Wcxx . . $ splitToWords#splitToWords(fda57c8427c60377).(options); |
| 276 | |
| 277 | uint32cxx . . $ uint32# arg = 0; |
| 278 | while (arg < W.numWordscxx . . $ splitToWords#numWords(db52760e79bf9054).()) { |
| 279 | if (strcmp(W.getWordcxx . . $ splitToWords#getWord(f109d7e0a0ca42b3).(arg), "-v") == 0) { |
| 280 | beVerbose++; |
| 281 | } else if (strcmp(W.getWordcxx . . $ splitToWords#getWord(f109d7e0a0ca42b3).(arg), "-s") == 0) { |
| 282 | minScore = atofcxx . . $ atof(9b0361fcbc284e4f).(W.getWordcxx . . $ splitToWords#getWord(f109d7e0a0ca42b3).(++arg)); |
| 283 | } else if (strcmp(W.getWordcxx . . $ splitToWords#getWord(f109d7e0a0ca42b3).(arg), "-j") == 0) { |
| 284 | maxJump = atoicxx . . $ atoi(f5ecf3191ed0cd93).(W.getWordcxx . . $ splitToWords#getWord(f109d7e0a0ca42b3).(++arg)); |
| 285 | } else if (strcmp(W.getWordcxx . . $ splitToWords#getWord(f109d7e0a0ca42b3).(arg), "-1") == 0) { |
| 286 | assemblyId1 = W.getWordcxx . . $ splitToWords#getWord(f109d7e0a0ca42b3).(++arg); |
| 287 | } else if (strcmp(W.getWordcxx . . $ splitToWords#getWord(f109d7e0a0ca42b3).(arg), "-2") == 0) { |
| 288 | assemblyId2 = W.getWordcxx . . $ splitToWords#getWord(f109d7e0a0ca42b3).(++arg); |
| 289 | } |
| 290 | |
| 291 | arg++; |
| 292 | } |
| 293 | |
| 294 | return((void *)(new TheStatscxx . . $ TheStats#(beVerbose, assemblyId1, assemblyId2, maxJump, minScore))); |
| 295 | } |
| 296 | |
| 297 | void |
| 298 | destructStatscxx . . $ destructStats(5d22bdacc48458e8).(void *handle) { |
| 299 | delete (TheStatscxx . . $ TheStats# *)handle; |
| 300 | } |
| 301 | |
| 302 | void |
| 303 | addStatscxx . . $ addStats(6c58c5e2437d25a2).(void *handle, void *sp) { |
| 304 | |
| 305 | // We aren't getting a single StrandPair anymore, we're getting a StrandPairManager now. |
| 306 | // |
| 307 | //((TheStats *)handle)->add((StrandPair *)sp); |
| 308 | // |
| 309 | ((StrandPairManagercxx . . $ StrandPairManager# *)sp)->addStatscxx . . $ StrandPairManager#addStats(7e4cc58128767af3).((TheStatscxx . . $ TheStats# *)handle); |
| 310 | } |
| 311 | |
| 312 | void |
| 313 | showStatscxx . . $ showStats(731a702ce4a38a2f).(void *handle, FILE *file) { |
| 314 | ((TheStatscxx . . $ TheStats# *)handle)->showcxx . . $ TheStats#show(8d4262d45fc644ab).(file); |
| 315 | } |