@@ -180,41 +180,54 @@ sqStore::sqStore_addEmptyLibrary(char const *name, sqLibrary_tech techType) {
180
180
181
181
182
182
183
-
183
+
// Allocate and return a new sqReadDataWriter that can be used to add a new
184
+
// read to the store. This function does NOT actually add the read to the
185
+
// store; the sqReadDataWriter is used to collect all the info about the
186
+
// read (read ID, read name, bases, quals, trim points) and then that object
187
+
// is added to the store after all info is added.
188
+
//
189
+
// Because the read isn't added until later, two consecutive calls to
190
+
// createEmptyRead() will result in both sqReadDataWriter objects referring
191
+
// to the same sqRead.
192
+
//
193
+
// (The reason for this annoyance is so that sqStoreCreate can test that the
194
+
// _homopoly_compressed_ length is big enough, and that length is only
195
+
// computed by sqReadDataWriter::setRawBases(). Thus, we need to populate
196
+
// the sqReadDataWriter object, test it, then discard it if too short.)
197
+
//
184
198
sqReadDataWriter *
185
-
sqStore::sqStore_addEmptyRead(sqLibrary *lib, const char *name) {
199
+
sqStore::sqStore_createEmptyRead(sqLibrary *lib, const char *name) {
186
200
187
201
assert(_info.sqInfo_lastReadID() < _readsAlloc);
188
202
assert(_mode != sqStore_readOnly);
189
203
190
-
// We reserve the zeroth read for "null". This is easy to accomplish
191
-
// here, just pre-increment the number of reads. However, we need to be sure
192
-
// to iterate up to and including _info.sqInfo_lastReadID().
204
+
// The zeroth read is "null". To get the next valid read ID, just
205
+
// add one to the current last read ID.
193
206
194
-
_info.sqInfo_addRead();
207
+
uint32 rID = _info.sqInfo_lastReadID() + 1;
208
+
uint32 lID = lib->sqLibrary_libraryID();
195
209
196
-
if (_readsAlloc <= _info.sqInfo_lastReadID()) {
197
-
uint32 newMax = _readsAlloc + _info.sqInfo_lastReadID() / 2;
210
+
// Grow the metadata arrays if they're too small.
198
211
199
-
setArraySize(_meta, _info.sqInfo_lastReadID(), _readsAlloc, newMax);
200
-
setArraySize(_rawU, _info.sqInfo_lastReadID(), _readsAlloc, newMax);
201
-
setArraySize(_rawC, _info.sqInfo_lastReadID(), _readsAlloc, newMax);
202
-
setArraySize(_corU, _info.sqInfo_lastReadID(), _readsAlloc, newMax);
203
-
setArraySize(_corC, _info.sqInfo_lastReadID(), _readsAlloc, newMax);
204
-
}
212
+
if (_readsAlloc <= rID) {
213
+
uint32 newMax = _readsAlloc + rID / 2;
205
214
206
-
// Initialize the new read.
215
+
setArraySize(_meta, rID, _readsAlloc, newMax);
216
+
setArraySize(_rawU, rID, _readsAlloc, newMax);
217
+
setArraySize(_rawC, rID, _readsAlloc, newMax);
218
+
setArraySize(_corU, rID, _readsAlloc, newMax);
219
+
setArraySize(_corC, rID, _readsAlloc, newMax);
220
+
}
207
221
208
-
uint32 rID = _info.sqInfo_lastReadID();
209
-
uint32 lID = lib->sqLibrary_libraryID();
222
+
// Initialize the metadata.
210
223
211
224
_meta[rID].sqReadMeta_initialize(rID, lID);
212
225
_rawU[rID].sqReadSeq_initialize();
213
226
_rawC[rID].sqReadSeq_initialize();
214
227
_corU[rID].sqReadSeq_initialize();
215
228
_corC[rID].sqReadSeq_initialize();
216
229
217
-
// With the read set up, set pointers in the readData. Whatever data is in there can stay.
230
+
// Make a new writer object, and initialize what we can.
218
231
219
232
sqReadDataWriter *rdw = new sqReadDataWriter(&_meta[rID],
220
233
&_rawU[rID],
@@ -229,6 +242,35 @@ sqStore::sqStore_addEmptyRead(sqLibrary *lib, const char *name) {
229
242
230
243
231
244
245
+
// Add a fully initialized read in sqReadDataWriter to the store.
246
+
//
247
+
// This is inherently dangerous. It assumes that the supplied sRDW is
248
+
// actually for the next read.
249
+
//
250
+
// If we're adding a new read - the ID _must_ be one more than the number
251
+
// of reads in the store - increment the number of reads in the metadata.
252
+
//
253
+
// If we're trying to add/modify a read that doesn't exist, blow up.
254
+
//
255
+
// Otherwise, we're modifying an existing read, and need to only write the
256
+
// read data.
257
+
//
258
+
void
259
+
sqStore::sqStore_addRead(sqReadDataWriter *rdw) {
260
+
261
+
if (rdw->_meta->sqRead_readID() == _info.sqInfo_lastReadID() + 1)
262
+
_info.sqInfo_addRead();
263
+
264
+
if (rdw->_meta->sqRead_readID() > _info.sqInfo_lastReadID()) {
265
+
fprintf(stderr, "ERROR: Attempt to add/modify read %u in a store with only %u reads.\n",
266
+
rdw->_meta->sqRead_readID(), _info.sqInfo_lastReadID());
267
+
assert(0);
268
+
}
269
+
270
+
_blobWriter->writeData(rdw);
271
+
}
272
+
273
+
232
274
233
275
void
234
276
sqStore::sqStore_setIgnored(uint32 id,
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4