Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/analysis/bsrate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -580,12 +580,14 @@ main_bsrate(int argc, const char **argv) {
unordered_set<int32_t> chroms_seen;

while (hts.read(hdr, aln)) {
const int32_t the_tid = get_tid(aln);
if (the_tid == -1)
continue;

if (reads_are_a_rich) flip_conversion(aln);

// get the correct chrom if it has changed
if (get_tid(aln) != current_tid) {
const int32_t the_tid = get_tid(aln);

if (the_tid != current_tid) {
// make sure all reads from same chrom are contiguous in the file
if (chroms_seen.find(the_tid) != end(chroms_seen))
throw runtime_error("chroms out of order in mapped reads file");
Expand Down
20 changes: 14 additions & 6 deletions src/analysis/methcounts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,22 +446,30 @@ process_reads(const bool VERBOSE, const bool show_progress,
vector<string>::const_iterator chrom_itr;

while (hts.read(hdr, aln)) {
if (get_tid(aln) == prev_tid) {
const int32_t tid = get_tid(aln);
if (tid == -1) // ADS: skip reads that have no tid -- they are not mapped
continue;
if (tid == prev_tid) {
// do the work for this mapped read, depending on strand
if (bam_is_rev(aln))
count_states_neg(aln, counts);
else
count_states_pos(aln, counts);
}
else { // chrom changes, output results, get the next one
else { // chrom has changed, so output results and get the next chrom

// write output if there is any; should fail only once
// write output if there is any; counts is empty only for first chrom
if (!counts.empty())
write_output<require_covered>(hdr, out, prev_tid,
*chrom_itr, counts, CPG_ONLY);

const int32_t tid = get_tid(aln);
if (tid < prev_tid) throw dnmt_error("SAM file is not sorted");
// make sure reads are sorted chrom tid number in header
if (tid < prev_tid) {
const std::string message = "SAM file is not sorted "
"previous tid: " +
std::to_string(prev_tid) +
" current tid: " + std::to_string(tid);
throw dnmt_error(message);
}

if (!require_covered)
for (auto i = prev_tid + 1; i < tid; ++i)
Expand Down
4 changes: 4 additions & 0 deletions src/utils/format-reads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,10 @@ format(const string &cmd, const size_t n_threads, const string &inputfile,
swap(aln, prev_aln); // start with prev_aln being first read

while (hts.read(hdr, aln)) {
// ADS: skip reads that have no tid -- they are not mapped
if (get_tid(aln) == -1)
continue;

standardize_format(input_format, aln);
if (same_name(prev_aln, aln, suff_len)) {
// below: essentially check for dovetail
Expand Down
11 changes: 10 additions & 1 deletion src/utils/uniq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,14 @@ uniq(const bool add_dup_count, const uint32_t max_buffer_size,
}

bam_rec aln;
if (hts.read(hdr, aln)) { // valid SAM/BAM can have 0 reads
bool found_mapped_read{false}; // valid SAM/BAM can have 0 reads
while (!found_mapped_read && hts.read(hdr, aln)) {
// ADS: skip reads that have no tid -- they are not mapped
if (get_tid(aln) != -1)
found_mapped_read = true;
}

if (found_mapped_read) {
rs_in.update(aln); // update stats for input we just got

vector<bam_rec> buffer(1, aln); // select output from this buffer
Expand All @@ -238,6 +244,9 @@ uniq(const bool add_dup_count, const uint32_t max_buffer_size,
int32_t cur_chrom = get_tid(aln);

while (hts.read(hdr, aln)) {
// ADS: skip reads that have no tid -- they are not mapped
if (get_tid(aln) == -1)
continue;
rs_in.update(aln);

// below works because buffer reset at every new chrom
Expand Down