Skip to content

Commit

Permalink
Change sqReadDataWriter_importData() so that it doesn't write to the …
Browse files Browse the repository at this point in the history
…imported metadata; move set*Bases() from .H to .C.
  • Loading branch information
brianwalenz committed Sep 5, 2020
1 parent 258941d commit dff1b12
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 40 deletions.
39 changes: 3 additions & 36 deletions src/stores/sqRead.H
Original file line number Diff line number Diff line change
Expand Up @@ -548,42 +548,9 @@ public:
public:
void sqReadDataWriter_importData(sqRead *read);

void sqReadDataWriter_setName(const char *N) {
duplicateArray(_name, _nameLen, _nameAlloc, N, (uint32)strlen(N) + 1);
};

// _setBases() doesn't need NUL terminated strings on input, but always
// makes NUL terminated strings for itself.

void sqReadDataWriter_setRawBases(const char *S, uint32 Slen) {
setArraySize(_rawBases, _rawBasesLen, _rawBasesAlloc, Slen+1, resizeArray_doNothing);

memcpy(_rawBases, S, sizeof(char) * Slen);
_rawBases[Slen] = 0;

_rawBasesLen = Slen + 1; // Length INCLUDING NUL, remember?

assert(_rawU->sqReadSeq_valid() == false);
assert(_rawC->sqReadSeq_valid() == false);

_rawU->sqReadSeq_setLength(_rawBases, _rawBasesLen-1, false);
_rawC->sqReadSeq_setLength(_rawBases, _rawBasesLen-1, true);
};

void sqReadDataWriter_setCorrectedBases(const char *S, uint32 Slen) {
setArraySize(_corBases, _corBasesLen, _corBasesAlloc, Slen+1, resizeArray_doNothing);

memcpy(_corBases, S, sizeof(char) * Slen);
_corBases[Slen] = 0;

_corBasesLen = Slen + 1; // Length INCLUDING NUL, remember?

assert(_corU->sqReadSeq_valid() == false);
assert(_corC->sqReadSeq_valid() == false);

_corU->sqReadSeq_setLength(_corBases, _corBasesLen-1, false);
_corC->sqReadSeq_setLength(_corBases, _corBasesLen-1, true);
};
void sqReadDataWriter_setName(const char *N);
void sqReadDataWriter_setRawBases(const char *S, uint32 Slen);
void sqReadDataWriter_setCorrectedBases(const char *S, uint32 Slen);

void sqReadDataWriter_writeBlob(writeBuffer *buffer);

Expand Down
73 changes: 69 additions & 4 deletions src/stores/sqReadDataWriter.C
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,80 @@
void
sqReadDataWriter::sqReadDataWriter_importData(sqRead *read) {

_meta = read->_meta;
_meta = read->_meta; // These point back to the sqStore.
_rawU = read->_rawU;
_rawC = read->_rawC;
_corU = read->_corU;
_corC = read->_corC;

sqReadDataWriter_setName (read->_name);
sqReadDataWriter_setRawBases (read->_rawBases, read->sqRead_length(sqRead_raw));
sqReadDataWriter_setCorrectedBases(read->_corBases, read->sqRead_length(sqRead_corrected));
// Copy the name, raw bases and corrected bases. We cannot use
// setRawBases/setCorrectedBases because those want to change the metadata
// in sqStore -- even though it should be "changing" the value to the same
// thing.
//
// Note that the lengths of these arrays include the NUL terminating byte,
// where the *Len variables below do not.

uint32 namLen = strlen(read->_name);
uint32 rawLen = read->sqRead_length(sqRead_raw);
uint32 corLen = read->sqRead_length(sqRead_corrected);

assert(0 == read->_name[namLen]);
assert(0 == read->_rawBases[rawLen]);
assert(0 == read->_corBases[corLen]);

duplicateArray(_name, _nameLen, _nameAlloc, read->_name, namLen + 1);
duplicateArray(_rawBases, _rawBasesLen, _rawBasesAlloc, read->_rawBases, rawLen + 1);
duplicateArray(_corBases, _corBasesLen, _corBasesAlloc, read->_corBases, corLen + 1);

assert(0 == _name[namLen]);
assert(0 == _rawBases[rawLen]);
assert(0 == _corBases[corLen]);
}



void
sqReadDataWriter::sqReadDataWriter_setName(const char *N) {
duplicateArray(_name, _nameLen, _nameAlloc, N, (uint32)strlen(N) + 1);
}



void
sqReadDataWriter::sqReadDataWriter_setRawBases(const char *S, uint32 Slen) {

setArraySize(_rawBases, _rawBasesLen, _rawBasesAlloc, Slen+1, resizeArray_doNothing);

memcpy(_rawBases, S, sizeof(char) * Slen);
_rawBases[Slen] = 0;

_rawBasesLen = Slen + 1; // Length INCLUDING NUL, remember?

assert(_rawU->sqReadSeq_valid() == false);
assert(_rawC->sqReadSeq_valid() == false);

_rawU->sqReadSeq_setLength(_rawBases, _rawBasesLen-1, false);
_rawC->sqReadSeq_setLength(_rawBases, _rawBasesLen-1, true);
}



void
sqReadDataWriter::sqReadDataWriter_setCorrectedBases(const char *S, uint32 Slen) {

setArraySize(_corBases, _corBasesLen, _corBasesAlloc, Slen+1, resizeArray_doNothing);

memcpy(_corBases, S, sizeof(char) * Slen);
_corBases[Slen] = 0;

_corBasesLen = Slen + 1; // Length INCLUDING NUL, remember?

assert(_corU->sqReadSeq_valid() == false);
assert(_corC->sqReadSeq_valid() == false);

_corU->sqReadSeq_setLength(_corBases, _corBasesLen-1, false);
_corC->sqReadSeq_setLength(_corBases, _corBasesLen-1, true);
}


Expand Down

0 comments on commit dff1b12

Please sign in to comment.