-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathoptions.py
373 lines (310 loc) · 15.1 KB
/
options.py
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
import os
from urllib.parse import urlparse
from traitlets import (
Float, Unicode, Int, Tuple, List, Instance, Bool, Dict, Enum,
link, observe, default, validate, TraitError, Union, HasTraits, TraitType
)
from ipywidgets import Widget, register, widget_serialization
from ipywidgets.widgets.trait_types import Color, InstanceDict
from ipywidgets.widgets import widget
from ._version import EXTENSION_VERSION
# NB '.txt' considered annotation as it is used in the public genomes. But not as per the doc.
TRACK_FILE_TYPES = { \
'annotation': [ '.txt', \
'.bed', '.gff', '.gff3', '.gtf', '.genePred', '.genePredExt', \
'.peaks', '.narrowPeak', '.broadPeak', '.bigBed', '.bedpe' \
],
'wig': ['.wig', '.bigWig', '.bedGraph'],
'alignment': ['.bam'],
'variant': ['.vcf'],
'seg': ['.seg'],
'spliceJunctions': ['.bed'],
'gwas': ['.gwas', '.bed'],
'interaction': ['.bedpe'],
}
class FieldColors(HasTraits):
field = Unicode()
palette = Dict(key_trait=Unicode, value_trait=Instance(Color))
class SortOption(HasTraits):
chr = Unicode() # chromosone name
position = Int() # genomic position
option = Unicode() # 'BASE', 'STRAND', 'INSERT_SIZE', 'MATE_CHR', 'MQ', 'TAG'
tag = Unicode () # doc not clear
direction = Unicode("ASC") # 'ASC' for ascending, 'DESC' for descending
class SortOrder(HasTraits):
chr = Unicode() # chromosone name
direction = Unicode("ASC") # 'ASC' for ascending, 'DESC' for descending
start = Int()
end = Int()
@register
class Track(Widget):
"""
A class reflecting the common fields of a track as per igv documentation.
https://github.com/igvteam/igv.js/wiki/Tracks-2.0
If a Track type is not inferable a generic Track will be instantiated.
"""
# Name of the widget view class in front-end
_view_name = Unicode('TrackView').tag(sync=True)
# Name of the widget model class in front-end
_model_name = Unicode('TrackModel').tag(sync=True)
# Name of the front-end module containing widget view
_view_module = Unicode('jupyter-igv').tag(sync=True)
# Name of the front-end module containing widget model
_model_module = Unicode('jupyter-igv').tag(sync=True)
# Version of the front-end module containing widget view
_view_module_version = Unicode(EXTENSION_VERSION).tag(sync=True)
# Version of the front-end module containing widget model
_model_module_version = Unicode(EXTENSION_VERSION).tag(sync=True)
def __new__(cls, **kwargs):
if cls is Track:
# we must infer the type to instantiate the right Track type
trackType = kwargs.get('type', None)
if trackType is None:
# then type is inferred from the file extension
url = kwargs.get('url')
path = urlparse(url).path
filename, filetype = os.path.splitext(path)
if filetype == '.gz': # some files might be compressed
innerfilename, innerfiletype = os.path.splitext(filename)
filetype = innerfiletype
for k, v in TRACK_FILE_TYPES.items():
if filetype in v:
trackType = k
break
if trackType == 'annotation':
return super(Track, cls).__new__(AnnotationTrack)
elif trackType == 'alignment':
return super(Track, cls).__new__(AlignmentTrack)
elif trackType == 'variant':
return super(Track, cls).__new__(VariantTrack)
elif trackType == 'wig':
return super(Track, cls).__new__(WigTrack)
elif trackType == 'seg':
return super(Track, cls).__new__(SegTrack)
elif trackType == 'spliceJunctions':
return super(Track, cls).__new__(SpliceJunctionsTrack)
elif trackType == 'gwas':
return super(Track, cls).__new__(GwassTrack)
elif trackType == 'interation':
return super(Track, cls).__new__(InteractionTrack)
else:
return super(Track, cls).__new__(cls)
else:
return super(Track, cls).__new__(cls)
# These fields are common to all Track types
sourceType = Unicode(default_value='file').tag(sync=True) #
format = Unicode().tag(sync=True) # missing documentation
name = Unicode().tag(sync=True)
url = Unicode().tag(sync=True)
indexURL = Unicode().tag(sync=True)
indexed = Bool(default_value=False).tag(sync=True)
order = Int().tag(sync=True)
color = Color().tag(sync=True).tag(sync=True)
height = Int(default_value=50).tag(sync=True)
autoHeight = Bool(default_value=False).tag(sync=True)
minHeight = Int(default_value=50).tag(sync=True)
maxHeight = Int(default_value=500).tag(sync=True)
# visibilityWindow = # missing documentation
removable = Bool(default_value=True).tag(sync=True)
headers = Dict().tag(sync=True)
oauthToken = Unicode(allow_none = True).tag(sync=True)
@register
class AnnotationTrack(Track):
"""
AnnotationTrack as described at:
https://github.com/igvteam/igv.js/wiki/Annotation-Track
"""
type = Unicode('annotation', read_only=True).tag(sync=True)
displayMode = Unicode(default_value = 'COLLAPSED').tag(sync=True)
expandedRowHeight = Int (default_value = 30).tag(sync=True)
squishedRowHeight = Int (default_value = 15).tag(sync=True)
nameField = Unicode(default_value = 'Name').tag(sync=True)
maxRows = Int (default_value = 500).tag(sync=True)
searchable = Bool(default_value=False).tag(sync=True)
filterTypes = List(Unicode, default_value=['chromosone', 'gene']).tag(sync=True, **widget_serialization)
color = Color("rgb(0,0,150)").tag(sync=True)
altColor = Color("rgb(0,0,150)").tag(sync=True)
colorBy = Instance(FieldColors, allow_none=True).tag(sync=True, **widget_serialization)
roi = List(InstanceDict(Track)).tag(sync=True, **widget_serialization) # regions of interest
@register
class AlignmentTrack(Track):
"""
AlignmentTrack as described at:
https://github.com/igvteam/igv.js/wiki/Alignment-Track
"""
type = Unicode('alignment', read_only=True).tag(sync=True)
viewAsPairs = Bool(default_value=False).tag(sync=True)
pairsSupported = Bool(default_value=True).tag(sync=True)
coverageColor = Color(default_value="rgb(150, 150, 150)").tag(sync=True, **widget_serialization) # default: rgb(150, 150, 150)
color = Color(default_value="rgb(170, 170, 170)").tag(sync=True, **widget_serialization) # default: rgb(170, 170, 170)
deletionColor = Color(default_value="black").tag(sync=True, **widget_serialization)
skippedColor = Color(default_value="rgb(150, 170, 170)").tag(sync=True, **widget_serialization) # default: rgb(150, 170, 170)
insertionColor = Color(default_value="rgb(138, 94, 161)").tag(sync=True, **widget_serialization) # default: rgb(138, 94, 161)
negStrandColor = Color(default_value="rgba(150, 150, 230, 0.75)").tag(sync=True, **widget_serialization) # default: rgba(150, 150, 230, 0.75)
posStrandColor = Color(default_value="rgba(230, 150, 150, 0.75)").tag(sync=True, **widget_serialization) # default: rgb(138, 94, 161)
# pairConnectorColor = Instance(Color, default_value="alignmentColor") # default: doc not clear
colorBy = Unicode("none").tag(sync=True) # "none", "strand", "firstOfPairStrand", or "tag"
colorByTag = Unicode().tag(sync=True) # TODO - doc not clear
bamColorTag = Unicode("YC").tag(sync=True) # TODO - doc not clear
samplingWindowSize = Int(100).tag(sync=True)
samplingDepth = Int(100).tag(sync=True)
alignmentRowHeight = Int(14).tag(sync=True)
readgroup = Unicode("RG").tag(sync=True)
sortOption = Instance(SortOption, allow_none=True).tag(sync=True, **widget_serialization)
showSoftClips = Bool(False).tag(sync=True)
showMismatches = Bool(True).tag(sync=True)
# Paired-end and mate-pair coloring options.
pairOrientation = Unicode(allow_none=True).tag(sync=True, **widget_serialization) # ff, fr, or rf
minFragmentLength = Int(allow_none=True).tag(sync=True, **widget_serialization)
maxFragmentLength = Int(allow_none=True).tag(sync=True, **widget_serialization)
roi = List(InstanceDict(Track)).tag(sync=True, **widget_serialization) # regions of interest
@register
class VariantTrack(Track):
"""
VariantTrack as described at:
https://github.com/igvteam/igv.js/wiki/Variant-Track
"""
type = Unicode('variant', read_only=True).tag(sync=True)
displayMode = Unicode('EXPANDED').tag(sync=True)
noCallColor = Color("rgb(250, 250, 250)").tag(sync=True)
homvarColor = Color("rgb(17,248,254)").tag(sync=True)
hetvarColor = Color("rgb(34,12,253)").tag(sync=True)
homrefColor = Color("rgb(200, 200, 200)").tag(sync=True)
squishedCallHeight = Int(1).tag(sync=True)
expandedCallHeight = Int(10).tag(sync=True)
roi = List(InstanceDict(Track)).tag(sync=True, **widget_serialization) # regions of interest
class Guideline(HasTraits):
color = Color().tag(sync=True)
dotted = Bool().tag(sync=True)
y = Int().tag(sync=True)
@register
class WigTrack(Track):
"""
WigTrack as described at:
https://github.com/igvteam/igv.js/wiki/Wig-Track
"""
type = Unicode('wig', read_only=True).tag(sync=True)
autoscale = Bool(True).tag(sync=True)
autoscaleGroup = Unicode(allow_none=True).tag(sync=True, **widget_serialization)
min = Int(0).tag(sync=True)
max = Int(allow_none=True).tag(sync=True, **widget_serialization)
color = Color(default_value="rgb(150, 150, 150)").tag(sync=True)
altColor = Color(allow_none=True).tag(sync=True, **widget_serialization)
guideLines = List(trait=Instance(Guideline), allow_none=True).tag(sync=True, **widget_serialization)
roi = List(InstanceDict(Track)).tag(sync=True, **widget_serialization) # regions of interest
@register
class SegTrack(Track):
"""
SegTrack Track as described at:
https://github.com/igvteam/igv.js/wiki/Seg-Track
"""
type = Unicode('seg', read_only=True).tag(sync=True)
isLog = Bool(allow_none=True).tag(sync=True, **widget_serialization)
displayMode = Unicode("EXPANDED").tag(sync=True) # "EXPANDED", "SQUISHED", or "FILL"
sort = InstanceDict(SortOrder).tag(sync=True, **widget_serialization)
roi = List(InstanceDict(Track)).tag(sync=True, **widget_serialization) # regions of interest
@register
class SpliceJunctionsTrack(Track):
"""
SpliceJunctionsTrack as described at:
https://github.com/igvteam/igv.js/wiki/SpliceJunctions
"""
type = Unicode('spliceJunctions', read_only=True).tag(sync=True)
# Display Options
colorBy = Unicode('numUniqueReads').tag(sync=True) # "numUniqueReads", "numReads", "isAnnotatedJunction", "strand", "motif"
colorByNumReadsThreshold = Int(5).tag(sync=True)
thicknessBasedOn = Unicode('numUniqueReads').tag(sync=True) # "numUniqueReads", "numReads", "isAnnotatedJunction"
bounceHeightBasedOn = Unicode('random').tag(sync=True) # "random", "distance", "thickness"
labelUniqueReadCount = Bool(True).tag(sync=True)
labelMultiMappedReadCount = Bool(True).tag(sync=True)
labelTotalReadCount = Bool(False).tag(sync=True)
labelMotif = Bool(False).tag(sync=True)
labelAnnotatedJunction = Unicode(allow_none=True).tag(sync=True, **widget_serialization)
# Filtering Options
minUniquelyMappedReads = Int(0).tag(sync=True)
minTotalReads = Int(0).tag(sync=True)
maxFractionMultiMappedReads = Int(1).tag(sync=True)
minSplicedAlignmentOverhang = Int(0).tag(sync=True)
hideStrand = Unicode(allow_none=True).tag(sync=True, **widget_serialization) # None, "+" or "-"
hideAnnotatedJunctions = Bool(False).tag(sync=True)
hideUnannotatedJunctions = Bool(False).tag(sync=True)
hideMotifs = List(Unicode).tag(sync=True, **widget_serialization)
roi = List(InstanceDict(Track)).tag(sync=True, **widget_serialization) # regions of interest
@register
class GwasTrack (Track):
"""
GwasTrack as described at:
https://github.com/igvteam/igv.js/wiki/GWAS
"""
type = Unicode('gwas', read_only=True).tag(sync=True)
min = Int(0).tag(sync=True)
max = Int(25).tag(sync=True)
# format = Unicode().tag(sync=True) # 'bed' or 'gwas' - format is already in Track -> validation only
posteriorProbability = Bool(False).tag(sync=True)
dotSize = Int(3).tag(sync=True)
columns = Dict(key_trait=Unicode, value_trait=Int, allow_none=True).tag(sync=True, **widget_serialization)
roi = List(InstanceDict(Track)).tag(sync=True, **widget_serialization) # regions of interest
@register
class InteractionTrack (Track):
"""
InteractionTrack as described at:
https://github.com/igvteam/igv.js/wiki/Interaction
"""
type = Unicode('interaction', read_only=True).tag(sync=True)
arcOrientation = Bool(True).tag(sync=True)
thickness = Int(2).tag(sync=True)
roi = List(InstanceDict(Track)).tag(sync=True, **widget_serialization) # regions of interest
class Exon(HasTraits):
start = Int()
end = Int()
cdStart = Int()
cdEnd = Int()
utr = Bool()
class TrackFeature(HasTraits):
chr = Unicode()
start = Int()
end = Int()
name = Unicode()
score = Float()
strand = Unicode()
cdStart = Int()
cdEnd = Int()
color = Instance(Color)
exons = List(trait=Instance(Exon))
@register
class ReferenceGenome(Widget):
"""
A class reflecting a reference genome as per IGV documentation.
https://github.com/igvteam/igv.js/wiki/Reference-Genome
"""
# Name of the widget view class in front-end
_view_name = Unicode('ReferenceGenomeView').tag(sync=True)
# Name of the widget model class in front-end
_model_name = Unicode('ReferenceGenomeModel').tag(sync=True)
# Name of the front-end module containing widget view
_view_module = Unicode('jupyter-igv').tag(sync=True)
# Name of the front-end module containing widget model
_model_module = Unicode('jupyter-igv').tag(sync=True)
# Version of the front-end module containing widget view
_view_module_version = Unicode(EXTENSION_VERSION).tag(sync=True)
# Version of the front-end module containing widget model
_model_module_version = Unicode(EXTENSION_VERSION).tag(sync=True)
id = Unicode(allow_none=True).tag(sync=True)
name = Unicode(allow_none=True).tag(sync=True)
fastaURL = Unicode().tag(sync=True)
indexURL = Unicode(allow_none=True).tag(sync=True)
cytobandURL = Unicode(allow_none=True).tag(sync=True)
aliasURL = Unicode(allow_none=True).tag(sync=True)
indexed = Bool(allow_none=True, default_value=None).tag(sync=True)
tracks = List(InstanceDict(Track)).tag(sync=True, **widget_serialization)
chromosomeOrder = Unicode(allow_none=True).tag(sync=True)
headers = Dict().tag(sync=True)
wholeGenomeView = Bool(default_value=True).tag(sync=True)
@register
class SearchService(Widget):
url = Unicode()
resultsField = Unicode()
coords = Int(default_value=1)
chromosomeField = Unicode(default_value='chromosome')
startField = Unicode(default_value='start')
endField = Unicode(default_value='end', allow_none=True)