Debian Codegraph @

atac-driver/libatac/atacFileStreamMerge.C

raw symbols SCIP
1 // This file is part of A2Amapper.cxx . . $ `<file>/atac-driver/libatac/atacFileStreamMerge.C`/
2 // Copyright (c) 2007 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 class afsmcxx . . $ afsm# {
28 public:
29 atacFileStreamcxx . . $ atacFileStream# *_theFilecxx . . $ afsm#_theFile.;
30 atacMatchcxx . . $ atacMatch# *_theMatchcxx . . $ afsm#_theMatch.;
31 atacFeaturecxx . . $ atacFeature# *_theFeaturecxx . . $ afsm#_theFeature.;
32
33 bool _endOfFilecxx . . $ afsm#_endOfFile.;
34
35 afsmcxx . . $ afsm#afsm(49f6e7a06ebc5aa8).() {
36 _theFilecxx . . $ afsm#_theFile. = 0L;
37 _theMatchcxx . . $ afsm#_theMatch. = 0L;
38 _theFeaturecxx . . $ afsm#_theFeature. = 0L;
39 _endOfFilecxx . . $ afsm#_endOfFile. = false;
40 };
41
42 ~cxx . . $ afsm#`~afsm`(ced63f7c635d850d).afsmcxx . . $ afsm#() {
43 };
44 };
45
46
47
48 atacFileStreamMergecxx . . $ atacFileStreamMerge#::atacFileStreamMergecxx . . $ atacFileStreamMerge#atacFileStreamMerge(49f6e7a06ebc5aa8).(void) {
49 _filesLencxx . . $ atacFileStreamMerge#_filesLen. = 0;
50 _filesMaxcxx . . $ atacFileStreamMerge#_filesMax. = 4;
51 _filescxx . . $ atacFileStreamMerge#_files. = new afsmcxx . . $ afsm#afsm(49f6e7a06ebc5aa8). [_filesMaxcxx . . $ atacFileStreamMerge#_filesMax.];
52 _theMatchIIDcxx . . $ atacFileStreamMerge#_theMatchIID. = 0;
53 _theFeatureIIDcxx . . $ atacFileStreamMerge#_theFeatureIID. = 0;
54 }
55
56 atacFileStreamMergecxx . . $ atacFileStreamMerge#::~cxx . . $ atacFileStreamMerge#`~atacFileStreamMerge`(ced63f7c635d850d).atacFileStreamMergecxx . . $ atacFileStreamMerge#(void) {
57 for (uint32cxx . . $ uint32# i=0; i<_filesLencxx . . $ atacFileStreamMerge#_filesLen.; i++)
58 delete _filescxx . . $ atacFileStreamMerge#_files.[i]._theFilecxx . . $ afsm#_theFile.;
59 delete [] _filescxx . . $ atacFileStreamMerge#_files.;
60
61 // But wait! Unless we munge our copies of data, we'll free things
62 // again when atacFileBase destructs!
63 //
64 _seqAcxx . . $ atacFileBase#_seqA. = 0L;
65 _seqBcxx . . $ atacFileBase#_seqB. = 0L;
66 }
67
68
69
70 void
71 atacFileStreamMergecxx . . $ atacFileStreamMerge#::writeHeadercxx . . $ atacFileStreamMerge#writeHeader(8d4262d45fc644ab).(FILE *out) {
72 if (_filescxx . . $ atacFileStreamMerge#_files.[0]._theFilecxx . . $ afsm#_theFile. != 0L)
73 _filescxx . . $ atacFileStreamMerge#_files.[0]._theFilecxx . . $ afsm#_theFile.->writeHeadercxx . . $ atacFileBase#writeHeader(8d4262d45fc644ab).(out);
74 }
75
76
77 void
78 atacFileStreamMergecxx . . $ atacFileStreamMerge#::addFilecxx . . $ atacFileStreamMerge#addFile(85c52e162fed56f9).(char const *filename) {
79
80 if (filename == 0L)
81 return;
82
83 if (_filesLencxx . . $ atacFileStreamMerge#_filesLen. >= _filesMaxcxx . . $ atacFileStreamMerge#_filesMax.) {
84 _filesMaxcxx . . $ atacFileStreamMerge#_filesMax. *= 2;
85 afsmcxx . . $ afsm# *F = new afsmcxx . . $ afsm#afsm(49f6e7a06ebc5aa8). [_filesMaxcxx . . $ atacFileStreamMerge#_filesMax.];
86 memcpy(F, _filescxx . . $ atacFileStreamMerge#_files., sizeof(afsmcxx . . $ afsm#) * _filesLencxx . . $ atacFileStreamMerge#_filesLen.);
87 delete [] _filescxx . . $ atacFileStreamMerge#_files.;
88 _filescxx . . $ atacFileStreamMerge#_files. = F;
89 }
90
91 _filescxx . . $ atacFileStreamMerge#_files.[_filesLencxx . . $ atacFileStreamMerge#_filesLen.]._theFilecxx . . $ afsm#_theFile. = new atacFileStreamcxx . . $ atacFileStream#(filename);
92
93 // Duplicate a bunch of stuff to our file.
94 //
95 if (_filesLencxx . . $ atacFileStreamMerge#_filesLen. == 0) {
96 strcpy(_fileAcxx . . $ atacFileBase#_fileA., _filescxx . . $ atacFileStreamMerge#_files.[_filesLencxx . . $ atacFileStreamMerge#_filesLen.]._theFilecxx . . $ afsm#_theFile.->assemblyFileAcxx . . $ atacFileBase#assemblyFileA(41208ce6ca65dd58).());
97 strcpy(_fileBcxx . . $ atacFileBase#_fileB., _filescxx . . $ atacFileStreamMerge#_files.[_filesLencxx . . $ atacFileStreamMerge#_filesLen.]._theFilecxx . . $ afsm#_theFile.->assemblyFileBcxx . . $ atacFileBase#assemblyFileB(41208ce6ca65dd58).());
98
99 strcpy(_labelAcxx . . $ atacFileBase#_labelA., _filescxx . . $ atacFileStreamMerge#_files.[_filesLencxx . . $ atacFileStreamMerge#_filesLen.]._theFilecxx . . $ afsm#_theFile.->labelAcxx . . $ atacFileBase#labelA(41208ce6ca65dd58).());
100 strcpy(_labelBcxx . . $ atacFileBase#_labelB., _filescxx . . $ atacFileStreamMerge#_files.[_filesLencxx . . $ atacFileStreamMerge#_filesLen.]._theFilecxx . . $ afsm#_theFile.->labelBcxx . . $ atacFileBase#labelB(41208ce6ca65dd58).());
101
102 //_params = _files[_filesLen]._theFile->_params;
103
104 _seqAcxx . . $ atacFileBase#_seqA. = _filescxx . . $ atacFileStreamMerge#_files.[_filesLencxx . . $ atacFileStreamMerge#_filesLen.]._theFilecxx . . $ afsm#_theFile.->fastaAcxx . . $ atacFileBase#fastaA(e73a05296fa21060).();
105 _seqBcxx . . $ atacFileBase#_seqB. = _filescxx . . $ atacFileStreamMerge#_files.[_filesLencxx . . $ atacFileStreamMerge#_filesLen.]._theFilecxx . . $ afsm#_theFile.->fastaBcxx . . $ atacFileBase#fastaB(e73a05296fa21060).();
106 }
107
108 _filesLencxx . . $ atacFileStreamMerge#_filesLen.++;
109 }
110
111
112
113 atacMatchcxx . . $ atacMatch#*
114 atacFileStreamMergecxx . . $ atacFileStreamMerge#::nextMatchcxx . . $ atacFileStreamMerge#nextMatch(7b3c5176a3224eae).(char type) {
115 atacMatchcxx . . $ atacMatch# *theMatch;
116 uint32cxx . . $ uint32# theMatchIdx;
117
118 // Make sure everyone has a match
119 //
120 for (uint32cxx . . $ uint32# i=0; i<_filesLencxx . . $ atacFileStreamMerge#_filesLen.; i++) {
121 if (_filescxx . . $ atacFileStreamMerge#_files.[i]._endOfFilecxx . . $ afsm#_endOfFile. == false) {
122 if (_filescxx . . $ atacFileStreamMerge#_files.[i]._theMatchcxx . . $ afsm#_theMatch. == 0L)
123 _filescxx . . $ atacFileStreamMerge#_files.[i]._theMatchcxx . . $ afsm#_theMatch. = _filescxx . . $ atacFileStreamMerge#_files.[i]._theFilecxx . . $ afsm#_theFile.->nextMatchcxx . . $ atacFileStream#nextMatch(7b3c5176a3224eae).(type);
124 if (_filescxx . . $ atacFileStreamMerge#_files.[i]._theMatchcxx . . $ afsm#_theMatch. == 0L)
125 _filescxx . . $ atacFileStreamMerge#_files.[i]._endOfFilecxx . . $ afsm#_endOfFile. = true;
126 }
127 }
128
129 // Pick the smallest.
130 //
131 theMatch = _filescxx . . $ atacFileStreamMerge#_files.[0]._theMatchcxx . . $ afsm#_theMatch.;
132 theMatchIdx = 0;
133
134
135 // need to set matchIID
136 // should probably also make a new match UID, or better, fix seatac to make UIDs
137
138
139 for (uint32cxx . . $ uint32# i=1; i<_filesLencxx . . $ atacFileStreamMerge#_filesLen.; i++) {
140 if (_filescxx . . $ atacFileStreamMerge#_files.[i]._theMatchcxx . . $ afsm#_theMatch.) {
141 if (theMatch == 0L) {
142 theMatch = _filescxx . . $ atacFileStreamMerge#_files.[i]._theMatchcxx . . $ afsm#_theMatch.;
143 theMatchIdx = i;
144 }
145
146 if (theMatch) {
147 if (_filescxx . . $ atacFileStreamMerge#_files.[i]._theMatchcxx . . $ afsm#_theMatch.->iid1cxx . . $ atacMatch#iid1. < theMatch->iid1cxx . . $ atacMatch#iid1.) {
148 theMatch = _filescxx . . $ atacFileStreamMerge#_files.[i]._theMatchcxx . . $ afsm#_theMatch.;
149 theMatchIdx = i;
150 }
151
152 if ((_filescxx . . $ atacFileStreamMerge#_files.[i]._theMatchcxx . . $ afsm#_theMatch.->iid1cxx . . $ atacMatch#iid1. <= theMatch->iid1cxx . . $ atacMatch#iid1.) &&
153 (_filescxx . . $ atacFileStreamMerge#_files.[i]._theMatchcxx . . $ afsm#_theMatch.->iid2cxx . . $ atacMatch#iid2. <= theMatch->iid2cxx . . $ atacMatch#iid2.)) {
154 theMatch = _filescxx . . $ atacFileStreamMerge#_files.[i]._theMatchcxx . . $ afsm#_theMatch.;
155 theMatchIdx = i;
156 }
157 }
158 }
159 }
160
161 // Mark it as used
162 //
163 _filescxx . . $ atacFileStreamMerge#_files.[theMatchIdx]._theMatchcxx . . $ afsm#_theMatch. = 0L;
164
165 return(theMatch);
166 }
167
168
169 atacFeaturecxx . . $ atacFeature#*
170 atacFileStreamMergecxx . . $ atacFileStreamMerge#::nextFeaturecxx . . $ atacFileStreamMerge#nextFeature(89eb56ca9d01cd3f).(char type[4]) {
171 return(0L);
172 }