| 1 | // This file is part of A2Amapper.cxx . . $ `<file>/atac-driver/libatac/atacFile.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 | #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 | |
| 27 | static |
| 28 | bool |
| 29 | isHeadercxx . . $ isHeader(c6b7e35ff6de5671).(char *inLine) { |
| 30 | return((inLine[0] == '!') || |
| 31 | (inLine[0] == '#') || |
| 32 | (inLine[0] == '/')); |
| 33 | } |
| 34 | |
| 35 | |
| 36 | atacFileStreamcxx . . $ atacFileStream#::atacFileStreamcxx . . $ atacFileStream#atacFileStream(85c52e162fed56f9).(char const *filename) { |
| 37 | |
| 38 | if (filename == 0L) |
| 39 | return; |
| 40 | |
| 41 | _inFilecxx . . $ atacFileStream#_inFile. = stdincxx . . $ `<external>/232824719582829767/stdio.h:153:9`!; |
| 42 | |
| 43 | if ((filename != 0L) && (strcmp(filename, "-") != 0)) { |
| 44 | errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = 0; |
| 45 | _inFilecxx . . $ atacFileStream#_inFile. = fopen(filename, "r"); |
| 46 | if (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!) |
| 47 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "atacFileStream::atacFileStream()-- failed to open %s: %s\n", filename, strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)), exitcxx . . $ exit(44ed87f96534fad7).(1); |
| 48 | } |
| 49 | |
| 50 | _theMatchIIDcxx . . $ atacFileStream#_theMatchIID. = 0; |
| 51 | _theFeatureIIDcxx . . $ atacFileStream#_theFeatureIID. = 0; |
| 52 | |
| 53 | readHeadercxx . . $ atacFileBase#readHeader(ee1e387797f67d6).(_inLinecxx . . $ atacFileStream#_inLine., _inFilecxx . . $ atacFileStream#_inFile.); |
| 54 | } |
| 55 | |
| 56 | atacFileStreamcxx . . $ atacFileStream#::~cxx . . $ atacFileStream#`~atacFileStream`(ced63f7c635d850d).atacFileStreamcxx . . $ atacFileStream#() { |
| 57 | }; |
| 58 | |
| 59 | |
| 60 | atacMatchcxx . . $ atacMatch#* |
| 61 | atacFileStreamcxx . . $ atacFileStream#::nextMatchcxx . . $ atacFileStream#nextMatch(7b3c5176a3224eae).(char type) { |
| 62 | atacMatchcxx . . $ atacMatch# *ret = 0L; |
| 63 | |
| 64 | while ((ret == 0L) && |
| 65 | (feof(_inFilecxx . . $ atacFileStream#_inFile.) == false)) { |
| 66 | |
| 67 | if (_inLinecxx . . $ atacFileStream#_inLine.[0] == 'M') { |
| 68 | _theMatchcxx . . $ atacFileStream#_theMatch..decodecxx . . $ atacMatch#decode(fda57c8427c60377).(_inLinecxx . . $ atacFileStream#_inLine.); |
| 69 | |
| 70 | if (_theMatchcxx . . $ atacFileStream#_theMatch..typecxx . . $ atacMatch#type.[0] == type) { |
| 71 | _theMatchcxx . . $ atacFileStream#_theMatch..matchiidcxx . . $ atacMatch#matchiid. = _theMatchIIDcxx . . $ atacFileStream#_theMatchIID.++; |
| 72 | ret = &_theMatchcxx . . $ atacFileStream#_theMatch.; |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | fgets(_inLinecxx . . $ atacFileStream#_inLine., 1024, _inFilecxx . . $ atacFileStream#_inFile.); |
| 77 | } |
| 78 | |
| 79 | return(ret); |
| 80 | } |
| 81 | |
| 82 | |
| 83 | atacFeaturecxx . . $ atacFeature#* |
| 84 | atacFileStreamcxx . . $ atacFileStream#::nextFeaturecxx . . $ atacFileStream#nextFeature(89eb56ca9d01cd3f).(char type[4]) { |
| 85 | atacFeaturecxx . . $ atacFeature# *ret = 0L; |
| 86 | |
| 87 | while ((ret == 0L) && |
| 88 | (feof(_inFilecxx . . $ atacFileStream#_inFile.) == false)) { |
| 89 | |
| 90 | if (_inLinecxx . . $ atacFileStream#_inLine.[0] == 'F') { |
| 91 | _theFeaturecxx . . $ atacFileStream#_theFeature..decodecxx . . $ atacFeature#decode(fda57c8427c60377).(_inLinecxx . . $ atacFileStream#_inLine.); |
| 92 | |
| 93 | // Return the feature if it is the correct type. 0 is the |
| 94 | // wildcard. |
| 95 | // |
| 96 | if (((_theFeaturecxx . . $ atacFileStream#_theFeature..typecxx . . $ atacFeature#type.[0] == 0) || (type[0] == 0) || (_theFeaturecxx . . $ atacFileStream#_theFeature..typecxx . . $ atacFeature#type.[0] == type[0])) && |
| 97 | ((_theFeaturecxx . . $ atacFileStream#_theFeature..typecxx . . $ atacFeature#type.[1] == 0) || (type[1] == 0) || (_theFeaturecxx . . $ atacFileStream#_theFeature..typecxx . . $ atacFeature#type.[1] == type[1])) && |
| 98 | ((_theFeaturecxx . . $ atacFileStream#_theFeature..typecxx . . $ atacFeature#type.[2] == 0) || (type[2] == 0) || (_theFeaturecxx . . $ atacFileStream#_theFeature..typecxx . . $ atacFeature#type.[2] == type[2])) && |
| 99 | ((_theFeaturecxx . . $ atacFileStream#_theFeature..typecxx . . $ atacFeature#type.[3] == 0) || (type[3] == 0) || (_theFeaturecxx . . $ atacFileStream#_theFeature..typecxx . . $ atacFeature#type.[3] == type[3]))) { |
| 100 | _theFeaturecxx . . $ atacFileStream#_theFeature..featureiidcxx . . $ atacFeature#featureiid. = _theFeatureIIDcxx . . $ atacFileStream#_theFeatureIID.++; |
| 101 | ret = &_theFeaturecxx . . $ atacFileStream#_theFeature.; |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | fgets(_inLinecxx . . $ atacFileStream#_inLine., 1024, _inFilecxx . . $ atacFileStream#_inFile.); |
| 106 | } |
| 107 | |
| 108 | return(ret); |
| 109 | } |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | atacFilecxx . . $ atacFile#::atacFilecxx . . $ atacFile#atacFile(85c52e162fed56f9).(char const *filename) { |
| 115 | |
| 116 | if (filename == 0L) |
| 117 | return; |
| 118 | |
| 119 | FILE *inFile = stdincxx . . $ `<external>/232824719582829767/stdio.h:153:9`!; |
| 120 | char inLine[1024]; |
| 121 | |
| 122 | if ((filename != 0L) && (strcmp(filename, "-") != 0)) { |
| 123 | errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = 0; |
| 124 | inFile = fopen(filename, "r"); |
| 125 | if (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!) |
| 126 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "atacFile::atacFile()-- failed to load %s: %s\n", filename, strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)), exitcxx . . $ exit(44ed87f96534fad7).(1); |
| 127 | } |
| 128 | |
| 129 | // Read the preamble, look for our data sources. This leaves us with |
| 130 | // the first match in the inLine, and fills in fileA and fileB. |
| 131 | // |
| 132 | readHeadercxx . . $ atacFileBase#readHeader(ee1e387797f67d6).(inLine, inFile); |
| 133 | |
| 134 | while (!feof(inFile)) { |
| 135 | switch(inLine[0]) { |
| 136 | case 'M': |
| 137 | { |
| 138 | atacMatchcxx . . $ atacMatch# mcxx . . $ atacMatch#atacMatch(fda57c8427c60377).(inLine); |
| 139 | |
| 140 | if (m.sanitycxx . . $ atacMatch#sanity(58b65b0b3b0914b8).(fastaAcxx . . $ atacFileBase#fastaA(e73a05296fa21060).(), fastaBcxx . . $ atacFileBase#fastaB(e73a05296fa21060).(), inLine)) { |
| 141 | if ((m.typecxx . . $ atacMatch#type.[0] == 'u') || |
| 142 | (m.typecxx . . $ atacMatch#type.[0] == 'x')) { |
| 143 | _matchescxx . . $ atacFile#_matches..addcxx . . $ atacMatchList#add(6a5d3ba5dfee27e1).(m); |
| 144 | } else if (m.typecxx . . $ atacMatch#type.[0] == 'r') { |
| 145 | _runscxx . . $ atacFile#_runs..addcxx . . $ atacMatchList#add(6a5d3ba5dfee27e1).(m); |
| 146 | } else if (m.typecxx . . $ atacMatch#type.[0] == 'c') { |
| 147 | _clumpscxx . . $ atacFile#_clumps..addcxx . . $ atacMatchList#add(6a5d3ba5dfee27e1).(m); |
| 148 | } else { |
| 149 | chompcxx . . $ `libutil/util.h:330:9`!(inLine); |
| 150 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "atacFile::atacFile()-- Unknown match record type '%c' -- '%s'.\n", m.typecxx . . $ atacMatch#type.[0], inLine); |
| 151 | } |
| 152 | } |
| 153 | } |
| 154 | break; |
| 155 | |
| 156 | case 'F': |
| 157 | { |
| 158 | chompcxx . . $ `libutil/util.h:330:9`!(inLine); |
| 159 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "atacFile::atacFile()-- Unknown feature record -- '%s'.\n", inLine); |
| 160 | } |
| 161 | break; |
| 162 | |
| 163 | default: |
| 164 | { |
| 165 | chompcxx . . $ `libutil/util.h:330:9`!(inLine); |
| 166 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "atacFile::atacFile()-- Unknown record -- '%s'.\n", inLine); |
| 167 | } |
| 168 | break; |
| 169 | } |
| 170 | |
| 171 | fgets(inLine, 1024, inFile); |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | atacFilecxx . . $ atacFile#::~cxx . . $ atacFile#`~atacFile`(ced63f7c635d850d).atacFilecxx . . $ atacFile#() { |
| 176 | } |
| 177 | |
| 178 | |
| 179 | |
| 180 | |
| 181 | |
| 182 | |
| 183 | |
| 184 | |
| 185 | atacFileBasecxx . . $ atacFileBase#::atacFileBasecxx . . $ atacFileBase#atacFileBase(49f6e7a06ebc5aa8).() { |
| 186 | _fileAcxx . . $ atacFileBase#_fileA.[0] = 0; |
| 187 | _fileBcxx . . $ atacFileBase#_fileB.[0] = 0; |
| 188 | |
| 189 | _labelAcxx . . $ atacFileBase#_labelA.[0] = 0; |
| 190 | _labelBcxx . . $ atacFileBase#_labelB.[0] = 0; |
| 191 | |
| 192 | _seqAcxx . . $ atacFileBase#_seqA. = 0L; |
| 193 | _seqBcxx . . $ atacFileBase#_seqB. = 0L; |
| 194 | } |
| 195 | |
| 196 | |
| 197 | atacFileBasecxx . . $ atacFileBase#::~cxx . . $ atacFileBase#`~atacFileBase`(ced63f7c635d850d).atacFileBasecxx . . $ atacFileBase#() { |
| 198 | delete _seqAcxx . . $ atacFileBase#_seqA.; |
| 199 | delete _seqBcxx . . $ atacFileBase#_seqB.; |
| 200 | } |
| 201 | |
| 202 | |
| 203 | void |
| 204 | atacFileBasecxx . . $ atacFileBase#::readHeadercxx . . $ atacFileBase#readHeader(ee1e387797f67d6).(char *inLine, FILE *in) { |
| 205 | |
| 206 | fgets(inLine, 1024, in); |
| 207 | while (!feof(in) && isHeadercxx . . $ isHeader(c6b7e35ff6de5671).(inLine)) { |
| 208 | chompcxx . . $ `libutil/util.h:330:9`!(inLine); |
| 209 | |
| 210 | if (inLine[0] == '/') { |
| 211 | char *key = inLine + 1; |
| 212 | char *val = inLine + 1; |
| 213 | |
| 214 | while (isspace(*key)) key++; // Skip whitespace between "/" and the key |
| 215 | while (*val != '=') val++; // Move to the "=" |
| 216 | *val++ = 0; // Terminate the key |
| 217 | while (isspace(*val)) val++; // Skip whitespace between "=" and the val |
| 218 | |
| 219 | chompcxx . . $ `libutil/util.h:330:9`!(key); |
| 220 | chompcxx . . $ `libutil/util.h:330:9`!(val); |
| 221 | |
| 222 | //fprintf(stderr, "key='%s' val='%s'\n", key, val); |
| 223 | |
| 224 | stringcxx . . $ std/string# K = keycxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).; |
| 225 | stringcxx . . $ std/string# V = valcxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d).; |
| 226 | _paramscxx . . $ atacFileBase#_params.[cxx . . $ std/map#`operator[]`(bbd415b616967878).K] =cxx . . $ std/__cxx11/basic_string#`operator=`(c0b47be1fddc0e75). V; |
| 227 | |
| 228 | // Save ones we use |
| 229 | |
| 230 | if (strncmp(key, "assemblyFile1", 14) == 0) |
| 231 | strcpy(_fileAcxx . . $ atacFileBase#_fileA., val); |
| 232 | |
| 233 | if (strncmp(key, "assemblyFile2", 14) == 0) |
| 234 | strcpy(_fileBcxx . . $ atacFileBase#_fileB., val); |
| 235 | |
| 236 | if (strncmp(key, "assemblyId1", 12) == 0) |
| 237 | strcpy(_labelAcxx . . $ atacFileBase#_labelA., val); |
| 238 | |
| 239 | if (strncmp(key, "assemblyId2", 12) == 0) |
| 240 | strcpy(_labelBcxx . . $ atacFileBase#_labelB., val); |
| 241 | } |
| 242 | |
| 243 | // Otherwise, it's a comment or the header |
| 244 | |
| 245 | fgets(inLine, 1024, in); |
| 246 | } |
| 247 | |
| 248 | //fprintf(stderr, "assemblyFile1 = '%s'\n", _fileA); |
| 249 | //fprintf(stderr, "assemblyFile2 = '%s'\n", _fileB); |
| 250 | //fprintf(stderr, "assemblyId1 = '%s'\n", _labelA); |
| 251 | //fprintf(stderr, "assemblyId2 = '%s'\n", _labelB); |
| 252 | |
| 253 | // Open some seqCache for each of the files |
| 254 | // |
| 255 | if (_fileAcxx . . $ atacFileBase#_fileA. && _fileAcxx . . $ atacFileBase#_fileA.[0]) { |
| 256 | if (fileExists(_fileAcxx . . $ atacFileBase#_fileA.)) { |
| 257 | _seqAcxx . . $ atacFileBase#_seqA. = new seqCachecxx . . $ seqCache#seqCache(cc76bd1196c143a3).(_fileAcxx . . $ atacFileBase#_fileA.); |
| 258 | } else { |
| 259 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "atacFile::readHeader()-- can't find '%s', no sequence read.\n", _fileAcxx . . $ atacFileBase#_fileA.); |
| 260 | } |
| 261 | } |
| 262 | if (_fileBcxx . . $ atacFileBase#_fileB. && _fileBcxx . . $ atacFileBase#_fileB.[0]) { |
| 263 | if (fileExists(_fileAcxx . . $ atacFileBase#_fileA.)) { |
| 264 | _seqBcxx . . $ atacFileBase#_seqB. = new seqCachecxx . . $ seqCache#seqCache(cc76bd1196c143a3).(_fileBcxx . . $ atacFileBase#_fileB.); |
| 265 | } else { |
| 266 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "atacFile::readHeader()-- can't find '%s', no sequence read.\n", _fileBcxx . . $ atacFileBase#_fileB.); |
| 267 | } |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | |
| 272 | |
| 273 | void |
| 274 | atacFileBasecxx . . $ atacFileBase#::writeHeadercxx . . $ atacFileBase#writeHeader(8d4262d45fc644ab).(FILE *out) { |
| 275 | |
| 276 | if (out == 0L) |
| 277 | out = stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!; |
| 278 | |
| 279 | fprintf(out, "!format atac 1.0\n"); |
| 280 | fprintf(out, "#\n"); |
| 281 | fprintf(out, "# Legend:\n"); |
| 282 | fprintf(out, "#\n"); |
| 283 | fprintf(out, "# Field 0: the row class\n"); |
| 284 | fprintf(out, "# Field 1: the match type u=ungapped, x=exact, ....\n"); |
| 285 | fprintf(out, "# Field 2: the match instance index\n"); |
| 286 | fprintf(out, "# Field 3: the parent index\n"); |
| 287 | fprintf(out, "# Field 4: the FASTA sequence id in the first assembly\n"); |
| 288 | fprintf(out, "# Field 5: the offset from the start of the sequence for the match\n"); |
| 289 | fprintf(out, "# Field 6: the length of the match in the first assembly\n"); |
| 290 | fprintf(out, "# Field 7: the orientation of the match sequence in the first assembly.\n"); |
| 291 | fprintf(out, "# Field 8: the FASTA sequence id for the second assembly\n"); |
| 292 | fprintf(out, "# Field 9: the offset from the start of the sequence for the match\n"); |
| 293 | fprintf(out, "# Field 10: the length of the match in the second assembly\n"); |
| 294 | fprintf(out, "# Field 11: the orientation of the match sequence in the second assembly.\n"); |
| 295 | fprintf(out, "#\n"); |
| 296 | |
| 297 | mapcxx . . $ std/map#<string,string>::iteratorcxx . . $ std/map#iterator# itcxx . . $ std/_Rb_tree_iterator#_Rb_tree_iterator(ced63f7c635d850d).; |
| 298 | for (it=cxx . . $ std/_Rb_tree_iterator#`operator=`(8fcde6b9475a88e3)._paramscxx . . $ atacFileBase#_params..begincxx . . $ std/map#begin(7e4de33083b6e738).(); it !=cxx . . $ std/`operator!=`(be6a71a859368080). _paramscxx . . $ atacFileBase#_params..endcxx . . $ std/map#end(7e4de33083b6e738).(); it++cxx . . $ std/_Rb_tree_iterator#operator++(2987e7ff93f61dc1).) |
| 299 | fprintf(out, "/%s=%s\n", it->cxx . . $ std/_Rb_tree_iterator#`operator->`(34d6acfd341ba7ab).firstcxx . . $ std/pair#first..c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).(), it->cxx . . $ std/_Rb_tree_iterator#`operator->`(34d6acfd341ba7ab).secondcxx . . $ std/pair#second..c_strcxx . . $ std/__cxx11/basic_string#c_str(8e614c7de0b1573e).()); |
| 300 | } |