Skip to content

Commit

Permalink
debugString function added (#516)
Browse files Browse the repository at this point in the history
* debugString is now a member of all Alignment implementations
  • Loading branch information
abhim00 authored and akmorrow13 committed Apr 25, 2019
1 parent a9ed822 commit 86a841b
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 9 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
],
"dependencies": {
"backbone": "1.1.2",
"jquery": "3.3.1",
"d3": "^3.5.5",
"data-canvas": ">=0.1.1",
"jbinary": "^2.1.3",
Expand Down
12 changes: 9 additions & 3 deletions src/main/Alignment.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ function ga4ghStrandToStrand(str: string): Strand {
return str && str == 'POS_STRAND' ? '+' : (str && str == 'NEG_STRAND' ? '-' : '.'); // either +, - or .
}

// builds a cigarString string that is useful to users.
function makeCigarString(cigarOps: Array<CigarOp>) {
return cigarOps.map(({op, length}) => length + op).join('');
}

export type MateProperties = {
ref: ?string;
pos: number;
Expand All @@ -52,10 +57,11 @@ export type Alignment = {
getMateProperties(): ?MateProperties;
getInferredInsertSize(): number;
getCoverage(referenceSource: Object): CoverageCount;

debugString(): string;
};

module.exports = {
strToStrand,
ga4ghStrandToStrand
};
ga4ghStrandToStrand,
makeCigarString
};
8 changes: 8 additions & 0 deletions src/main/GA4GHAlignment.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
'use strict';

import type {CigarOp, MateProperties, Strand} from './Alignment';
import {makeCigarString} from './Alignment';
import type {CoverageCount} from './viz/pileuputils';
import {getOpInfo} from './viz/pileuputils';

Expand Down Expand Up @@ -104,6 +105,13 @@ class GA4GHAlignment /* implements Alignment */ {
return 0;
}
}
debugString(): string {
return `Name: ${this.name}
Position: ${this.pos.toString()}
CIGAR: ${makeCigarString(this.cigarOps)}
Sequence: ${this.alignment.alignedSequence}
Quality: ${this.alignment.alignedQuality} `;
}

getCoverage(referenceSource: Object): CoverageCount {
return {
Expand Down
8 changes: 2 additions & 6 deletions src/main/data/SamRead.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import type VirtualOffset from './VirtualOffset';
import type {Strand, CigarOp, MateProperties} from '../Alignment';
import {makeCigarString} from '../Alignment';

import jDataView from 'jdataview';
import jBinary from 'jbinary';
Expand Down Expand Up @@ -161,7 +162,7 @@ class SamRead /* implements Alignment */ {
}

getCigarString(): string {
return makeCigarString(this.getFull().cigar);
return makeCigarString(this.cigarOps);
}

getQualPhred(): string {
Expand Down Expand Up @@ -249,11 +250,6 @@ Tags: ${JSON.stringify(f.auxiliary, null, ' ')}
}
}

// Convert a structured Cigar object into the string format we all love.
function makeCigarString(cigarOps: Array<{op:string; length:number}>) {
return cigarOps.map(({op, length}) => length + op).join('');
}

// Convert an array of Phred scores to a printable string.
function makeAsciiPhred(qualities: number[]): string {
if (qualities.length === 0) return '';
Expand Down
1 change: 1 addition & 0 deletions src/test/FakeAlignment.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class FakeAlignment /* implements Alignment */ {
getInterval(): ContigInterval<string> { return this.interval; }
getReferenceLength(): number { return this.interval.length(); }
getMateProperties(): ?MateProperties { return this.mateProps; }
debugString(): string { return this.name; }

getCoverage(referenceSource: Object): CoverageCount {
return {
Expand Down
1 change: 1 addition & 0 deletions src/test/GA4GHAlignment-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ describe('GA4GHAlignment', function() {
pos: 10007,
strand: '-'
});
expect(a.debugString().length).to.be.above(0);
done();
});

Expand Down
1 change: 1 addition & 0 deletions src/test/data/SamRead-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ describe('SamRead', function() {
pos: 79,
strand: '-'
});
expect(read.debugString().length).to.be.above(0);

// This one has a more interesting Cigar string
expect(reads[3].cigarOps).to.deep.equal([
Expand Down

0 comments on commit 86a841b

Please sign in to comment.