Пример #1
0
char *bamGetQuerySequence(const bam1_t *bam, boolean useStrand)
/* Allocate and return the nucleotide sequence encoded in bam.  The BAM format
 * reverse-complements query sequence when the alignment is on the - strand,
 * so if useStrand is given we rev-comp it back to restore the original query
 * sequence. */
{
    const bam1_core_t *core = &bam->core;
    int qLen = core->l_qseq;
    char *qSeq = needMem(qLen+1);
    bamUnpackQuerySequence(bam, useStrand, qSeq);
    return qSeq;
}
Пример #2
0
int bamAddOneSamAlignment(const bam1_t *bam, void *data, bam_hdr_t *header)
/* bam_fetch() calls this on each bam alignment retrieved.  Translate each bam
 * into a samAlignment. */
{
struct bamToSamHelper *helper = (struct bamToSamHelper *)data;
struct lm *lm = helper->lm;
struct samAlignment *sam;
lmAllocVar(lm, sam);
const bam1_core_t *core = &bam->core;
struct dyString *dy = helper->dy;
sam->qName = lmCloneString(lm, bam1_qname(bam));
sam->flag = core->flag;
if (helper->chrom != NULL)
    sam->rName = helper->chrom;
else
    sam->rName = lmCloneString(lm, header->target_name[core->tid]);
sam->pos = core->pos + 1;
sam->mapQ = core->qual;
dyStringClear(dy);
bamUnpackCigar(bam, dy);
sam->cigar = lmCloneStringZ(lm, dy->string, dy->stringSize);
if (core->mtid >= 0)
    {
    if (core->tid == core->mtid)
	sam->rNext = "=";
    else
	sam->rNext = lmCloneString(lm, header->target_name[core->mtid]);
    }
else
    sam->rNext = "*";
sam->pNext = core->mpos + 1;
sam->tLen = core->isize;
sam->seq = lmAlloc(lm, core->l_qseq + 1);
bamUnpackQuerySequence(bam, FALSE, sam->seq);
char *bamQual = (char *)bam1_qual(bam);
if (isAllSameChar(bamQual, core->l_qseq, -1))
    sam->qual = "*";
else
    {
    sam->qual = lmCloneStringZ(lm, bamQual, core->l_qseq);
    addToChars(sam->qual, core->l_qseq, 33);
    }
dyStringClear(dy);
bamUnpackAux(bam, dy);
sam->tagTypeVals = lmCloneStringZ(lm, dy->string, dy->stringSize);
slAddHead(&helper->samList, sam);
return 0;
}