Skip to content

Commit 99ff688

Browse files
committed
Adapted maxBin size per Strand
1 parent cb5da1a commit 99ff688

File tree

3 files changed

+110
-69
lines changed

3 files changed

+110
-69
lines changed

server_tsspredator/__init__.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,8 @@ def readMasterTable(path):
305305
classesTSS = getTSSClass(line, headerIndices)
306306
if tss_key not in data_per_genome[genome]["TSS"]:
307307
typeTSS = getTSSType(line, headerIndices)
308+
if typeTSS == "Undetected":
309+
continue
308310
data_per_genome[genome]["TSS"][tss_key] = {
309311
'superPos': superPos,
310312
'superStrand': superStrand,
@@ -353,28 +355,37 @@ def aggregateTSS(tssList, maxGenome):
353355
'''aggregate TSS'''
354356
aggregatedTSS = {}
355357
binSizes = [5000,10000,50000]
358+
binSizeMax = {}
356359
for binSize in binSizes:
357360
aggregatedTSS[binSize] = []
361+
maxBinCount = {"+": 0, "-": 0}
358362
for i in range(0, maxGenome, binSize):
359363
binStart = i
360364
binEnd = i + binSize
361-
filteredTSS = [(tss["mainClass"],tss["superStrand"], tss["typeTSS"]) for tss in tssList if binStart <= int(tss["superPos"]) <= binEnd]
365+
filteredTSS = [(tss["mainClass"],tss["superStrand"], tss["typeTSS"]) for tss in tssList if binStart <= int(tss["superPos"]) < binEnd]
362366
countedTSS = dict(collections.Counter(filteredTSS))
363367
expanded_countedTSS = []
368+
binSum = {"+": 0, "-": 0}
364369
for key in countedTSS.keys():
370+
371+
binSum[key[1]] += countedTSS[key]
365372
tempValue = {}
366373
tempValue['mainClass'] = key[0]
367374
tempValue['strand'] = key[1]
368375
tempValue['typeTSS'] = key[2]
369376
tempValue['count'] = countedTSS[key]
377+
370378
tempValue['binStart'] = binStart
371379

372380
tempValue['binEnd'] = min(binEnd, maxGenome)
373381
expanded_countedTSS.append(tempValue)
374-
375-
382+
maxBinCount = {"+": max(maxBinCount["+"], binSum["+"]), "-": max(maxBinCount["-"], binSum["-"])}
383+
if binSum['+'] ==64:
384+
print(expanded_countedTSS)
376385
aggregatedTSS[binSize].extend(expanded_countedTSS)
377-
return aggregatedTSS
386+
binSizeMax[binSize] = maxBinCount
387+
388+
return aggregatedTSS, binSizeMax
378389

379390

380391

@@ -399,7 +410,8 @@ def getTSSViewer(filePath):
399410
# read SuperGFF
400411
masterTable[genomeKey]['superGFF'], maxValue = parseSuperGFF(superGFFPath)
401412
masterTable[genomeKey]['maxValue'] = maxValue
402-
masterTable[genomeKey]['aggregatedTSS'] = aggregateTSS(masterTable[genomeKey]['TSS'], maxValue)
413+
masterTable[genomeKey]['aggregatedTSS'], maxValueTSS = aggregateTSS(masterTable[genomeKey]['TSS'], maxValue)
414+
masterTable[genomeKey]['maxAggregatedTSS'] = maxValueTSS
403415

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

src/components/Result/GoslingViz.js

Lines changed: 82 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import { GoslingComponent } from "gosling.js";
99
* @returns {JSX.Element} - The rendered genome visualization component.
1010
*/
1111
function GoslingGenomeViz({ dataKey, showPlot, filter }) {
12-
12+
const COLORS_TSS = ["#80b1d3", "#fb8072", "#ffffb3", "#8dd3c7", "#bebada"]
13+
const ORDER_TSS_CLASSES = ["Primary", "Secondary", "Internal", "Antisense", "Orphan"]
1314
const [spec, setSpec] = useState(null);
1415

1516
const fetchData = async (dataKey) => {
@@ -31,11 +32,25 @@ function GoslingGenomeViz({ dataKey, showPlot, filter }) {
3132
console.error("Error fetching data:", data);
3233
return;
3334
}
34-
const spec = {
35+
const maxValue = Math.max(...Object.values(data["data"]).map(d => d["maxValue"]));
36+
const allViews = getViews(data["data"])
37+
const distributedViews = [{
3538
"arrangement": "vertical",
39+
"views": allViews.filter((_, i) => i < allViews.length / 2)
40+
}, {
41+
"arrangement": "vertical",
42+
"views": allViews.filter((_, i) => i >= allViews.length / 2)
43+
}]
44+
45+
const spec = {
46+
style: { background: "gray", backgroundOpacity: 0.05, outline: "black", outlineWidth: 2 },
47+
"title": "Visualization of TSSs and Genes",
48+
"arrangement": "horizontal",
3649
"spacing": 50,
3750
"linkingId": "detail",
38-
"views": getViews(data["data"])
51+
"zoomLimits": [0, maxValue],
52+
53+
"views": distributedViews
3954
};
4055
setSpec(spec);
4156
} catch (error) {
@@ -90,64 +105,63 @@ function GoslingGenomeViz({ dataKey, showPlot, filter }) {
90105

91106
}
92107

93-
const createTSSTrack = (data, aggregatedTSS, strand, title = null) => {
94-
let binnedViews = [
95-
{ "GT": 50000, "LT": 200000, "size": 5000 },
96-
{ "GT": 200000, "LT": 500000, "size": 10000 },
97-
{ "GT": 500000, "LT": NaN, "size": 50000 }].map(({ GT, LT, size }) => {
98-
let transitionPadding = 20000;
99-
return {
100-
"data": {
101-
"values": aggregatedTSS[size].filter(d => filter.includes(d["typeTSS"])),
102-
"type": "json",
103-
"genomicFields": ["binStart", "binEnd"],
104-
},
105-
"dataTransform": [
106-
{ "type": "filter", "field": "strand", "oneOf": [strand] }
107-
],
108-
"x": { "field": "binStart", "type": "genomic", "axis": strand === "+" ? "top" : "none", },
109-
"xe": { "field": "binEnd", "type": "genomic", },
110-
"mark": "bar",
111-
"y": { "field": "count", "type": "quantitative", axis: "left" },
112-
"color": {
108+
const createTSSTrack = (data, aggregatedTSS, binSizes, strand, maxGenome, title = null) => {
109+
let sizesBins = Object.keys(binSizes).map((size, i) => { return { "GT": size * 10, "LT": (i === Object.keys(binSizes).length - 1) ? maxGenome * 1.1 : size * 40, size: parseInt(size), maxValueBin: binSizes[size] } })
110+
console.log(sizesBins)
111+
let binnedViews = sizesBins.map(({ GT, LT, size, maxValueBin }) => {
112+
let transitionPadding = 25000;
113+
return {
114+
"data": {
115+
"values": aggregatedTSS[size].filter(d => filter.includes(d["typeTSS"])),
116+
"type": "json",
117+
"genomicFields": ["binStart", "binEnd"],
118+
},
119+
"dataTransform": [
120+
{ "type": "filter", "field": "strand", "oneOf": [strand] }
121+
],
122+
"x": { "field": "binStart", "type": "genomic", "axis": strand === "+" ? "top" : "none", },
123+
"xe": { "field": "binEnd", "type": "genomic", "axis": "none" },
124+
"mark": "bar",
125+
"y": { "field": "count", "type": "quantitative", axis: "left", domain: [0, maxValueBin[strand]], range: [0, 90] },
126+
"color": {
127+
"field": "mainClass",
128+
"type": "nominal",
129+
"domain": ORDER_TSS_CLASSES,
130+
"range": COLORS_TSS,
131+
"legend": strand === "+"
132+
},
133+
"tooltip": [
134+
{ "field": "binStart", "type": "genomic", "alt": "Bin start" },
135+
{ "field": "binEnd", "alt": "Bin end" },
136+
{
113137
"field": "mainClass",
114138
"type": "nominal",
115-
"domain": ["Primary", "Secondary", "Internal", "Antisense", "Orphan"],
116-
"range": ["#7585FF", "#FF8A85", "#FFC785", "#85FFD9", "#B285FF"],
117-
"legend": strand === "+"
139+
"alt": "Main TSS class",
118140
},
119-
"tooltip": [
120-
{ "field": "binStart", "type": "genomic", "alt": "Bin start" },
121-
{ "field": "binEnd", "alt": "Bin end" },
122-
{
123-
"field": "mainClass",
124-
"type": "nominal",
125-
"alt": "Main TSS class",
126-
},
127-
{ "field": "count", "alt": "Number of TSS" },
128-
],
129-
"visibility": [
130-
{
131-
"operation": "GT",
132-
"measure": "zoomLevel",
133-
"threshold": GT,
134-
"transitionPadding": transitionPadding,
135-
"target": "track"
136-
},
137-
!isNaN(LT) &&
138-
{
139-
"operation": "LT",
140-
"measure": "zoomLevel",
141-
"threshold": LT + 7500,
142-
"transitionPadding": transitionPadding,
143-
"target": "track"
144-
}
145-
]
146-
}
147-
});
141+
{ "field": "count", "alt": "Number of TSS" },
142+
],
143+
"visibility": [
144+
{
145+
"operation": "GT",
146+
"measure": "zoomLevel",
147+
"threshold": GT,
148+
"transitionPadding": transitionPadding,
149+
"target": "track"
150+
},
151+
!isNaN(LT) &&
152+
{
153+
"operation": "LT",
154+
"measure": "zoomLevel",
155+
"threshold": LT,
156+
"transitionPadding": transitionPadding,
157+
"target": "track"
158+
}
159+
]
160+
}
161+
});
148162
return [
149163
{
150-
"title": title,
164+
151165
"alignment": "overlay",
152166
"data": {
153167
"values": data.filter(d => filter.includes(d["typeTSS"])),
@@ -158,7 +172,7 @@ function GoslingGenomeViz({ dataKey, showPlot, filter }) {
158172

159173
"tracks": [
160174
{
161-
175+
"title": title,
162176
"dataTransform": [
163177
{ "type": "filter", "field": "superStrand", "oneOf": [strand] }
164178
],
@@ -169,8 +183,8 @@ function GoslingGenomeViz({ dataKey, showPlot, filter }) {
169183
"color": {
170184
"field": "mainClass",
171185
"type": "nominal",
172-
"domain": ["Primary", "Secondary", "Internal", "Antisense", "Orphan"],
173-
"range": ["#7585FF", "#FF8A85", "#FFC785", "#85FFD9", "#B285FF"],
186+
"domain": ORDER_TSS_CLASSES,
187+
"range": COLORS_TSS,
174188
"legend": strand === "+"
175189
},
176190
"tooltip": [
@@ -198,10 +212,10 @@ function GoslingGenomeViz({ dataKey, showPlot, filter }) {
198212
]
199213
}
200214

201-
const createTracks = (data, title) => {
215+
const createTracks = (data, title, maxGenome) => {
202216
let geneTracks = createGeneTrack(data["superGFF"]);
203-
let TSSTracks_plus = createTSSTrack(data["TSS"], data["aggregatedTSS"], "+", title);
204-
let TSSTracks_minus = createTSSTrack(data["TSS"], data["aggregatedTSS"], "-");
217+
let TSSTracks_plus = createTSSTrack(data["TSS"], data["aggregatedTSS"], data["maxAggregatedTSS"], "+", maxGenome, title);
218+
let TSSTracks_minus = createTSSTrack(data["TSS"], data["aggregatedTSS"], data["maxAggregatedTSS"], "-", maxGenome);
205219
return TSSTracks_plus.concat(geneTracks).concat(TSSTracks_minus);
206220
}
207221

@@ -211,17 +225,21 @@ function GoslingGenomeViz({ dataKey, showPlot, filter }) {
211225
views.push({
212226
"alignment": "stack",
213227
"title": genome,
228+
214229
"assembly": [["", data[genome]["maxValue"]]],
215230
"spacing": 0,
216231
"layout": "linear",
217-
"tracks": createTracks(data[genome], genome,)
232+
"tracks": createTracks(data[genome], genome, data[genome]["maxValue"])
218233
})
219234
}
220235
return views;
221236

222237
}
223238

224-
return spec && <GoslingComponent spec={spec} />
239+
return showPlot && (spec && <div style={{ padding: "0 !important", width: "100vw" }}>
240+
<GoslingComponent spec={spec} />
241+
</div>
242+
);
225243

226244

227245

src/css/Result.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,14 @@
2929
.result-margin-left {
3030
margin-left: 3%;
3131
}
32+
33+
.gosling-component{
34+
padding: 0 0 0 0 !important; /* remove padding */
35+
/* center elements */
36+
display: flex;
37+
justify-content: center;
38+
align-items: center;
39+
flex-direction: column;
40+
margin: 0 0 0 0;
41+
42+
}

0 commit comments

Comments
 (0)