Skip to content

Commit

Permalink
removed plotly
Browse files Browse the repository at this point in the history
  • Loading branch information
lmdu committed Nov 3, 2024
1 parent 35cf934 commit c5ea8f0
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 57 deletions.
2 changes: 1 addition & 1 deletion src/resources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<file>icons/success.svg</file>
<file>scripts/datatables.min.css</file>
<file>scripts/datatables.min.js</file>
<file>scripts/plotly.min.js</file>
<file>scripts/echarts.min.js</file>
<file>scripts/tabler.min.css</file>
<file>scripts/tabler.min.js</file>
<file>template/stats.html</file>
Expand Down
45 changes: 45 additions & 0 deletions src/scripts/echarts.min.js

Large diffs are not rendered by default.

124 changes: 68 additions & 56 deletions src/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -1084,7 +1084,7 @@ def get_script_js(self):
js_files = [
":/scripts/tabler.min.js",
":/scripts/datatables.min.js",
":/scripts/plotly.min.js"
":/scripts/echarts.min.js"
]

js = []
Expand Down Expand Up @@ -1166,8 +1166,53 @@ def get_stats_tables(self):

return tables

def draw_pie_plot(self, pid, title, name, data):
return """
echarts.init(document.getElementById('{pid}')).setOption({
title: {
text: {title}
},
series: [{
name: {name},
type: 'pie',
radius: ['40%', '70%'],
label: {
show: true,
},
emphasis: {
label: {
show: true,
fontSize: 32,
fontWeight: 'bold'
}
},
data: {data}
}]
});
""".format(pid=pid, title=title, name=name, data=data)

def draw_bar_plot(self, pid, title, name, data):
return """
echarts.init(document.getElementById('{pid}')).setOption({
title: {
text: {title}
},
xAxis: {
type: 'category',
data: {name}
},
yAxis: {
type: 'value'
},
series: [{
data: {data},
type: 'bar'
}]
});
""".format(pid=pid, title=title, name=name, data=data)

def get_stats_plots(self):
plots = []
plots = {}

for i, f in enumerate(self.fastx_files):
datas = self.fastx_datas[i]
Expand All @@ -1177,70 +1222,33 @@ def get_stats_plots(self):

for s in datai:
if s == 'type_stats':
names = []
counts = []
lengths = []

for row in datai[s]:
names.append(row[0])
counts.append(row[1])
lengths.append(row[2])
counts.append({'value': row[1], 'name': row[0]})
lengths.append({'value': row[2], 'name': row[0]})

plots.append("""
Plotly.newPlot('{cat}-count-pie-{idx}', [{{
type: 'pie',
values: {counts},
labels: {names}
}}], {{
title: "{cat} count distribution",
font: {{size: 14}}
}}, {{
responsive: true
}});
pid = "{}-count-pie-{}".format(rtype, f.id)
title = "{} count distribution".format(rtype)
name = "{} count".format(rtype)
plots[pid] = self.draw_pie_plot(pid, title, name, counts)

Plotly.newPlot('{cat}-length-pie-{idx}', [{{
type: 'pie',
values: {lengths},
labels: {names}
}}], {{
title: "{cat} length distribution",
font: {{size: 14}}
}}, {{
responsive: true
}});
""".format(
cat = rtype,
idx = f.id,
names = json.dumps(names),
counts = json.dumps(counts),
lengths = json.dumps(lengths)
))
pid = "{}-length-pie-{}".format(rtype, f.id)
title = "{} length distribution".format(rtype)
name = "{} length".format(rtype)
plots[pid] = self.draw_pie_plot(pid, title, name, counts)

if s == 'annot_stats':
names = []
counts = []

for row in datai[s]:
names.append(row[0])
counts.append(row[1])
counts.append({'value': row[1], 'name': row[0]})

plots.append("""
Plotly.newPlot('{cat}-annot-pie-{idx}', [{{
type: 'pie',
values: {counts},
labels: {names}
}}], {{
title: "{cat} distribution in different regions",
font: {{size: 14}}
}}, {{
responsive: true
}});
""".format(
cat = rtype,
idx = f.id,
names = json.dumps(names),
counts = json.dumps(counts)
))
pid = "{}-annot-pie-{}".format(rtype, f.id)
title = "{} distribution in different gene regions".format(rtype)
name = "{} annotation".format(rtype)
plots[pid] = self.draw_pie_plot(pid, title, name, counts)

if s == 'motif_stats':
motifs = []
Expand All @@ -1250,13 +1258,17 @@ def get_stats_plots(self):
motifs.append(row[0])
counts.append(row[5])

pid = "{}-motif-bar-{idx}".format(rtype, f.id)
title = "{} motif distribution".format(rtype)
plots[pid] = self.draw_bar_plot(pid, title, motifs, counts)

plots.append("""
Plotly.newPlot('{cat}-motif-bar-{idx}', [{{
Plotly.newPlot('', [{{
type: 'bar',
y: {counts},
x: {motifs}
}}], {{
title: "{cat} motif distribution",
title: "",
font: {{size: 14}},
yaxis: {{
title: {{
Expand Down

0 comments on commit c5ea8f0

Please sign in to comment.