Skip to content

Commit 5a8b858

Browse files
committed
Transition of bins depending on zoom level
1 parent f306a57 commit 5a8b858

File tree

3 files changed

+155
-45
lines changed

3 files changed

+155
-45
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,4 @@ server_tsspredator.egg-info/PKG-INFO
3232
celerybeat-schedule.db
3333
server_tsspredator/exampleData/campylobacter/files.zip
3434
server_tsspredator/exampleData/pseudomonas/files.zip
35-
celery/redis.config
36-
server_tsspredator/redisdb/redis.config
35+
server_tsspredator.egg-info

server_tsspredator/__init__.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from werkzeug.utils import secure_filename
77
from celery.exceptions import Ignore
88
from celery.utils.log import get_task_logger
9+
import collections
910

1011
import json
1112
import tempfile
@@ -309,7 +310,8 @@ def readMasterTable(path):
309310
'superStrand': superStrand,
310311
'classesTSS': [classesTSS],
311312
"mainClass": classesTSS,
312-
'typeTSS': typeTSS
313+
'typeTSS': typeTSS,
314+
"count": 1
313315
}
314316
else:
315317
data_per_genome[genome]["TSS"][tss_key]['classesTSS'].append(classesTSS)
@@ -347,14 +349,42 @@ def parseSuperGFF (path):
347349

348350
return data_per_gene, maxValue
349351

352+
def aggregateTSS(tssList, maxGenome):
353+
'''aggregate TSS'''
354+
aggregatedTSS = {}
355+
binSizes = [5000,10000,50000]
356+
for binSize in binSizes:
357+
aggregatedTSS[binSize] = []
358+
for i in range(0, maxGenome, binSize):
359+
binStart = i
360+
binEnd = i + binSize
361+
filteredTSS = [(tss["mainClass"],tss["superStrand"], tss["typeTSS"]) for tss in tssList if binStart <= int(tss["superPos"]) <= binEnd]
362+
countedTSS = dict(collections.Counter(filteredTSS))
363+
expanded_countedTSS = []
364+
for key in countedTSS.keys():
365+
tempValue = {}
366+
tempValue['mainClass'] = key[0]
367+
tempValue['strand'] = key[1]
368+
tempValue['typeTSS'] = key[2]
369+
tempValue['count'] = countedTSS[key]
370+
tempValue['binStart'] = binStart
371+
372+
tempValue['binEnd'] = min(binEnd, maxGenome)
373+
expanded_countedTSS.append(tempValue)
374+
375+
376+
aggregatedTSS[binSize].extend(expanded_countedTSS)
377+
return aggregatedTSS
378+
379+
380+
350381
@app.route('/api/TSSViewer/<filePath>/')
351382
def getTSSViewer(filePath):
352383
'''send result of TSS prediction to frontend'''
353384
print(filePath)
354385
# get path of zip file
355386
completePath = tempfile.gettempdir().replace('\\', '/') + '/' + filePath + '/result.zip'
356387
if os.path.exists(completePath):
357-
print(completePath)
358388
# Unzip MasterTable
359389
try:
360390
with tempfile.TemporaryDirectory(prefix="tmpPredViewer") as tmpdir:
@@ -370,6 +400,8 @@ def getTSSViewer(filePath):
370400
# read SuperGFF
371401
masterTable[genomeKey]['superGFF'], maxValue = parseSuperGFF(superGFFPath)
372402
masterTable[genomeKey]['maxValue'] = maxValue
403+
masterTable[genomeKey]['aggregatedTSS'] = aggregateTSS(masterTable[genomeKey]['TSS'], maxValue)
404+
print(masterTable[genomeKey]['aggregatedTSS'])
373405

374406
return jsonify({'result': 'success', 'data': masterTable})
375407
except Exception as e:

src/components/Result/GoslingViz.js

