Skip to content

Commit

Permalink
Fixes 1-based error for anti-sense reads and TLEN in pseudobam
Browse files Browse the repository at this point in the history
  • Loading branch information
pmelsted committed Jun 17, 2015
1 parent a2ee0b2 commit 4dce074
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
8 changes: 7 additions & 1 deletion src/KmerIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,7 @@ void KmerIndex::load(ProgramOptions& opt, bool loadKmerTable) {
in.close();
}


int KmerIndex::mapPair(const char *s1, int l1, const char *s2, int l2, int ec) const {
bool d1 = true;
bool d2 = true;
Expand Down Expand Up @@ -1171,6 +1172,12 @@ void KmerIndex::match(const char *s, int l, std::vector<std::pair<KmerEntry, int
}
}


//use: (pos,sense) = index.findPosition(tr,km,val,p)
//pre: index.kmap[km] == val,
// km is the p-th k-mer of a read
// val.contig maps to tr
//post: km is found in position pos (1-based) on the sense/!sense strand of tr
std::pair<int,bool> KmerIndex::findPosition(int tr, Kmer km, KmerEntry val, int p) const {
bool fw = (km == km.rep());
bool csense = (fw == val.isFw());
Expand Down Expand Up @@ -1207,7 +1214,6 @@ std::pair<int,bool> KmerIndex::findPosition(int tr, Kmer km, KmerEntry val, int
return {trpos + (c.length - val.getPos()) - p, !csense}; // 1-based, case II
}
}

}

/*
Expand Down
24 changes: 15 additions & 9 deletions src/ProcessReads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,13 +395,16 @@ void outputPseudoBam(const KmerIndex &index, int ec, const kseq_t *seq1, const s
}
}

int posread = (f1 & 0x10) ? (x1.first - seq1->seq.l) : x1.first;
int posmate = (f1 & 0x20) ? (x2.first - seq2->seq.l) : x2.first;
int posread = (f1 & 0x10) ? (x1.first - seq1->seq.l + 1) : x1.first;
int posmate = (f1 & 0x20) ? (x2.first - seq2->seq.l + 1) : x2.first;

getCIGARandSoftClip(cig, bool(f1 & 0x10), (f1 & 0x04) == 0, posread, posmate, seq1->seq.l, index.target_lens_[tr]);

int tlen = x2.first - x1.first;
if (tlen != 0) {
tlen += (tlen>0) ? 1 : -1;
}

printf("%s\t%d\t%s\t%d\t255\t%s\t=\t%d\t%d\t%s\t%s\tNH:i:%d\n", seq1->name.s, f1 & 0xFFFF, index.target_names_[tr].c_str(), posread, cig, posmate, (x2.first-x1.first), (f1 & 0x10) ? &buf1[0] : seq1->seq.s, (f1 & 0x10) ? &buf2[0] : seq1->qual.s, nmap);
printf("%s\t%d\t%s\t%d\t255\t%s\t=\t%d\t%d\t%s\t%s\tNH:i:%d\n", seq1->name.s, f1 & 0xFFFF, index.target_names_[tr].c_str(), posread, cig, posmate, tlen, (f1 & 0x10) ? &buf1[0] : seq1->seq.s, (f1 & 0x10) ? &buf2[0] : seq1->qual.s, nmap);
}

revset = false;
Expand Down Expand Up @@ -434,13 +437,16 @@ void outputPseudoBam(const KmerIndex &index, int ec, const kseq_t *seq1, const s
}
}

int posread = (f2 & 0x10) ? (x2.first - seq2->seq.l) : x2.first;
int posmate = (f2 & 0x20) ? (x1.first - seq1->seq.l) : x1.first;

int posread = (f2 & 0x10) ? (x2.first - seq2->seq.l + 1) : x2.first;
int posmate = (f2 & 0x20) ? (x1.first - seq1->seq.l + 1) : x1.first;

getCIGARandSoftClip(cig, bool(f2 & 0x10), (f2 & 0x04) == 0, posread, posmate, seq2->seq.l, index.target_lens_[tr]);
int tlen = x1.first - x2.first;
if (tlen != 0) {
tlen += (tlen > 0) ? 1 : -1;
}

printf("%s\t%d\t%s\t%d\t255\t%s\t=\t%d\t%d\t%s\t%s\tNH:i:%d\n", seq2->name.s, f2 & 0xFFFF, index.target_names_[tr].c_str(), posread, cig, posmate, (x1.first-x2.first), (f2 & 0x10) ? &buf1[0] : seq2->seq.s, (f2 & 0x10) ? &buf2[0] : seq2->qual.s, nmap);
printf("%s\t%d\t%s\t%d\t255\t%s\t=\t%d\t%d\t%s\t%s\tNH:i:%d\n", seq2->name.s, f2 & 0xFFFF, index.target_names_[tr].c_str(), posread, cig, posmate, tlen, (f2 & 0x10) ? &buf1[0] : seq2->seq.s, (f2 & 0x10) ? &buf2[0] : seq2->qual.s, nmap);
}


Expand Down Expand Up @@ -471,7 +477,7 @@ void outputPseudoBam(const KmerIndex &index, int ec, const kseq_t *seq1, const s
}
}

int posread = (f1 & 0x10) ? (x1.first - seq1->seq.l) : x1.first;
int posread = (f1 & 0x10) ? (x1.first - seq1->seq.l+1) : x1.first;
int dummy=1;
getCIGARandSoftClip(cig, bool(f1 & 0x10), (f1 & 0x04) == 0, posread, dummy, seq1->seq.l, index.target_lens_[tr]);

Expand Down

0 comments on commit 4dce074

Please sign in to comment.