-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathtool.py
164 lines (156 loc) · 6.2 KB
/
tool.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
import igv_notebook
from urllib.parse import urlparse
from os.path import basename
from IPython import get_ipython
from .navbar import show_navbar
# Attempt to import nbtools, if it's not installed create a dummy decorator that does nothing
try:
from nbtools import build_ui
except ImportError:
def build_ui(*args, **kwargs):
def decorator(func):
return func
return decorator
@build_ui(name="Integrative Genomics Viewer (IGV)",
description="Use igv.js to embed an interactive genome visualization",
logo="http://igv.org/web/img/favicon.ico",
origin="+",
run_label="Visualize",
color='#4a8797',
parameter_groups=[
{
"name": "Basic Parameters",
"parameters": ["genome", "tracks", "indices", "locus"],
},
{
"name": "Advanced Parameters",
"parameters": ["track_format", "track_type"],
"hidden": False,
"advanced": True
}
],
parameters={
"genome": {
"name": "genome",
"description": "Choose the genome for your data.",
"type": "choice",
"combo": True,
"sendto": False,
"default": "hg38",
"choices": { # Find a way to read this directly from genomes.json and populate dynamically
"Human (GRCh38/hg38)": "hg38",
"Human (CRCh37/hg19)": "hg19",
"Human (hg18)": "hg18",
"Mouse (GRCm38/mm10)": "mm10",
"Gorilla (gorGor4.1/gorGor4)": "gorGor4",
"Chimp (SAC 2.1.4/panTro4)": "panTro4",
"Bonobo (MPI-EVA panpan1.1/panPan2)": "panPan2",
"Pig (SGSC Sscrofa11.1/susScr11)": "susScr11",
"Cow (UMD_3.1.1/bosTau8)": "bosTau8",
"Dog (Broad CanFam3.1/canFam3)": "canFam3",
"Rat (RGCS 6.0/rn6)": "rn6",
"Zebrafish (GRCZ11/danRer11)": "danRer11",
"Zebrafish (GRCZ10/danRer10)": "danRer10",
"D. melanogaster (dm6)": "dm6",
"C. elegans (ce11)": "ce11",
"S. cerevisiae (sacCer3)": "sacCer3"
}
},
"tracks": {
"name": "tracks",
"description": "Enter the URL to the track dataset(s)",
"type": "file",
"optional": True,
"default": "",
"maximum": 100
},
"indices": {
"name": "indices",
"description": "Enter the URL to the index files that correspond to each track",
"type": "file",
"optional": True,
"default": "",
"maximum": 100
},
"track_format": {
"name": "track format",
"description": "Enter the format of the track datasets",
"type": "choice",
"combo": True,
"optional": True,
"default": "",
"choices": { # Display some common track formats
"": "",
"bw": "bw",
"bigwig": "bigwig",
"wig": "wig",
"bedgraph": "bedgraph",
"tdf": "tdf",
"vcf": "vcf",
"seg": "seg",
"mut": "mut",
"bam": "bam",
"cram": "cram",
"bedpe": "bedpe",
"bedpe-loop": "bedpe-loop",
"bp": "bp",
"gwas": "gwas",
"bed": "bed",
"bigbed": "bigbed",
"bb": "bb"
}
},
"track_type": {
"name": "track type",
"description": "Enter the type of the track datasets",
"type": "choice",
"combo": True,
"optional": True,
"default": "",
"choices": { # Display some common track types
"": "",
"annotation": "annotation",
"variant": "variant",
"alignment": "alignment",
"interaction": "interaction",
"wig": "wig",
"seg": "seg",
"mut": "mut",
"arc": "arc",
"gwas": "gwas",
"bedtype": "bedtype"
}
},
"locus": {
"name": "locus",
"description": "Provide a locus or gene of interest for your data",
"type": "text",
"optional": True,
"default": "",
}
})
def igv_tool(genome, tracks=None, indices=None, track_format=None, track_type=None, locus=None):
# Create the navbar
show_navbar()
# Create the genome browser and display it
igv_notebook.file_reader.get_ipython = get_ipython # Workaround for a bug in igv_notebook
igv_notebook.init()
browser = igv_notebook.Browser({"genome": genome, "locus": locus})
# Ensure tracks and indices are represented as lists
if not tracks: tracks = []
if not indices: indices = []
if type(tracks) == str: tracks = [tracks]
if type(indices) == str: indices = [indices]
# Add tracks to the browser
for i in range(len(tracks)):
track_spec = {
"name": basename(urlparse(tracks[i]).path),
"url": tracks[i]
}
if track_format: track_spec['format']: track_format
if track_type: track_spec['type']: track_type
if i < len(indices) and indices[i]:
track_spec['indexURL'] = indices[i]
else:
track_spec['indexed'] = False
browser.load_track(track_spec)