else arr_partial_unknown.push_back(bam_dup1(b));
}
+char get_pattern_code(uint32_t flag) {
+ if (flag & 0x0040) return (flag & 0x0010 ? 1 : 0);
+ else return (flag & 0x0010 ? 0 : 1);
+}
+
bool less_than(bam1_t *a, bam1_t *b) {
int32_t ap1 = min(a->core.pos, a->core.mpos);
int32_t ap2 = max(a->core.pos, a->core.mpos);
int32_t bp1 = min(b->core.pos, b->core.mpos);
int32_t bp2 = max(b->core.pos, b->core.mpos);
+ char apat = get_pattern_code(a->core.flag); // apt: a's pattern of strand and mate information
+ char bpat = get_pattern_code(b->core.flag);
if (a->core.tid != b->core.tid) return a->core.tid < b->core.tid;
if (ap1 != bp1) return ap1 < bp1;
- return ap2 < bp2;
+ if (ap2 != bp2) return ap2 < bp2;
+ return apat < bpat;
}
int main(int argc, char* argv[]) {
if (argc != 3) {
- printf("Usage: rsem-scan-for-paired-end-reads input.sam output.bam\n");
+ printf("UsaOAge: rsem-scan-for-paired-end-reads input.sam output.bam\n");
exit(-1);
}
if (isPaired) {
add_to_appropriate_arr(b);
while ((go_on = (samread(in, b) >= 0)) && (qname == bam1_qname(b))) {
- general_assert(b->core.flag & 0x0001, "Read " + qname + " is detected as both single-end and paired-end read!", true);
+ general_assert_1(b->core.flag & 0x0001, "Read " + qname + " is detected as both single-end and paired-end read!");
add_to_appropriate_arr(b);
}
- general_assert(arr_both.size() % 2 == 0, "Number of first and second mates in read " + qname + "'s full alignments (both mates are aligned) are not matched!", true);
- general_assert((arr_partial_1.size() + arr_partial_2.size() + arr_partial_unknown.size()) % 2 == 0, "Number of first and second mates in read " + qname + "'s partial alignments (at most one mate is aligned) are not matched!", true);
+ general_assert_1(arr_both.size() % 2 == 0, "Number of first and second mates in read " + qname + "'s full alignments (both mates are aligned) are not matched!");
+ general_assert_1((arr_partial_1.size() + arr_partial_2.size() + arr_partial_unknown.size()) % 2 == 0, "Number of first and second mates in read " + qname + "'s partial alignments (at most one mate is aligned) are not matched!");
if (!arr_both.empty()) {
sort(arr_both.begin(), arr_both.end(), less_than);