Lines changed: 120 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ function GoslingGenomeViz({ dataKey, showPlot, filter }) {
3636
"spacing": 50,
3737
"views": getViews(data["data"])
3838
};
39-
console.log(spec);
4039
setSpec(spec);
4140
} catch (error) {
4241
console.error("Error fetching data:", error);
@@ -64,6 +63,16 @@ function GoslingGenomeViz({ dataKey, showPlot, filter }) {
6463
"opacity": { "value": 0.4 },
6564
"size": { "value": 4 },
6665
"tracks": [{
66+
"tooltip": [
67+
{ "field": "start", "type": "genomic", "alt": "Gene Start" },
68+
{ "field": "end", "type": "genomic", "alt": "Gene End" },
69+
{
70+
"field": "locus_tag",
71+
"type": "nominal",
72+
"alt": "Locus Tag",
73+
},
74+
{ "field": "product", "alt": "Gene Product" },
75+
],
6776

6877
"dataTransform": [
6978
{ "type": "filter", "field": "strand", "oneOf": "+" }
@@ -80,7 +89,9 @@ function GoslingGenomeViz({ dataKey, showPlot, filter }) {
8089

8190
}
8291

83-
const createTSSTrack = (data, strand, title = null) => {
92+
const createTSSTrack = (data, aggregatedTSS, strand, title = null) => {
93+
console.log(aggregatedTSS);
94+
console.log(data);
8495
return [
8596
{
8697
"title": title,
@@ -90,61 +101,129 @@ function GoslingGenomeViz({ dataKey, showPlot, filter }) {
90101
"type": "json",
91102
"genomicFields": ["superPos"],
92103
},
93-
// "row": { "field": "superStrand", "type": "nominal", "domain": ["+", "-"] },
94-
// "mark": "point",
95-
// "x": { "field": "superPos", "type": "genomic", "axis": "top" },
96104

97105
"color": {
98106
"field": "mainClass",
99107
"type": "nominal",
100-
101108
"domain": ["Primary", "Secondary", "Internal", "Antisense", "Orphan"],
102109
"range": ["#7585FF", "#FF8A85", "#FFC785", "#85FFD9", "#B285FF"],
103110
"legend": strand === "+"
104111
},
105-
"tracks": [{
106-
"dataTransform": [
107-
{ "type": "filter", "field": "superStrand", "oneOf": [strand] }
108-
],
109-
"x": { "field": "superPos", "type": "genomic", "axis": strand === "+" ? "top" : "none" },
110-
"mark": strand === "+" ? "triangleRight" : "triangleLeft",
111-
"style": { "align": strand === "+" ? "left" : "right" },
112-
"size": { "value": 15 },
113-
},
114-
{
115-
"data": {
116-
"values": data.filter(d => filter.includes(d["typeTSS"])),
117-
"type": "json",
118-
"genomicFields": ["superPos"],
119-
"binSize": 10,
120-
},
121-
"dataTransform": [
122-
{ "type": "filter", "field": "superStrand", "oneOf": [strand] }
123-
],
124-
"x": { "field": "superPos", "type": "genomic", "aggregate": "bin", "axis": "none" },
125-
"xe": { "field": "superPos", "type": "genomic" },
126-
// "size": { "value": 10 },
127-
"y": {
128-
"field": "mainClass", "type": "nominal", "axis": "none",
129-
"domain": ["Primary", "Secondary", "Internal", "Antisense", "Orphan"],
130-
"range": [50, 50, 50, 50, 50],
131-
"aggregate": "count"
132-
133-
},
134-
"mark": "bar",
135-
// "y": { "type": "quantitative", "axis": "none" },
136-
}]
112+
"tracks": [
113+
{
114+
115+
"dataTransform": [
116+
{ "type": "filter", "field": "superStrand", "oneOf": [strand] }
117+
],
118+
"x": { "field": "superPos", "type": "genomic", "axis": strand === "+" ? "top" : "none" },
119+
"mark": strand === "+" ? "triangleRight" : "triangleLeft",
120+
"style": { "align": strand === "+" ? "left" : "right" },
121+
"size": { "value": 15 },
122+
"tooltip": [
123+
{ "field": "superPos", "type": "genomic", "alt": "TSS Position" },
124+
{
125+
"field": "mainClass",
126+
"type": "nominal",
127+
"alt": "Main TSS class",
128+
},
129+
{ "field": "classesTSS", "alt": "All TSS classes" },
130+
],
131+
"visibility": [
132+
{
133+
"operation": "LT",
134+
"measure": "zoomLevel",
135+
"threshold": 50000,
136+
"transitionPadding": 500,
137+
"target": "mark"
138+
}
139+
]
140+
}, ...[
141+
{ "GT": 50000, "LT": 200000, "size": 5000 },
142+
{ "GT": 200000, "LT": 500000, "size": 10000 },
143+
{ "GT": 500000, "LT": null, "size": 50000 }].map(({ GT, LT, size }) => {
144+
console.log(GT, LT, size);
145+
return {
146+
"data": {
147+
"values": aggregatedTSS[size].filter(d => filter.includes(d["typeTSS"])),
148+
"type": "json",
149+
"genomicFields": ["binStart", "binEnd"],
150+
},
151+
"dataTransform": [
152+
{ "type": "filter", "field": "strand", "oneOf": [strand] }
153+
],
154+
"x": { "field": "binStart", "type": "genomic", "axis": strand === "+" ? "top" : "none", },
155+
"xe": { "field": "binEnd", "type": "genomic", },
156+
"mark": "bar",
157+
"y": { "field": "count", "type": "quantitative" },
158+
"color": {
159+
"field": "mainClass",
160+
"type": "nominal",
161+
"domain": ["Primary", "Secondary", "Internal", "Antisense", "Orphan"],
162+
"range": ["#7585FF", "#FF8A85", "#FFC785", "#85FFD9", "#B285FF"],
163+
"legend": false
164+
},
165+
"tooltip": [
166+
{ "field": "binStart", "type": "genomic", "alt": "Bin start" },
167+
{
168+
"field": "mainClass",
169+
"type": "nominal",
170+
"alt": "Main TSS class",
171+
},
172+
{ "field": "count", "alt": "Number of TSS" },
173+
{ "field": "binEnd", "alt": "Bin end" },
174+
],
175+
"visibility": [
176+
{
177+
"operation": "GT",
178+
"measure": "zoomLevel",
179+
"threshold": GT,
180+
"transitionPadding": 10,
181+
"target": "mark"
182+
},
183+
{
184+
"operation": "LT",
185+
"measure": "zoomLevel",
186+
"threshold": LT,
187+
"transitionPadding": 10,
188+
"target": "mark"
189+
}
190+
]
191+
}
192+
})
193+
194+
,
195+
// {
196+
// "data": {
197+
// "values": [{ "test": 1, "binStart": 12, "binEnd": 412 }],
198+
// "type": "json",
199+
// // "genomicFields": ["binStart", "binEnd"],
200+
201+
// },
202+
// // "dataTransform": [
203+
// // { "type": "filter", "field": "strand", "oneOf": [strand] }
204+
// // ],
205+
// // "x": { "field": "binStart", "type": "genomic", "axis": "none" },
206+
// // "size": { "value": 1 },
207+
// // "color": {
208+
// // "field": "typeTSS",
209+
// // "type": "nominal",
210+
// // "domain": ["Primary", "Secondary", "Internal", "Antisense", "Orphan"],
211+
// // "range": ["#7585FF", "#FF8A85", "#FFC785", "#85FFD9", "#B285FF"],
212+
// // "legend": false
213+
// // },
214+
// "mark": "bar",
215+
// }
216+
]
137217
}
138218

139219
]
140220
}
141221

142222
const createTracks = (data, title) => {
143223
let geneTracks = createGeneTrack(data["superGFF"]);
144-
let TSSTracks_plus = createTSSTrack(data["TSS"], "+", title);
145-
let TSSTracks_minus = createTSSTrack(data["TSS"], "-");
224+
let TSSTracks_plus = createTSSTrack(data["TSS"], data["aggregatedTSS"], "+", title);
225+
let TSSTracks_minus = createTSSTrack(data["TSS"], data["aggregatedTSS"], "-");
146226
return TSSTracks_plus.concat(geneTracks).concat(TSSTracks_minus);
147-
148227
}
149228

150229
const getViews = (data) => {

0 commit comments

Comments
 (0)