Skip to content

Commit

Permalink
adds strand-preserving bam seqs
Browse files Browse the repository at this point in the history
  • Loading branch information
mfansler committed Jun 26, 2020
1 parent 9b2cc60 commit 79569b0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
36 changes: 27 additions & 9 deletions src/ProcessReads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2979,7 +2979,10 @@ FastqSequenceReader::FastqSequenceReader(FastqSequenceReader&& o) :
o.state = false;
}

const std::string BamSequenceReader::seq_enc = "=ACMGRSVTWYHKDBN";
// sequence decoding table
const std::string BamSequenceReader::seq_enc = "=ACMGRSVTWYHKDBN";
// complement sequence decoding table
const std::string BamSequenceReader::cseq_enc = "=TGKCYSBAWRDMHVN";

BamSequenceReader::~BamSequenceReader() {
if (fp) {
Expand Down Expand Up @@ -3038,16 +3041,31 @@ bool BamSequenceReader::fetchSequences(char *buf, const int limit, std::vector<s
bufpos += l_bc + l_umi + 1;

pi = buf + bufpos;
int len = (l_seq + 1) / 2;
if (l_seq % 2) --len;
int len = l_seq / 2;
int j = 0;
for (int i = 0; i < len; ++i, ++eseq) {
buf[bufpos++] = seq_enc[*eseq >> 4];
buf[bufpos++] = seq_enc[*eseq & 0x0F];
}
if (l_seq % 2) {
buf[bufpos++] = seq_enc[*eseq >> 4];

if (rec->core.flag & BAM_FREVERSE) { // insert reverse complement
// start at end
bufpos += l_seq;
for (int i = 0; i < len; ++i, ++eseq) {
buf[--bufpos] = cseq_enc[*eseq >> 4];
buf[--bufpos] = cseq_enc[*eseq & 0x0F];
}
if (l_seq % 2) {
buf[--bufpos] = cseq_enc[*eseq >> 4];
}
// reset position to end
bufpos += l_seq;
} else { // insert forward sequence
for (int i = 0; i < len; ++i, ++eseq) {
buf[bufpos++] = seq_enc[*eseq >> 4];
buf[bufpos++] = seq_enc[*eseq & 0x0F];
}
if (l_seq % 2) {
buf[bufpos++] = seq_enc[*eseq >> 4];
}
}
// insert delimiter
buf[bufpos++] = '\0';
seqs.emplace_back(pi, l_seq);

Expand Down
1 change: 1 addition & 0 deletions src/ProcessReads.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ class BamSequenceReader : public SequenceReader {

private:
static const std::string seq_enc;
static const std::string cseq_enc;
};

class MasterProcessor {
Expand Down

0 comments on commit 79569b0

Please sign in to comment.