-
Notifications
You must be signed in to change notification settings - Fork 199
/
BAMDriver.js
106 lines (97 loc) · 3.69 KB
/
BAMDriver.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
define([
'JBrowse/Util',
'JBrowse/Model/FileBlob',
'JBrowse/Model/XHRBlob'
],
function( Util, FileBlob, XHRBlob ) {
var uniqCounter = 0;
return {
storeType: 'JBrowse/Store/SeqFeature/BAM',
tryResource: function( configs, resource ) {
if( resource.type == 'bam' ) {
var basename = Util.basename(
resource.file ? resource.file.name :
resource.url ? resource.url :
''
);
if( !basename )
return false;
// go through the configs and see if there is one with a BAI that seems to match
for( var n in configs ) {
var c = configs[n];
if( Util.basename( c.bai ? c.bai.blob.name : c.baiUrlTemplate, '.bai' ) == basename ) {
// it's a match, put it in
c.bam = this._makeBlob( resource );
return true;
}
}
// go through again and look for BAIs that don't have .bam on them
basename = Util.basename( basename, '.bam' );
for( var n in configs ) {
var c = configs[n];
if( Util.basename( c.bai ? c.bai.blob.name : c.baiUrlTemplate, '.bai' ) == basename ) {
// it's a match, put it in
c.bam = this._makeBlob( resource );
return true;
}
}
// otherwise make a new store config for it
var newName = 'bam_'+uniqCounter++;
configs[newName] = {
type: this.storeType,
bam: this._makeBlob( resource ),
name: newName
};
return true;
} else if( resource.type == 'bai' ) {
var basename = Util.basename(
resource.file ? resource.file.name :
resource.url ? resource.url :
''
, '.bai'
);
if( !basename )
return false;
// go through the configs and look for BAMs that match like zee.bam -> zee.bam.bai
for( var n in configs ) {
var c = configs[n];
if( Util.basename( c.bam ? c.bam.blob.name : c.urlTemplate ) == basename ) {
// it's a match, put it in
c.bai = this._makeBlob( resource );
return true;
}
}
// go through again and look for BAMs that match like zee.bam -> zee.bai
for( var n in configs ) {
var c = configs[n];
if( Util.basename( c.bam ? c.bam.blob.name : c.urlTemplate, '.bam' ) == basename ) {
// it's a match, put it in
c.bai = this._makeBlob( resource );
return true;
}
}
// otherwise make a new store
var newName = 'bam_'+uniqCounter++;
configs[newName] = {
bai: this._makeBlob( resource ),
name: newName,
type: this.storeType
};
return true;
}
else
return false;
},
_makeBlob: function( resource ) {
var r = resource.file ? new FileBlob( resource.file ) :
resource.url ? new XHRBlob( resource.url ) :
null;
if( ! r )
throw 'unknown resource type';
return r;
},
confIsValid: function( conf ) {
return (conf.bam || conf.urlTemplate) && ( conf.bai || conf.baiUrlTemplate || conf.urlTemplate );
}
};
});