js/sample.js
function alignSeqUsingCigar(rawseq, rawquals, cigar) {
    var ops = parseCigar(cigar);
    var seq = [];
    var quals = [];
    var cursor = 0;
    for (var ci = 0; ci < ops.length; ++ci) {
        var co = ops[ci];
        if (co.op == 'M') {
            seq.push(rawseq.substr(cursor, co.cnt));
            quals.push(rawquals.substr(cursor, co.cnt));
            cursor += co.cnt;
        } else if (co.op == 'D') {
            for (var oi = 0; oi < co.cnt; ++oi) {
                seq.push('-');
                quals.push('Z');
            }
        } else if (co.op == 'I') {
            cursor += co.cnt;
        } else if (co.op == 'S') {
            cursor += co.cnt;
        } else {
            console.log('unknown cigop' + co.op);
        }
    }
    var processedSeq = {seq: seq.join(''), quals: quals.join('')};
    return processedSeq;
}
function alignSeqUsingCigar(rawseq, rawquals, cigar) {
    var ops = parseCigar(cigar);
    var seq = [];
    var quals = [];
    var cursor = 0;
    for (var ci = 0; ci < ops.length; ++ci) {
        var co = ops[ci];
        if (co.op == 'M') {
            seq.push(rawseq.substr(cursor, co.cnt));
            quals.push(rawquals.substr(cursor, co.cnt));
            cursor += co.cnt;
        } else if (co.op == 'D') {
            for (var oi = 0; oi < co.cnt; ++oi) {
                seq.push('-');
                quals.push('Z');
            }
        } else if (co.op == 'I') {
            cursor += co.cnt;
        } else if (co.op == 'S') {
            cursor += co.cnt;
        } else {
            console.log('unknown cigop' + co.op);
        }
    }
    var processedSeq = {seq: seq.join(''), quals: quals.join('')};
    return processedSeq;
}
function alignSeqUsingCigar ( rawseq , rawquals , cigar ) { var ops = parseCigar ( cigar ) ; var seq = [ ] ; var quals = [ ] ; var cursor = 0 ; for ( var ci = 0 ; ci < ops . length ; ++ ci ) { var co = ops [ ci ] ; if ( co . op == 'M' ) { seq . push ( rawseq . substr ( cursor , co . cnt ) ) ; quals . push ( rawquals . substr ( cursor , co . cnt ) ) ; cursor += co . cnt ; } else if ( co . op == 'D' ) { for ( var oi = 0 ; oi < co . cnt ; ++ oi ) { seq . push ( '-' ) ; quals . push ( 'Z' ) ; } } else if ( co . op == 'I' ) { cursor += co . cnt ; } else if ( co . op == 'S' ) { cursor += co . cnt ; } else { console . log ( 'unknown cigop' + co . op ) ; } } var processedSeq = { seq : seq . join ( '' ) , quals : quals . join ( '' ) } ; return processedSeq ; }
Generates an aligned read from the raw sequence of a BAM record
using given cigar string.

Params:
rawseq: unaligned read sequence from Bam record
rawquals: unaligned read quals from Bam record
cigar: Bam cigar string from Bam record

Returns an object with 2 properties:
seq: string containing aligned read
quals: string containing printable-character representation
of sequencing quality score
Generates an aligned read from the raw sequence of a BAM record using given cigar string .