| 1 | // This file is part of A2Amapper.cxx . . $ `<file>/atac-driver/gapShifter/cleanAtac.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 | // Reads a set of atac matches, trims off ends that are mismatch. |
| 27 | // Computes the percent identity of the resulting match. |
| 28 | // Outputs the trimmed match if it is above some percent identity. |
| 29 | |
| 30 | void |
| 31 | usagecxx . . $ usage(fda57c8427c60377).(char *name) { |
| 32 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "usage: %s [-d identity] [-i identity] -m matches\n", name); |
| 33 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " -d discard the match if it is below this percent identity\n"); |
| 34 | } |
| 35 | |
| 36 | int |
| 37 | maincxx . . $ main(afcd3168fc1188a4).(int argc, char *argv[]) { |
| 38 | char *matchesFile = 0L; |
| 39 | double discardThreshold = 0.0; |
| 40 | uint32cxx . . $ uint32# discardLength = 0; |
| 41 | |
| 42 | int arg=1; |
| 43 | while (arg < argc) { |
| 44 | if (strcmp(argv[arg], "-m") == 0) { |
| 45 | matchesFile = argv[++arg]; |
| 46 | } else if (strcmp(argv[arg], "-d") == 0) { |
| 47 | discardThreshold = atofcxx . . $ atof(9b0361fcbc284e4f).(argv[++arg]); |
| 48 | if (discardThreshold > 1.0) |
| 49 | discardThreshold /= 100; |
| 50 | } else if (strcmp(argv[arg], "-l") == 0) { |
| 51 | discardLength = atoicxx . . $ atoi(f5ecf3191ed0cd93).(argv[++arg]); |
| 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 | |
| 62 | atacFilecxx . . $ atacFile# AFcxx . . $ atacFile#atacFile(85c52e162fed56f9).(matchesFile); |
| 63 | atacMatchListcxx . . $ atacMatchList# &ML = *AF.matchescxx . . $ atacFile#matches(33e88ebc28d05bce).(); |
| 64 | seqCachecxx . . $ seqCache# Acachecxx . . $ seqCache#seqCache(cc76bd1196c143a3).(AF.assemblyFileAcxx . . $ atacFileBase#assemblyFileA(41208ce6ca65dd58).(), 32, false); |
| 65 | seqCachecxx . . $ seqCache# Bcachecxx . . $ seqCache#seqCache(cc76bd1196c143a3).(AF.assemblyFileBcxx . . $ atacFileBase#assemblyFileB(41208ce6ca65dd58).(), 32, false); |
| 66 | |
| 67 | for (uint32cxx . . $ uint32# i=0; i<ML.numMatchescxx . . $ atacMatchList#numMatches(db52760e79bf9054).(); i++) { |
| 68 | atacMatchcxx . . $ atacMatch# *m = ML.getMatchcxx . . $ atacMatchList#getMatch(4b949e4d42dbfd78).(i); |
| 69 | |
| 70 | uint32cxx . . $ uint32# identities = 0; |
| 71 | |
| 72 | //char *a = Acache.getSequenceInCore(m->iid1)->sequence() + m->pos1; |
| 73 | //char *b = Bcache.getSequenceInCore(m->iid2)->sequence() + m->pos2; |
| 74 | //uint32 p, q; |
| 75 | |
| 76 | |
| 77 | // Trim the match |
| 78 | // |
| 79 | if (m->fwd2cxx . . $ atacMatch#fwd2.) { |
| 80 | char *a = Acache.getSequenceInCorecxx . . $ seqCache#getSequenceInCore(715c05706546271f).(m->iid1cxx . . $ atacMatch#iid1.)->sequencecxx . . $ seqInCore#sequence(e7e5aa338b9d5147).() + m->pos1cxx . . $ atacMatch#pos1.; |
| 81 | char *b = Bcache.getSequenceInCorecxx . . $ seqCache#getSequenceInCore(715c05706546271f).(m->iid2cxx . . $ atacMatch#iid2.)->sequencecxx . . $ seqInCore#sequence(e7e5aa338b9d5147).() + m->pos2cxx . . $ atacMatch#pos2.; |
| 82 | uint32cxx . . $ uint32# p = 0; |
| 83 | |
| 84 | while ((m->len1cxx . . $ atacMatch#len1. > 0) && (toUpper[(int)a[p]] != toUpper[(int)b[p]])) { |
| 85 | m->pos1cxx . . $ atacMatch#pos1.++; |
| 86 | m->pos2cxx . . $ atacMatch#pos2.++; |
| 87 | m->len1cxx . . $ atacMatch#len1.--; |
| 88 | m->len2cxx . . $ atacMatch#len2.--; |
| 89 | p++; |
| 90 | } |
| 91 | |
| 92 | a = Acache.getSequenceInCorecxx . . $ seqCache#getSequenceInCore(715c05706546271f).(m->iid1cxx . . $ atacMatch#iid1.)->sequencecxx . . $ seqInCore#sequence(e7e5aa338b9d5147).() + m->pos1cxx . . $ atacMatch#pos1.; |
| 93 | b = Bcache.getSequenceInCorecxx . . $ seqCache#getSequenceInCore(715c05706546271f).(m->iid2cxx . . $ atacMatch#iid2.)->sequencecxx . . $ seqInCore#sequence(e7e5aa338b9d5147).() + m->pos2cxx . . $ atacMatch#pos2.; |
| 94 | p = m->len1cxx . . $ atacMatch#len1.-1; |
| 95 | while ((m->len1cxx . . $ atacMatch#len1. > 0) && (toUpper[(int)a[p]] != toUpper[(int)b[p]])) { |
| 96 | m->len1cxx . . $ atacMatch#len1.--; |
| 97 | m->len2cxx . . $ atacMatch#len2.--; |
| 98 | p--; |
| 99 | } |
| 100 | |
| 101 | } else { |
| 102 | char *a = Acache.getSequenceInCorecxx . . $ seqCache#getSequenceInCore(715c05706546271f).(m->iid1cxx . . $ atacMatch#iid1.)->sequencecxx . . $ seqInCore#sequence(e7e5aa338b9d5147).() + m->pos1cxx . . $ atacMatch#pos1.; |
| 103 | char *b = Bcache.getSequenceInCorecxx . . $ seqCache#getSequenceInCore(715c05706546271f).(m->iid2cxx . . $ atacMatch#iid2.)->sequencecxx . . $ seqInCore#sequence(e7e5aa338b9d5147).() + m->pos2cxx . . $ atacMatch#pos2.; |
| 104 | uint32cxx . . $ uint32# p = 0; |
| 105 | uint32cxx . . $ uint32# q = m->len2cxx . . $ atacMatch#len2. - 1; |
| 106 | |
| 107 | while ((m->len1cxx . . $ atacMatch#len1. > 0) && (toUpper[(int)a[p]] != complementSymbol[toUpper[(int)b[q]]])) { |
| 108 | m->pos1cxx . . $ atacMatch#pos1.++; |
| 109 | m->len1cxx . . $ atacMatch#len1.--; |
| 110 | m->len2cxx . . $ atacMatch#len2.--; |
| 111 | p++; |
| 112 | q--; |
| 113 | } |
| 114 | |
| 115 | a = Acache.getSequenceInCorecxx . . $ seqCache#getSequenceInCore(715c05706546271f).(m->iid1cxx . . $ atacMatch#iid1.)->sequencecxx . . $ seqInCore#sequence(e7e5aa338b9d5147).() + m->pos1cxx . . $ atacMatch#pos1.; |
| 116 | b = Bcache.getSequenceInCorecxx . . $ seqCache#getSequenceInCore(715c05706546271f).(m->iid2cxx . . $ atacMatch#iid2.)->sequencecxx . . $ seqInCore#sequence(e7e5aa338b9d5147).() + m->pos2cxx . . $ atacMatch#pos2.; |
| 117 | p = m->len1cxx . . $ atacMatch#len1. - 1; |
| 118 | q = 0; |
| 119 | while ((m->len1cxx . . $ atacMatch#len1. > 0) && (toUpper[(int)a[p]] != complementSymbol[toUpper[(int)b[q]]])) { |
| 120 | m->len1cxx . . $ atacMatch#len1.--; |
| 121 | m->pos2cxx . . $ atacMatch#pos2.++; |
| 122 | m->len2cxx . . $ atacMatch#len2.--; |
| 123 | p--; |
| 124 | q++; |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | if (m->len1cxx . . $ atacMatch#len1. > 0) { |
| 129 | char *a = Acache.getSequenceInCorecxx . . $ seqCache#getSequenceInCore(715c05706546271f).(m->iid1cxx . . $ atacMatch#iid1.)->sequencecxx . . $ seqInCore#sequence(e7e5aa338b9d5147).() + m->pos1cxx . . $ atacMatch#pos1.; |
| 130 | char *b = Bcache.getSequenceInCorecxx . . $ seqCache#getSequenceInCore(715c05706546271f).(m->iid2cxx . . $ atacMatch#iid2.)->sequencecxx . . $ seqInCore#sequence(e7e5aa338b9d5147).() + m->pos2cxx . . $ atacMatch#pos2.; |
| 131 | |
| 132 | if (m->fwd2cxx . . $ atacMatch#fwd2.) { |
| 133 | for (uint32cxx . . $ uint32# p=0; p<m->len1cxx . . $ atacMatch#len1.; p++) { |
| 134 | if (toUpper[(int)a[p]] == toUpper[(int)b[p]]) |
| 135 | identities++; |
| 136 | } |
| 137 | } else { |
| 138 | for (uint32cxx . . $ uint32# p=0, q=m->len2cxx . . $ atacMatch#len2.-1; p<m->len1cxx . . $ atacMatch#len1.; p++, q--) { |
| 139 | if (toUpper[(int)a[p]] == toUpper[complementSymbol[(int)b[q]]]) |
| 140 | identities++; |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | double myIdentity = (double)identities / m->len1cxx . . $ atacMatch#len1.; |
| 145 | |
| 146 | if ((myIdentity > discardThreshold) && (m->len1cxx . . $ atacMatch#len1. > discardLength)) { |
| 147 | m->printcxx . . $ atacMatch#print(f61d327ebbdda89f).(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, AF.labelAcxx . . $ atacFileBase#labelA(41208ce6ca65dd58).(), AF.labelBcxx . . $ atacFileBase#labelB(41208ce6ca65dd58).()); |
| 148 | } else { |
| 149 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "match "uint32FMTcxx . . $ `libutil/util.h:65:10`!" is only %6.2f%% identity and "uint32FMTcxx . . $ `libutil/util.h:65:10`!" long: ", |
| 150 | i, 100.0 * identities / m->len1cxx . . $ atacMatch#len1., m->len1cxx . . $ atacMatch#len1.); |
| 151 | m->printcxx . . $ atacMatch#print(f61d327ebbdda89f).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, AF.labelAcxx . . $ atacFileBase#labelA(41208ce6ca65dd58).(), AF.labelBcxx . . $ atacFileBase#labelB(41208ce6ca65dd58).()); |
| 152 | if (m->len1cxx . . $ atacMatch#len1. < 200) { |
| 153 | char tmp[1000]; |
| 154 | |
| 155 | strncpy(tmp, a, m->len1cxx . . $ atacMatch#len1.); |
| 156 | tmp[m->len1cxx . . $ atacMatch#len1.] = 0; |
| 157 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " %s\n", tmp); |
| 158 | |
| 159 | strncpy(tmp, b, m->len1cxx . . $ atacMatch#len1.); |
| 160 | tmp[m->len1cxx . . $ atacMatch#len1.] = 0; |
| 161 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " %s\n", tmp); |
| 162 | } |
| 163 | } |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | return(0); |
| 168 | } |