Skip to content

Commit

Permalink
Fix issues detected by random-test
Browse files Browse the repository at this point in the history
  • Loading branch information
Rone committed May 30, 2020
1 parent b15af56 commit 13055ff
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 28 deletions.
10 changes: 5 additions & 5 deletions bowtie_inspect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static void printUsage(ostream& out) {
<< "Options:" << endl;
if(wrapper == "basic-0") {
out << " --large-index force inspection of the 'large' index, even if a" << endl
<< " 'small' one is present." << endl;
<< " 'small' one is present." << endl;
}
out << " -a/--across <int> Number of characters across in FASTA output (default: 60)" << endl
<< " -n/--names Print reference sequence names only" << endl
Expand All @@ -74,9 +74,9 @@ static void printUsage(ostream& out) {
if(wrapper.empty()) {
cerr << endl
<< "*** Warning ***" << endl
<< "'boowtie-inspect' was run directly. It is recommended "
<< "to use the wrapper script instead."
<< endl << endl;
<< "'bowtie-inspect' was run directly. It is recommended "
<< "to use the wrapper script instead."
<< endl << endl;
}
}

Expand Down Expand Up @@ -317,7 +317,7 @@ void print_index_sequences(
if (textoff_adj - last_text_off > 1)
curr_ref_seq += string(textoff_adj - last_text_off - 1, 'N');

curr_ref_seq.push_back(cat_ref[i]);
curr_ref_seq.push_back("ACGT"[(int)cat_ref[i]]);
last_text_off = textoff;
first = false;
}
Expand Down
8 changes: 4 additions & 4 deletions ebwt_search_backtrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -1596,7 +1596,7 @@ class GreedyDFSRangeSource {
ASSERT_ONLY(qualTot += qual0);
uint32_t ci = (uint32_t)(_qlen - _mms[0] - 1);
// _chars[] is index in terms of RHS-relative depth
int c = charToDna5[(int)_chars[ci]];
int c = asc2dna[(int)_chars[ci]];
assert_lt(c, 4);
assert_neq(c, (int)(*_qry)[_mms[0]]);
// Second, append the substituted character for the position
Expand All @@ -1612,7 +1612,7 @@ class GreedyDFSRangeSource {
ASSERT_ONLY(qualTot += qual1);
ci = (uint32_t)(_qlen - _mms[1] - 1);
// _chars[] is index in terms of RHS-relative depth
c = charToDna5[(int)_chars[ci]];
c = asc2dna[(int)_chars[ci]];
assert_lt(c, 4);
assert_neq(c, (int)(*_qry)[_mms[1]]);
// Second, append the substituted character for the position
Expand All @@ -1627,7 +1627,7 @@ class GreedyDFSRangeSource {
ASSERT_ONLY(qualTot += qual2);
ci = (uint32_t)(_qlen - _mms[2] - 1);
// _chars[] is index in terms of RHS-relative depth
c = charToDna5[(int)_chars[ci]];
c = asc2dna[(int)_chars[ci]];
assert_lt(c, 4);
assert_neq(c, (int)(*_qry)[_mms[2]]);
// Second, append the substituted character for the position
Expand Down Expand Up @@ -1854,7 +1854,7 @@ class EbwtRangeSource : public RangeSource {
assert(rc == 'A' || rc == 'C' || rc == 'G' || rc == 'T');
ASSERT_ONLY(char oc = (char)qryBuf_[qlen_ - seedRange_.mms[i] - 1]);
assert_neq(rc, oc);
qryBuf_[qlen_ - seedRange_.mms[i] - 1] = charToDna5[(int)rc];
qryBuf_[qlen_ - seedRange_.mms[i] - 1] = asc2dna[(int)rc];
assert_neq(rc, (*qry_)[qlen_ - seedRange_.mms[i] - 1]);
}
qry_ = &qryBuf_;
Expand Down
2 changes: 1 addition & 1 deletion filebuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ class FileBuf {
// if we see caret or EOF, break
if(c == '>' || c == -1) break;
// append and continue
seq[seqcur++] = charToDna5[c];
seq[seqcur++] = asc2dna[c];
get(); c = peek();
}
}
Expand Down
2 changes: 1 addition & 1 deletion hit_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ struct HitSet {
assert_lt(sz, 1024);
seq.resize(sz);
for(size_t j = 0; j < sz; j++) {
seq[j] = charToDna5[fb.get()];
seq[j] = asc2dna[fb.get()];
}
qual.resize(sz);
fb.get(qual.wbuf(), sz);
Expand Down
38 changes: 28 additions & 10 deletions pat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ bool VectorPatternSource::parse(Read& ra, Read& rb, TReadId rdid) const {
assert_in(toupper(c), "ACGTN");
if(nchar++ >= this->trim5_) {
assert_neq(0, asc2dnacat[c]);
r.patFw.append(charToDna5[c]); // ascii to int
r.patFw.append(asc2dna[c]); // ascii to int
}
}
c = ra.readOrigBuf[cur++];
Expand Down Expand Up @@ -610,7 +610,7 @@ bool FastaPatternSource::parse(Read& r, Read& rb, TReadId rdid) const {
if(isalpha(c)) {
// If it's past the 5'-end trim point
if(nchar++ >= this->trim5_) {
r.patFw.append(charToDna5[c]);
r.patFw.append(asc2dna[c]);
}
}
assert_lt(cur, buflen);
Expand Down Expand Up @@ -768,7 +768,7 @@ bool FastaContinuousPatternSource::parse(
assert_in(toupper(c), "ACGTN");
if(nchar++ >= this->trim5_) {
assert_neq(0, asc2dnacat[c]);
ra.patFw.append(charToDna5[c]); // ascii to int
ra.patFw.append(asc2dna[c]); // ascii to int
}
}
}
Expand Down Expand Up @@ -893,7 +893,7 @@ bool FastqPatternSource::parse(Read &r, Read& rb, TReadId rdid) const {
if(isalpha(c)) {
// If it's past the 5'-end trim point
if(nchar++ >= this->trim5_) {
r.patFw.append(charToDna5[c]);
r.patFw.append(asc2dna[c]);
}
}
assert_lt(cur, buflen);
Expand Down Expand Up @@ -994,7 +994,17 @@ pair<bool, int> TabbedPatternSource::nextBatchFromFile(
readbuf[readi].readOrigBuf.append(c);
c = getc_wrapper();
}
while(c >= 0 && (c == '\n' || c == '\r') && readi < pt.max_buf_ - 1) {
if (c == '\n') {
readbuf[readi].readOrigBuf.append(c);
c = getc_wrapper();
if (c == '\r')
readbuf[readi].readOrigBuf.append(c);
else {
ungetc_wrapper(c);
c = '\n'; // reset to last seen char
}
}
while(c >= 0 && (c == '\n' || c == '\r') && readi < pt.max_buf_ - 1) {
c = getc_wrapper();
}
}
Expand Down Expand Up @@ -1050,7 +1060,7 @@ bool TabbedPatternSource::parse(Read& ra, Read& rb, TReadId rdid) const {
assert_in(toupper(c), "ACGTN");
if(nchar++ >= this->trim5_) {
assert_neq(0, asc2dnacat[c]);
r.patFw.append(charToDna5[c]);
r.patFw.append(asc2dna[c]);
}
}
c = ra.readOrigBuf[cur++];
Expand Down Expand Up @@ -1136,8 +1146,17 @@ pair<bool, int> RawPatternSource::nextBatchFromFile(
readbuf[readi].readOrigBuf.append(c);
c = getc_wrapper();
}

}
if (c == '\n') {
readbuf[readi].readOrigBuf.append(c);
c = getc_wrapper();
if (c == '\r')
readbuf[readi].readOrigBuf.append(c);
else {
ungetc_wrapper(c);
c = '\n'; // reset to last character seen
}
}
}
while (readi > 0 && readbuf[readi-1].readOrigBuf.length() == 0)
readi--;
return make_pair(c < 0, readi);
Expand All @@ -1161,12 +1180,11 @@ bool RawPatternSource::parse(Read& r, Read& rb, TReadId rdid) const {
cur--;
while(cur < buflen) {
c = r.readOrigBuf[cur++];
assert(c != '\r' && c != '\n');
if(isalpha(c)) {
assert_in(toupper(c), "ACGTN");
if(nchar++ >= this->trim5_) {
assert_neq(0, asc2dnacat[c]);
r.patFw.append(charToDna5[c]);
r.patFw.append(asc2dna[c]);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion ref_read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ RefRecord fastaRefReadSize(FileBuf& in,
// Output it
if(bpout != NULL) {
// output nucleotide
bpout->write(charToDna5[c]);
bpout->write(asc2dna[c]);
}
} else if(cat == 2) {
// It's an N or a gap
Expand Down
7 changes: 3 additions & 4 deletions ref_read.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ static RefRecord fastaRefReadAppend(FileBuf& in,
// Consume it
len++;
// Add it to referenece buffer
dst.set(charToDna5[c], dstoff++);
assert_lt(charToDna5[(int)dst[dst.length()-1]], 4);
dst.set(asc2dna[c], dstoff++);
assert_lt((int)dst[dstoff-1], 4);
}
c = in.get();
if(rparms.nsToAs && dna4Cat[c] == 2) c = 'A';
Expand All @@ -248,8 +248,7 @@ static RefRecord fastaRefReadAppend(FileBuf& in,
// ilen = length of buffer before this last sequence was appended.
if(rparms.reverse == REF_READ_REVERSE_EACH) {
// Find limits of the portion we just appended
size_t nlen = dstoff;
dst.reverseWindow(ilen, nlen);
dst.reverseWindow(ilen, len);
}
return RefRecord((TIndexOffU)off, (TIndexOffU)len, first);
}
Expand Down
2 changes: 1 addition & 1 deletion reference.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ class BitPairReference {
if((*infiles)[i].at(0) == '\\') {
(*infiles)[i].erase(0, 1);
}
osv.push_back(BTRefString((*infiles)[i].c_str()));
osv.push_back(BTRefString((*infiles)[i].c_str(), true));
}
} else {
readSequenceFiles(*infiles, osv);
Expand Down
8 changes: 7 additions & 1 deletion sstring.h
Original file line number Diff line number Diff line change
Expand Up @@ -2619,6 +2619,12 @@ std::ostream& operator<< (std::ostream& os, const SStringFixed<T, S>& str) {
return os;
}

template<typename T>
std::ostream& operator<<(std::ostream& os, const SString<T>& str) {
os << str.toZBuf();
return os;
}

extern uint8_t asc2dna[];
extern uint8_t asc2col[];

Expand Down Expand Up @@ -3488,7 +3494,7 @@ class SDnaMaskString : public SStringExpandable<char, S, M> {

typedef SStringExpandable<char, 1024, 2> BTString;
typedef SDnaStringExpandable<1024, 2> BTDnaString;
typedef SDnaStringExpandable<1024, 2> BTRefString;
typedef SDnaMaskString<32, 2> BTDnaMask;
typedef SString<char> BTRefString;

#endif /* SSTRING_H_ */

0 comments on commit 13055ff

Please sign in to comment.