int Encryptor::update() { if (pCaesarSettings->adType == CAESAR_TYPE_COUNTER) { increaseArray(m_ad, pCaesarSettings->adLength); } if (pCaesarSettings->keyType == CAESAR_TYPE_COUNTER) { increaseArray(m_key, pCaesarSettings->keyLength); } if (pCaesarSettings->smnType == CAESAR_TYPE_COUNTER) { increaseArray(m_smn, pCaesarSettings->smnLength); } if (pCaesarSettings->pmnType == CAESAR_TYPE_COUNTER) { increaseArray(m_pmn, pCaesarSettings->pmnLength); } if (pCaesarSettings->plaintextType == CAESAR_TYPE_COUNTER) { increaseArray(m_plaintext, pCaesarSettings->adLength); } return STAT_OK; }
uint16 abColumn::extendRead(abColumn *column, uint16 beadLink) { increaseArray(_beads, _beadsLen, _beadsMax, 1); uint32 link = _beadsLen++; _beads[link]._unused = column->_beads[beadLink]._unused; _beads[link]._isRead = column->_beads[beadLink]._isRead; _beads[link]._isUnitig = column->_beads[beadLink]._isUnitig; _beads[link]._base = '-'; _beads[link]._qual = 0; if (column->_beads[beadLink]._prevOffset == UINT16_MAX) { assert(column->_beads[beadLink]._nextOffset != UINT16_MAX); assert(_nextColumn == column); _beads[link]._prevOffset = UINT16_MAX; _beads[link]._nextOffset = beadLink; column->_beads[beadLink]._prevOffset = link; } else { assert(column->_beads[beadLink]._prevOffset != UINT16_MAX); assert(_prevColumn == column); _beads[link]._prevOffset = beadLink; _beads[link]._nextOffset = UINT16_MAX; column->_beads[beadLink]._nextOffset = link; } return(link); }
gkRead * gkStore::gkStore_addEmptyRead(gkLibrary *lib) { assert(_readsMMap == NULL); assert(_info.numReads <= _readsAlloc); assert(_mode != gkStore_readOnly); // We reserve the zeroth read for "null". This is easy to accomplish // here, just pre-increment the number of reads. However, we need to be sure // to iterate up to and including _info.numReads. _info.numReads++; if (_info.numReads == _readsAlloc) increaseArray(_reads, _info.numReads, _readsAlloc, _info.numReads/2); _reads[_info.numReads] = gkRead(); _reads[_info.numReads]._readID = _info.numReads; _reads[_info.numReads]._libraryID = lib->gkLibrary_libraryID(); //fprintf(stderr, "ADD READ %u = %u alloc = %u\n", _info.numReads, _reads[_info.numReads]._readID, _readsAlloc); return(_reads + _info.numReads); }
abSeqID abAbacus::addRead(gkStore *gkpStore, uint32 readID, uint32 askip, uint32 bskip, bool complemented) { // Grab the read gkRead *read = gkpStore->gkStore_getRead(readID); gkReadData *readData = new gkReadData; //fprintf(stderr, "abAbacus::addRead()-- want readID=%u, store returned read %u\n", // readID, read->gkRead_readID()); gkpStore->gkStore_loadReadData(read, readData); uint32 seqLen = read->gkRead_sequenceLength() - askip - bskip; // Tell abacus about it. increaseArray(_sequences, _sequencesLen, _sequencesMax, 1); abSequence *ns = _sequences + _sequencesLen; ns->initialize(readID, _sequencesLen++, seqLen, complemented, _basesLen, _beadsLen); // Make a complement table char inv[256] = {0}; inv['a'] = 't'; inv['A'] = 'T'; inv['c'] = 'g'; inv['C'] = 'G'; inv['g'] = 'c'; inv['G'] = 'C'; inv['t'] = 'a'; inv['T'] = 'A'; inv['n'] = 'n'; inv['N'] = 'N'; inv['-'] = '-'; // Stash the bases/quals { char *seq = readData->gkReadData_getSequence() + ((complemented == false) ? askip : bskip); char *qlt = readData->gkReadData_getQualities() + ((complemented == false) ? askip : bskip); while (_basesMax <= _basesLen + seqLen + 1) resizeArrayPair(_bases, _quals, _basesLen, _basesMax, 2 * _basesMax); for (uint32 ii=0; ii<seqLen; ii++) assert((seq[ii] == 'A') || (seq[ii] == 'C') || (seq[ii] == 'G') || (seq[ii] == 'T') || (seq[ii] == 'N')); if (complemented == false) for (uint32 ii=0, pp=_basesLen; ii<seqLen; ii++, pp++, _basesLen++) { _bases[pp] = seq[ii]; _quals[pp] = qlt[ii]; assert(CNS_MIN_QV + '0' <= _quals[pp]); assert(_quals[pp] <= CNS_MAX_QV + '0'); } else for (uint32 ii=seqLen, pp=_basesLen; ii-->0; pp++, _basesLen++) { _bases[pp] = inv[ seq[ii] ]; _quals[pp] = qlt[ii]; assert(CNS_MIN_QV + '0' <= _quals[pp]); assert(_quals[pp] <= CNS_MAX_QV + '0'); } _bases[_basesLen] = 0; // NUL terminate the strings so we can use them in aligners _quals[_basesLen] = 0; _basesLen++; } delete readData; // Make beads for each base, set the pointer to the first bead { increaseArray(_beads, _beadsLen, _beadsMax, seqLen); uint32 firstBead = _beadsLen; for (uint32 bp=0; bp<ns->length(); bp++, _beadsLen++) { _beads[_beadsLen].boffset.set(_beadsLen); // Offset into the beads array _beads[_beadsLen].soffset.set(ns->firstBase().get() + bp); // Offset into the sequence array _beads[_beadsLen].foffset = bp; // Offset into the read itself // Check that nothing odd happened with the ident. assert(_beads[_beadsLen].ident().get() == ns->firstBead().get() + bp); // Set previous/next bead appropriately. if (_beads[_beadsLen].foffset == 0) _beads[_beadsLen].prev = abBeadID(); else _beads[_beadsLen].prev.set(_beads[_beadsLen].ident().get() - 1); if (_beads[_beadsLen].foffset == ns->length() - 1) _beads[_beadsLen].next = abBeadID(); else _beads[_beadsLen].next.set(_beads[_beadsLen].ident().get() + 1); _beads[_beadsLen].up = abBeadID(); // No up bead yet. _beads[_beadsLen].down = abBeadID(); // No down bead yet. _beads[_beadsLen].frag_index = ns->ident(); // Bead is for this read idx. _beads[_beadsLen].column_index = abColID(); // Isn't in a column yet. } } assert(_beads[_beadsLen-1].ident() == ns->lastBead()); // Return the (internal) index we saved this read at. #if 0 fprintf(stderr, "read %d firstBead %d lastBead %d _basesLen %u\n", ns->ident().get(), ns->firstBead().get(), ns->lastBead().get(), _basesLen); #endif return(ns->ident()); }
gkLibrary * gkStore::gkStore_addEmptyLibrary(char const *name) { assert(_librariesMMap == NULL); assert(_info.numLibraries <= _librariesAlloc); // Library[0] doesn't exist, see comments in addEmptyRead below. _info.numLibraries++; if (_info.numLibraries == _librariesAlloc) increaseArray(_libraries, _info.numLibraries, _librariesAlloc, 128); // Bullet proof the library name - so we can make files with this prefix. char libname[LIBRARY_NAME_SIZE]; uint32 libnamepos = 0; bool modified = false; bool truncated = false; for (char const *orig=name; *orig; orig++) { if (*orig == '/') { libname[libnamepos++] = '_'; libname[libnamepos++] = '-'; libname[libnamepos++] = '_'; modified = true; } else if (isspace(*orig) == 0) { libname[libnamepos++] = *orig; } else { libname[libnamepos++] = '_'; modified = true; } if (libnamepos >= LIBRARY_NAME_SIZE) { libname[LIBRARY_NAME_SIZE-1] = 0; truncated = true; break; } } libname[libnamepos] = 0; #if 0 if (modified || truncated) fprintf(stderr, "gkStore_addEmptyLibrary()-- added library '%s' (original name '%s')\n", libname, name); else fprintf(stderr, "gkStore_addEmptyLibrary()-- added library '%s'\n", libname); #endif _libraries[_info.numLibraries] = gkLibrary(); strcpy(_libraries[_info.numLibraries]._libraryName, libname); _libraries[_info.numLibraries]._libraryID = _info.numLibraries; return(_libraries + _info.numLibraries); }