Beispiel #1
0
bool doesASTRequireProfiling(SILModule &M, ASTNode N) {
  return M.getOptions().GenerateProfile && !isUnmapped(N);
}
Beispiel #2
0
 bool isMapped() const {assert(m_dataPtr); return !isUnmapped();}
SamRead::SamRead(const bam1_t *b, bam_header_t *_bamHeader, const faidx_t *_fai) {
    fai = _fai;
    const bam1_core_t *c = &b->core;
    uint32_t len = c->l_qseq;

    double mapPhred = (double) c->qual;
    mapQual = (1.0 - pow(10.0, -mapPhred / 10.0));

    if (mapQual < 0.0 || mapQual > 1.0 || std::isnan(mapQual) || std::isinf(mapQual)) {
        throw std::string("Phred error.");
    } else if (mapQual < 1e-16) {
        mapQual = 1e-16;
    } else if (mapQual > 1 - 1e-16) {
        mapQual = 1 - 1e-16;
    }

    pos = c->pos; // zero-based
    seq_name = (std::string)reinterpret_cast<char *>(bam1_qname(b));
    seq.reserve(len);
    qual.reserve(len);
    for (size_t x = 0; x < len; x++) {
        seq += (bam_nt16_rev_table[ bam1_seqi(bam1_seq(b), x) ]);
        // convert phred to probability
        double basePhred = (double)(((uint8_t *) bam1_qual(b))[x]);
        double q = (1.0 - pow(10.0, -basePhred / 10.0));
        if (q < 0.0 || q > 1.0 || std::isnan(q) || std::isinf(q)) {
            throw std::string("Phred error.");
        }
        if (q < 1e-16) {
            q = 1e-16;
        }
        if (q > 1.0 - 1e-16) {
            q = 1.0 - 1e-16;
        }
        qual.push_back(q);   // base quality is on log10 scale
    }

    bam = new bam1_t;
    *bam = *b;
    bam->data = new uint8_t[b->m_data];
    bam->m_data = b->m_data;
    for (int m = 0; m < b->m_data; m++) {
        bam->data[m] = b->data[m];
    }

    if (bam->core.flag & BAM_FREVERSE) {
        onReverseStrand = true;
    } else {
        onReverseStrand = false;
    }

    matePos = bam->core.mpos;
    mateLen = -1;
    this->bamHeader = _bamHeader;

    uint32_t *rawCigar = bam1_cigar(b);
    
    leftMostPos = pos;
    rightMostPos = getEndPos();

    if(!isUnmapped()) {
        rightMostPos = pos;
        hasIndel = false;
        hasHardClip = false;
        hasSoftClip = false;
        hasOtherCigarFlag = false;
        bool isLeftMost = true;
        softClipSize = 0;
        
        // set CIGAR string
        for (int k = 0; k < c->n_cigar; ++k) {
            int op = rawCigar[k] & BAM_CIGAR_MASK;
            int32_t len = rawCigar[k] >> BAM_CIGAR_SHIFT;
            // update position for the next cigar
            if (op == BAM_CMATCH) {
                cigars.push_back(CIGAR(CIGAR::MATCH, len));
                rightMostPos += len;
                isLeftMost = false;
            } else if (op == BAM_CINS) {
                cigars.push_back(CIGAR(CIGAR::INS, len));
                hasIndel = true;
                isLeftMost = false;
            } else if (op == BAM_CDEL) {
                cigars.push_back(CIGAR(CIGAR::DEL, len));
                rightMostPos += len;
                hasIndel = true;
                isLeftMost = false;
            } else if (op == BAM_CSOFT_CLIP) {
                rightMostPos += len;

                if (softClipSize < (int)len) {
                    softClipSize = (int)len;
                }
                hasSoftClip = true;
                cigars.push_back(CIGAR(CIGAR::SOFTCLIP, len));
                if (isLeftMost) {
                    leftMostPos -= len;
                    isLeftMost = false;
                }
            } else if (op == BAM_CHARD_CLIP) {
                hasHardClip = true;
            } else {
                hasOtherCigarFlag = true;
            }
        }

        parseVariants();
    }