Skip to content

Commit 137bcf9

Browse files
author
Jon Palmer
committed
try to fix compare output yet again
1 parent 4d00d4e commit 137bcf9

File tree

2 files changed

+61
-39
lines changed

2 files changed

+61
-39
lines changed

funannotate/compare.py

+50-35
Original file line numberDiff line numberDiff line change
@@ -1519,19 +1519,15 @@ def addlink(x):
15191519
baseurl = "http://eggnog5.embl.de/"
15201520
elif x.startswith("ENOG41"):
15211521
baseurl = "http://eggnog45.embl.de/"
1522-
x = '<a target="_blank" href="{}#/app/results?target_nogs={}>{}</a>'.format(
1523-
baseurl, x, x
1524-
)
1522+
else:
1523+
return "None found"
1524+
x = f'<a target="_blank" href="{baseurl}#/app/results?target_nogs={x}">{x}</a>'
15251525
return x
15261526

15271527
def addlink2(x):
1528-
x = (
1529-
'<a target="_blank" href="http://www.orthodb.org/?level=&species=&query='
1530-
+ x
1531-
+ '">'
1532-
+ x
1533-
+ "</a>"
1534-
)
1528+
if x == "None":
1529+
return "None found"
1530+
x = f'<a target="_blank" href="http://www.orthodb.org/?level=&species=&query={x}">{x}</a>'
15351531
return x
15361532

15371533
# building remaining HTML output
@@ -1540,35 +1536,39 @@ def addlink2(x):
15401536
df = pd.read_csv(orthologs, sep="\t", header=None)
15411537
orthtable = []
15421538
for row in df.itertuples():
1539+
# eggnog results for table
15431540
if isinstance(row[3], str):
1544-
if ", " in row[3]:
1545-
t = row[3].split(", ") # convert Eggnog to list
1541+
if row[3] == "None":
1542+
value = "None found"
15461543
else:
1547-
t = [row[3]]
1548-
else:
1549-
t = ["None"]
1550-
if t[0] == "None":
1551-
t = ["None"]
1544+
if ", " in row[3]:
1545+
t = row[3].split(", ") # convert Eggnog to list
1546+
else:
1547+
t = [row[3]]
1548+
t = [addlink(y) for y in t]
1549+
t = [x for x in t if x not in ["None", None, ""]]
1550+
if len(t) > 0:
1551+
value = "; ".join(t)
1552+
else:
1553+
value = "None found"
15521554
else:
1553-
t = [addlink(y) for y in t]
1554-
try:
1555-
value = "; ".join(t)
1556-
except TypeError:
15571555
value = "None found"
1556+
# busco results for table
15581557
if isinstance(row[4], str):
1559-
if ", " in row[4]:
1560-
r = row[4].split(", ") # convert BUSCO to list
1558+
if row[4] == "None":
1559+
value2 = "None found"
15611560
else:
1562-
r = [row[4]]
1563-
else:
1564-
r = ["None"]
1565-
if r[0] == "None":
1566-
r = ["None"]
1561+
if ", " in row[4]:
1562+
r = row[4].split(", ") # convert BUSCO to list
1563+
else:
1564+
r = [row[4]]
1565+
r = [x for x in r if x not in ["None", None, ""]]
1566+
r = [addlink2(y) for y in r]
1567+
if len(r) > 0:
1568+
value2 = "; ".join(r)
1569+
else:
1570+
value2 = "None found"
15671571
else:
1568-
r = [addlink2(y) for y in r]
1569-
try:
1570-
value2 = "; ".join(r)
1571-
except TypeError:
15721572
value2 = "None found"
15731573
final = [row[0], row[1], row[2], value, value2, row[5]]
15741574
orthtable.append(final)
@@ -1586,11 +1586,10 @@ def addlink2(x):
15861586
pd.set_option("display.max_colwidth", None)
15871587
except ValueError:
15881588
pd.set_option("display.max_colwidth", 0)
1589+
html_table = df2html(df2)
15891590
output.write(lib.HEADER)
15901591
output.write(lib.ORTHOLOGS)
1591-
output.write(
1592-
df2.to_html(index=False, escape=False, classes="table table-hover")
1593-
)
1592+
output.write(html_table)
15941593
output.write(lib.FOOTER)
15951594

15961595
else:
@@ -1643,5 +1642,21 @@ def addlink2(x):
16431642
lib.log.info("Funannotate compare completed successfully!")
16441643

16451644

1645+
def df2html(df):
1646+
# for some effing reason pandas isn't doing this properly
1647+
html = '<table id="table" class="table table-bordered table-responsive m-3" style="width:80%; !important;font-sze:10pt;">'
1648+
html += '<thead class="table-dark"><tr>'
1649+
for x in df.columns.values.tolist():
1650+
html += f"<th>{x}</th>"
1651+
html += "</tr></thead><tbody>"
1652+
for row in df.itertuples(index=False):
1653+
html += "<tr>"
1654+
for i in range(len(row)):
1655+
html += f"<td>{row[i]}</td>"
1656+
html += "</tr>"
1657+
html += "</tbody></table>"
1658+
return html
1659+
1660+
16461661
if __name__ == "__main__":
16471662
main(sys.argv[1:])

funannotate/library.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -11360,6 +11360,8 @@ def getBlastDBinfo(input):
1136011360
<!-- Custom styles for this template -->
1136111361
<link href="css/starter-template.css" rel="stylesheet">
1136211362
<script src="js/ie-emulation-modes-warning.js"></script>
11363+
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/t/bs/dt-1.10.11/datatables.min.css"/>
11364+
<script type="text/javascript" src="https://cdn.datatables.net/t/bs/dt-1.10.11/datatables.min.js"></script>
1136311365
</head>
1136411366
<body>
1136511367
<nav class="navbar navbar-inverse navbar-fixed-top">
@@ -11391,10 +11393,8 @@ def getBlastDBinfo(input):
1139111393
</nav>
1139211394
"""
1139311395
ORTHOLOGS = """
11394-
<div class="container">
11395-
<div class="table">
11396-
<h2 class="sub-header">Orthologous protein groups</h2>
11397-
<div class="table-responsive">
11396+
<div class="container-fluid">
11397+
<h2 class="sub-header">Orthologous protein groups</h2>
1139811398
"""
1139911399
INDEX = """
1140011400
<div class="container">
@@ -11535,6 +11535,13 @@ def getBlastDBinfo(input):
1153511535
<script src="js/bootstrap.min.js"></script>
1153611536
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
1153711537
<script src="js/ie10-viewport-bug-workaround.js"></script>
11538+
<script type="text/javascript">
11539+
$(document).ready(function() {
11540+
$('#table').DataTable({
11541+
"paging": false
11542+
});
11543+
});
11544+
</script>
1153811545
</body>
1153911546
</html>
1154011547

0 commit comments

Comments
 (0)