void countReadsPerGene(String<unsigned> & readsPerGene, String<TIntervalTree> const & intervalTrees, TStore const & store) { resize(readsPerGene, length(store.annotationStore), 0); String<TId> result; int numAlignments = length(store.alignedReadStore); // iterate aligned reads and get search their begin and end positions SEQAN_OMP_PRAGMA(parallel for private (result)) for (int i = 0; i < numAlignments; ++i) { TAlignedRead const & ar = store.alignedReadStore[i]; TPos queryBegin = _min(ar.beginPos, ar.endPos); // In gapped space TPos queryEnd = _max(ar.beginPos, ar.endPos); // In gapped space // search read-overlapping genes findIntervals(result, intervalTrees[ar.contigId] /*Ungapped space*/, queryBegin, queryEnd); // increase read counter for each overlapping annotation given the id in the interval tree for (unsigned j = 0; j < length(result); ++j) { SEQAN_OMP_PRAGMA(atomic) readsPerGene[result[j]] += 1; } } }
Best,