This repository has been archived by the owner on Aug 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew_routes.py
221 lines (179 loc) · 6.09 KB
/
new_routes.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
from bottle import request, response, static_file
import hashlib
import os
import pandas as pd
import time
pdApp.tprefix = "iFISH4U|Probe Design|"
pdApp.vd["breadcrumbs"] = True
pdApp.vd["SHOW_COOKIE_CONSENT_BANNER"] = True
pdApp.vd["menu_template"] = "design_menu.tpl"
pdApp.vd["google_analytics_token"] = "UA-99031010-6"
class EnableCors(object):
"""https://stackoverflow.com/a/17262900/1593536"""
name = "enable_cors"
api = 2
def apply(self, fn, context):
def _enable_cors(*args, **kwargs):
# set CORS headers
response.headers["Access-Control-Allow-Origin"] = "*"
response.headers["Access-Control-Allow-Methods"] = "GET, POST, PUT, OPTIONS"
response.headers[
"Access-Control-Allow-Headers"
] = "Origin, Accept, Content-Type, X-Requested-With, X-CSRF-Token"
if request.method != "OPTIONS":
# actual request; reply with the actual response
return fn(*args, **kwargs)
return _enable_cors
pdApp.install(EnableCors())
@root.route("/browse")
@root.route("/browse/")
@bot.view("browse")
def callback():
d = {}
d["custom_stylesheets"] = []
d["title"] = "iFISH4U|Browse"
d["description"] = "Browse iFISH probes."
return d
@root.route("/download")
@root.route("/download/")
@bot.view("download")
def callback():
d = {}
d["custom_stylesheets"] = []
d["title"] = "iFISH4U|Download"
d["description"] = "Download iFISH databases."
return d
@root.route("/aftf")
@root.route("/aftf/")
@bot.view("aftf")
def callback():
d = {}
d["custom_stylesheets"] = []
d["title"] = "iFISH4U|Advanced FISH Techniques Facility"
d["description"] = "Order probes via our facility."
return d
@root.route("/custom_images/<path>")
def callback(path):
return bot.static_file(path, f"{os.path.dirname(args.custom_routes)}/images/")
@root.route("/custom_css/<path>")
def callback(path):
return bot.static_file(path, f"{os.path.dirname(args.custom_routes)}/css/")
@root.route("/custom_js/<path>")
def callback(path):
return bot.static_file(path, f"{os.path.dirname(args.custom_routes)}/js/")
@root.route("/custom_data/<path>")
def callback(path):
return bot.static_file(path, f"{os.path.dirname(args.custom_routes)}/data/")
@root.route("/custom/giemsa_bands")
def callback():
giemsa = pd.read_csv(
os.path.join(
os.path.dirname(args.custom_routes), "data", "hg19.giemsa_bands.txt"
),
"\t",
)
return giemsa.to_json(orient="records")
@root.route("/custom/giemsa_bands/chr/<chrom>")
def callback(chrom):
giemsa = pd.read_csv(
os.path.join(
os.path.dirname(args.custom_routes), "data", "hg19.giemsa_bands.txt"
),
"\t",
)
giemsa = giemsa.loc[giemsa["chrom"] == chrom]
giemsa = giemsa.reset_index()
return giemsa.to_json(orient="records")
@root.route("/custom/probe_list")
def callback():
probes = pd.read_csv(
os.path.join(
os.path.dirname(args.custom_routes),
"data",
"tda_dna-unifish_oligopool_chr_spotting.bed",
),
"\t",
)
return probes.to_json(orient="records")
@root.route("/custom/probe_list/pos/<chrom>\:<chromStart>-<chromEnd>")
def callback(chrom, chromStart, chromEnd):
probes = pd.read_csv(
os.path.join(
os.path.dirname(args.custom_routes),
"data",
"tda_dna-unifish_oligopool_chr_spotting.bed",
),
"\t",
)
probes = probes.loc[probes["chrom"].values == chrom, :]
probes = probes.loc[probes["chromStart"].values >= int(chromStart), :]
probes = probes.loc[probes["chromEnd"].values <= int(chromEnd), :]
return probes.to_json(orient="records")
@root.get("/custom/probe_download/")
def callback():
GET = dict(request.query)
probeList = GET["probes"].replace("[", "").replace("]", "").split(",")
withPrimers = int(GET["primers"]) == 1
fastaTotal = [""]
for probeName in probeList:
probeName = probeName.strip('"')
if withPrimers:
probePath = f"{probeName}.with_primers.fa"
else:
probePath = f"{probeName}.fa"
probePath = os.path.join(
os.path.dirname(args.custom_routes), "data", "probes", probePath
)
if not os.path.isfile(probePath):
return f'ERROR: cannot find probe "{probeName}".'
else:
with open(probePath, "r") as IH:
fastaTotal.append("".join(IH.readlines()))
encoder = hashlib.sha256()
encoder.update(bytes(str(time.time()), "utf-8"))
fastaName = encoder.hexdigest()
response.set_header("Content-Disposition", f'attachment; filename="{fastaName}.fa"')
response.set_header("Content-Type", "plain/txt")
return "".join(fastaTotal).strip()
@root.route("/custom/dbdownload/hg19")
def callback():
return static_file(
"iFISH.40mer.tsv.gz",
os.path.join(os.path.dirname(args.custom_routes), "data", "databases"),
download="iFISH.40mer.hg19.gz",
mimetype="application/gzip",
)
@root.route("/custom/dbdownload/clean/hg19")
def callback():
return static_file(
"iFISH.40mer.clean.tsv.gz",
os.path.join(os.path.dirname(args.custom_routes), "data", "databases"),
download="iFISH.40mer.hg19.clean.gz",
mimetype="application/gzip",
)
@root.route("/custom/dbdownload/chrom/<chrom>")
def callback(chrom):
return static_file(
f"{chrom}.gz",
os.path.join(
os.path.dirname(args.custom_routes),
"data",
"databases",
"iFISH.40mer.singleChr",
),
download=f"iFISH.40mer.hg19.{chrom}.gz",
mimetype="application/gzip",
)
@root.route("/custom/dbdownload/clean/chrom/<chrom>")
def callback(chrom):
return static_file(
f"{chrom}.gz",
os.path.join(
os.path.dirname(args.custom_routes),
"data",
"databases",
"iFISH.40mer.clean.singleChr",
),
download=f"iFISH.40mer.hg19.clean.{chrom}.gz",
mimetype="application/gzip",
)