Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for CRAM regularizing failing #1367

Merged
merged 5 commits into from May 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/JBrowse/Browser.js
Expand Up @@ -730,6 +730,13 @@ regularizeReferenceName: function( refname ) {
return refname;

refname = refname.toLowerCase()

// special case of double regularizing behaving badly
if(refname.match(/^chrm/)) {
return 'chrm'
}

refname = refname
.replace(/^chro?m?(osome)?/,'chr')
.replace(/^co?n?ti?g/,'ctg')
.replace(/^scaff?o?l?d?/,'scaffold')
Expand Down
1 change: 0 additions & 1 deletion src/JBrowse/Store/SeqFeature/CRAM.js
Expand Up @@ -21,7 +21,6 @@ class CramSlightlyLazyFeature {
_get_strand() { return this.record.isReverseComplemented() ? -1 : 1 }
_get_read_group_id() { return this.record.readGroupId }
_get_qual() { return (this.record.qualityScores || []).map(q => q+33).join(' ')}
_get_seq() { return this.record.readBases}
_get_seq_id() { return this._store._refIdToName(this.record.sequenceId)}
_get_qc_failed() { return this.record.isFailedQc()}
_get_secondary_alignment() { return this.record.isSecondary()}
Expand Down
7 changes: 6 additions & 1 deletion src/JBrowse/Store/SeqFeature/IndexedFasta.js
Expand Up @@ -70,7 +70,12 @@ return declare( [ SeqFeatureStore, DeferredFeaturesMixin ],
if(query.start < 0) {
query.start = 0;
}
this.fasta.getResiduesByName( this.refSeq.name, query.start, query.end ).then((seq) => {
var refname = query.ref;
// if they both regularize to the same thing, use this.refSeq.name since that is guaranteed to be from refseq store
if(!this.browser.compareReferenceNames( this.refSeq.name, refname ) )
refname = this.refSeq.name;

this.fasta.getResiduesByName( refname, query.start, query.end ).then(seq => {
featCallback(new SimpleFeature({data: {seq, start: query.start, end: query.end}}))
endCallback()
},
Expand Down
1 change: 1 addition & 0 deletions src/JBrowse/Store/SeqFeature/SequenceChunks.js
Expand Up @@ -48,6 +48,7 @@ return declare( SeqFeatureStore,
errorCallback = errorCallback || function(e) { console.error(e); };

var refname = query.ref;
// if they both regularize to the same thing, use this.refSeq.name since that is guaranteed to be from refseq store
if( ! this.browser.compareReferenceNames( this.refSeq.name, refname ) )
refname = this.refSeq.name;

Expand Down
7 changes: 6 additions & 1 deletion src/JBrowse/Store/SeqFeature/TwoBit.js
Expand Up @@ -79,7 +79,12 @@ return declare([ SeqFeatureStore, DeferredFeaturesMixin], {
if (start < 0) {
start = 0
}
this.twoBit.getSequence(query.ref, start, query.end)
var refname = query.ref;
// if they both regularize to the same thing, use this.refSeq.name since that is guaranteed to be from refseq store
if(!this.browser.compareReferenceNames( this.refSeq.name, refname ) )
refname = this.refSeq.name;

this.twoBit.getSequence(refname, start, query.end)
.then(seq => {
if (seq !== undefined) {
featCallback(new SimpleFeature({
Expand Down
19 changes: 18 additions & 1 deletion tests/js_tests/spec/RegularizeRefSeqs.spec.js
Expand Up @@ -9,7 +9,14 @@ describe( 'centralized ref seq name regularization', function() {

var testCases = [
[ 'ctgA', 'ctga' ],
[ 'MT', 'chrm' ],
[ 'Pt', 'pt' ],
[ 'C9', 'c9' ],
[ 'chrM', 'chrm' ],
[ 'chrMT', 'chrm' ],
[ 'ChrC', 'chrc' ],
[ 'chrom01', 'chr1' ],
[ 'Bvchr1_un.sca002', 'bvchr1_un.sca002' ],
[ 'chr01', 'chr1' ],
[ 'CHROMOSOME11', 'chr11' ],
[ 'SCAFFOLD0231', 'scaffold231' ],
Expand All @@ -19,11 +26,21 @@ describe( 'centralized ref seq name regularization', function() {
[ '01', 'chr1' ],
[ '1', 'chr1' ]
];



array.forEach( testCases, function( testCase ) {
it( 'works for '+testCase[0], function() {
expect( b.regularizeReferenceName( testCase[0] ) ).toEqual( testCase[1] );
});
});

array.forEach( testCases, function( testCase ) {
it( 'double regularizing works for '+testCase[1], function() {
expect( b.regularizeReferenceName( testCase[1] ) ).toEqual( testCase[1] );
});
});
})

});
});

20 changes: 12 additions & 8 deletions tests/js_tests/spec/TwoBit.spec.js
Expand Up @@ -10,11 +10,12 @@ require([
aspect,
XHRBlob
) {

describe(".2bit data store with T_ko.2bit", function() {

var t = new TwoBitStore({
browser: new Browser({ unitTestMode: true }),
refSeq: { name: 'chr1', start: 1, end: 500001 },
blob: new XHRBlob("../data/T_ko.2bit")
});

Expand Down Expand Up @@ -55,17 +56,18 @@ describe(".2bit data store with T_ko.2bit", function() {
function() { done = true; });

waitsFor( function() { return done; }, 2000);
runs(function(){
runs(function(){
expect(features.length).toEqual(0);
});
});

});

describe(".2bit data store with volvox.2bit", function() {

var t2 = new TwoBitStore({
browser: new Browser({ unitTestMode: true }),
refSeq: { name: 'chr1', start: 1, end: 500001 },
blob: new XHRBlob("../data/volvox.2bit")
});

Expand Down Expand Up @@ -122,19 +124,20 @@ describe(".2bit data store with volvox.2bit", function() {
function() { done = true; });

waitsFor( function() { return done; }, 2000);
runs(function(){
runs(function(){
expect(features.length).toEqual(0);
});
});

});

var seqString = "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNACTCTATCTATCTATCTATCTATCTTTTTCCCCCCGGGGGGagagagagactctagcatcctcctacctcacNNacCNctTGGACNCcCaGGGatttcNNNcccNNCCNCgN";

describe(".2bit data store with random data foo.2bit", function() {

var t3 = new TwoBitStore({
browser: new Browser({unitTestMode: true }),
refSeq: { name: 'chr1', start: 1, end: 500001 },
blob: new XHRBlob("../data/foo.2bit")
});

Expand Down Expand Up @@ -182,6 +185,7 @@ describe(".2bit data store with random data foo.2bit", function() {
describe("empty 2bit", function() {
var t4 = new TwoBitStore({
browser: new Browser({ unitTestMode: true }),
refSeq: { name: 'chr1', start: 1, end: 500001 },
blob: new XHRBlob("../data/empty.2bit")
});

Expand All @@ -192,9 +196,9 @@ describe("empty 2bit", function() {
it("returns no data, but doesn't crash", function() {
var done;
var features = [];
t4.getFeatures({ref: "unimportant", start: 0, end: 4000},
t4.getFeatures({ref: "unimportant", start: 0, end: 4000},
function(feature) {
features.push(feature);
features.push(feature);
},
function() { done = true; },
function(err) { console.log(err); });
Expand Down