Skip to content

Commit

Permalink
try to fix compare output yet again
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Palmer committed Apr 11, 2023
1 parent 4d00d4e commit 137bcf9
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 39 deletions.
85 changes: 50 additions & 35 deletions funannotate/compare.py
Expand Up @@ -1519,19 +1519,15 @@ def addlink(x):
baseurl = "http://eggnog5.embl.de/"
elif x.startswith("ENOG41"):
baseurl = "http://eggnog45.embl.de/"
x = '<a target="_blank" href="{}#/app/results?target_nogs={}>{}</a>'.format(
baseurl, x, x
)
else:
return "None found"
x = f'<a target="_blank" href="{baseurl}#/app/results?target_nogs={x}">{x}</a>'
return x

def addlink2(x):
x = (
'<a target="_blank" href="http://www.orthodb.org/?level=&species=&query='
+ x
+ '">'
+ x
+ "</a>"
)
if x == "None":
return "None found"
x = f'<a target="_blank" href="http://www.orthodb.org/?level=&species=&query={x}">{x}</a>'
return x

# building remaining HTML output
Expand All @@ -1540,35 +1536,39 @@ def addlink2(x):
df = pd.read_csv(orthologs, sep="\t", header=None)
orthtable = []
for row in df.itertuples():
# eggnog results for table
if isinstance(row[3], str):
if ", " in row[3]:
t = row[3].split(", ") # convert Eggnog to list
if row[3] == "None":
value = "None found"
else:
t = [row[3]]
else:
t = ["None"]
if t[0] == "None":
t = ["None"]
if ", " in row[3]:
t = row[3].split(", ") # convert Eggnog to list
else:
t = [row[3]]
t = [addlink(y) for y in t]
t = [x for x in t if x not in ["None", None, ""]]
if len(t) > 0:
value = "; ".join(t)
else:
value = "None found"
else:
t = [addlink(y) for y in t]
try:
value = "; ".join(t)
except TypeError:
value = "None found"
# busco results for table
if isinstance(row[4], str):
if ", " in row[4]:
r = row[4].split(", ") # convert BUSCO to list
if row[4] == "None":
value2 = "None found"
else:
r = [row[4]]
else:
r = ["None"]
if r[0] == "None":
r = ["None"]
if ", " in row[4]:
r = row[4].split(", ") # convert BUSCO to list
else:
r = [row[4]]
r = [x for x in r if x not in ["None", None, ""]]
r = [addlink2(y) for y in r]
if len(r) > 0:
value2 = "; ".join(r)
else:
value2 = "None found"
else:
r = [addlink2(y) for y in r]
try:
value2 = "; ".join(r)
except TypeError:
value2 = "None found"
final = [row[0], row[1], row[2], value, value2, row[5]]
orthtable.append(final)
Expand All @@ -1586,11 +1586,10 @@ def addlink2(x):
pd.set_option("display.max_colwidth", None)
except ValueError:
pd.set_option("display.max_colwidth", 0)
html_table = df2html(df2)
output.write(lib.HEADER)
output.write(lib.ORTHOLOGS)
output.write(
df2.to_html(index=False, escape=False, classes="table table-hover")
)
output.write(html_table)
output.write(lib.FOOTER)

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


def df2html(df):
# for some effing reason pandas isn't doing this properly
html = '<table id="table" class="table table-bordered table-responsive m-3" style="width:80%; !important;font-sze:10pt;">'
html += '<thead class="table-dark"><tr>'
for x in df.columns.values.tolist():
html += f"<th>{x}</th>"
html += "</tr></thead><tbody>"
for row in df.itertuples(index=False):
html += "<tr>"
for i in range(len(row)):
html += f"<td>{row[i]}</td>"
html += "</tr>"
html += "</tbody></table>"
return html


if __name__ == "__main__":
main(sys.argv[1:])
15 changes: 11 additions & 4 deletions funannotate/library.py
Expand Up @@ -11360,6 +11360,8 @@ def getBlastDBinfo(input):
<!-- Custom styles for this template -->
<link href="css/starter-template.css" rel="stylesheet">
<script src="js/ie-emulation-modes-warning.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/t/bs/dt-1.10.11/datatables.min.css"/>
<script type="text/javascript" src="https://cdn.datatables.net/t/bs/dt-1.10.11/datatables.min.js"></script>
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
Expand Down Expand Up @@ -11391,10 +11393,8 @@ def getBlastDBinfo(input):
</nav>
"""
ORTHOLOGS = """
<div class="container">
<div class="table">
<h2 class="sub-header">Orthologous protein groups</h2>
<div class="table-responsive">
<div class="container-fluid">
<h2 class="sub-header">Orthologous protein groups</h2>
"""
INDEX = """
<div class="container">
Expand Down Expand Up @@ -11535,6 +11535,13 @@ def getBlastDBinfo(input):
<script src="js/bootstrap.min.js"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="js/ie10-viewport-bug-workaround.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#table').DataTable({
"paging": false
});
});
</script>
</body>
</html>
Expand Down

0 comments on commit 137bcf9

Please sign in to comment.