#! /usr/bin/env python
# -*- coding: utf-8 -*-
import xml.etree.ElementTree as ET
import os, sys, json, subprocess
import SELSLIB2
def __insert_plotly():
html = """
"""
return html
def __insert_css():
html = """
"""
return html
def __insert_sortable():
html = """
"""
return html
def __verification_graph(root):
html = """
Verification
"""
if root.find('VERIFICATION/message') is not None:
html += """
"""+root.find('VERIFICATION/message').text+"""
\n"""
if root.find('VERIFICATION') is not None:
cc = json.loads(root.find('VERIFICATION/CC').text)
wMPD = json.loads(root.find('VERIFICATION/wMPE').text)
incorrect = json.loads(root.find('VERIFICATION/incorrect').text)
html += """
"""
else:
html += "
⚠ Information is not yet available
"
html += """
"""
return html
def __insert_table_borges(root):
html = """
Search and expension
"""
fran = 1
aden_show = ""
aden_hide = ""
if root.find("ens1_frag" + str(fran) + "/FRF") is not None:
html += """\n"""
html += """
\n"""
if root.find("ens1_frag" + str(fran) + "/FTF") is not None:
clustftf = json.loads(root.find("ens1_frag" + str(fran) + "/FTF/allclus").text)
if key in clustftf and root.find("ens1_frag" + str(fran) + "/FTF/C" + keyd) is not None:
body_table_row += """
\n"""
if root.find("ens1_frag" + str(fran) + "/PACK") is not None:
clustpack = json.loads(root.find("ens1_frag" + str(fran) + "/PACK/allclus").text)
if key in clustpack and root.find("ens1_frag" + str(fran) + "/PACK/C" + keyd) is not None:
body_table_row += """
\n"""
if root.find("ens1_frag" + str(fran) + "/RNP") is not None:
clustrnp = json.loads(root.find("ens1_frag" + str(fran) + "/RNP/allclus").text)
if key in clustrnp and root.find("ens1_frag" + str(fran) + "/RNP/C" + keyd) is not None:
body_table_row += """
\n"""
if root.find("ens1_frag" + str(fran) + "/INITCC") is not None:
clustinitcc = json.loads(
root.find("ens1_frag" + str(fran) + "/INITCC/allclus").text)
if key in clustinitcc and root.find("ens1_frag" + str(
fran) + "/INITCC/BEFORE/C" + keyd) is not None:
body_table_row += """
\n"""
if root.find("ens1_frag" + str(fran) + "/FTF") is not None:
clustftf = json.loads(root.find("ens1_frag" + str(fran) + "/FTF/allclus").text)
if key in clustftf:
body_table_row += """
\n"""
if root.find("ens1_frag" + str(fran) + "/PACK") is not None:
clustpack = json.loads(root.find("ens1_frag" + str(fran) + "/PACK/allclus").text)
if key in clustpack:
body_table_row += """
\n"""
if root.find("ens1_frag" + str(fran) + "/RNP") is not None:
clustrnp = json.loads(root.find("ens1_frag" + str(fran) + "/RNP/allclus").text)
if key in clustrnp:
body_table_row += """
"
return html
def __insert_aside_lite(coiled_coil):
html = """
"""
return html
def __insert_aside_borges():
html = """
"""
return html
def __insert_aside_shredder():
html = """
"""
return html
def __insert_header():
html = """
Arcimboldo"""
html += __insert_plotly()
html += __insert_css()
html += __insert_sortable()
html += """"""
return html
def __insert_summary(root, nameOutput, coiled_coil=False):
html = """
\n"""
if root.find('LINKS') is not None:
numblinks = int(root.find('LINKS/number').text)
# print "===============NUBER OF LINKS=============",numblinks
for qds in range(numblinks):
# print root.find('LINKS/N'+str(qds))
if root.find('LINKS/N' + str(qds)) is not None:
text_link = root.find('LINKS/N' + str(qds) + '/text').text
text_link = text_link.strip('Click here')
text_link = text_link.strip(':')
url_link = root.find('LINKS/N' + str(qds) + '/url').text
#html += """
"""+text_link+"""
"""
html += """
Click here """+text_link
if root.find('backtracing/EXP/finalcc') is not None:
if float(root.find('backtracing/EXP/finalcc').text) >= 30:
if not coiled_coil:
html += """
It seems you have a good solution! Here you can find the best solution and map for further refinement.
\n"""
else:
html += """
Here you can find the best solution and map for further refinement.
\n"""
SELSLIB2.SOLVED = True
html += """
"""
return html
def __backtracking_lite(root):
html = """
Backtracking
"""
if root.find('backtracing') is not None:
html += "
The current best solution is: " + str(
root.find('backtracing/model').text) + " with FINALCC: " + str(
root.find('backtracing/finalcc').text) + " and n. residues traced " + str(
root.find('backtracing/restraced').text) + " file is: " + str(
root.find('backtracing/file').text) + "
\n"
# FRF
if root.find('backtracing/FRF') is not None:
html += """
\n"""
# INITCC
if root.find('backtracing/INITCC') is not None:
html += """\n
INITIAL CC
\n"""
html += """
\n"""
html += """
After Refinement: Pos. in Rank: """ + str(
root.find('backtracing/INITCC/posRank').text) + """ INITCC: """ + str(
root.find('backtracing/INITCC/initcc').text) + """ Top INITCC in Cluster """ + str(
root.find('backtracing/INITCC/cluster').text) + """: """ + str(
root.find('backtracing/INITCC/top_initcc').text) + """
\n"""
html += """
\n"""
html += """\n
EXPANSION
\n"""
html += """
\n"""
# Cycle n:
if root.find('backtracing/EXP') is not None:
html += """
Cycle """ + str(root.find('backtracing/EXP/cycle').text) + """:\n"""
if float(root.find('backtracing/EXP/finalcc').text) < 30.0:
html += """
Final CC: """ + str(
root.find('backtracing/EXP/finalcc').text) + """% N. Residues Traced: """ + str(
root.find('backtracing/EXP/restraced').text) + """
\n"""
else:
html += """
Final CC: """ + str(
root.find('backtracing/EXP/finalcc').text) + """% N. Residues Traced: """ + str(
root.find('backtracing/EXP/restraced').text) + """
\n"""
html += """
\n"""
html += """
\n"""
if root.find('backtracing/EXP') is not None:
if float(root.find('backtracing/EXP/finalcc').text) >= 30:
if root.find('VERIFICATION/solved') is None or bool(root.find('VERIFICATION/solved').text):
if float(root.find('data/resolution').text) < 2.1:
html += """
It seems you have a good solution! Here you can find the best solution and map for further refinement.
\n"""
else:
html += """
Here you can find the best solution and map for further refinement.
\n"""
SELSLIB2.SOLVED = True
else:
html += "
⚠ Information is not yet available
"
html += """
"""
return html
def __rotation_clustering(root):
aden_show = ""
aden_hide = ""
html = """
Rotation clustering
"""
if root.find('rot_clustering') is not None:
full = json.loads(root.find('rot_clustering/full').text)
reduced = json.loads(root.find('rot_clustering/reduced').text)
full_graph = json.loads(root.find('rot_clustering/graphfull').text)
reduced_graph = json.loads(root.find('rot_clustering/graphreduced').text)
aden_show = ""
aden_hide = ""
for ldr in full:
nclu, way = ldr
aden_show += """ document.getElementById('FRF-""" + str(nclu) + """').style.display=""" + way + """;\n """
for ldr in reduced:
nclu, way = ldr
aden_hide += """ document.getElementById('FRF-""" + str(nclu) + """').style.display=""" + way + """;\n """
aden_show += """ document.getElementById('clusters_full').style.display = "";\n """
aden_show += """ document.getElementById('clusters_reduced').style.display = "none";\n """
aden_hide += """ document.getElementById('clusters_full').style.display = "none";\n """
aden_hide += """ document.getElementById('clusters_reduced').style.display = "";\n """
x_full = [i[0] for i in full_graph]
bar_full = [i[1] for i in full_graph]
line1_full = [i[3] for i in full_graph]
line2_full = [i[2] for i in full_graph]
x_reduced = [i[0] for i in reduced_graph]
bar_reduced = [i[1] for i in reduced_graph]
line1_reduced = [i[3] for i in reduced_graph]
line2_reduced = [i[2] for i in reduced_graph]
html += """
#Cluster
#Rotations
#Distinct Pdb
Top LLG
LLG Mean
Top Zscore
Zscore Mean
"""
brins = 0
green = json.loads(root.find('rot_clustering/green').text)
while 1:
berd = root.find('rot_clustering/FRF-' + str(brins))
if berd == None:
break
html += """
"""
if brins in green:
html += """
\n"""
else:
html += """
\n"""
html += """
""" + berd.find('cluster').text + """
""" + berd.find('rotations').text + """
""" + berd.find('distinct').text + """
""" + berd.find('top_llg').text + """
""" + berd.find('mean_llg').text + """
""" + berd.find('top_zscore').text + """
""" + berd.find('mean_zscore').text + """
"""
brins += 1
html += """
\n
\n
"""
else:
html += "
⚠ Information is not yet available
"
return html
def __backtracking_borges(root):
html = """
Backtracking
"""
html += ""
if root.find('backtracing') is not None:
html += "
The current best solution is: " + str(
root.find('backtracing/model').text) + " with FINALCC: " + str(
root.find('backtracing/finalcc').text) + " and n. residues traced " + str(
root.find('backtracing/restraced').text) + " file is: " + str(
root.find('backtracing/file').text) + "
\n"
# FRF
if root.find('backtracing/FRF') is not None:
html += """
\n"""
# INITCC
if root.find('backtracing/INITCC') is not None:
html += """\n
INITIAL CC
\n"""
html += """
\n"""
# BEFORE REF
if root.find('backtracing/INITCC/BEFORE') is not None:
html += """
Before Refinement: Pos. in Rank: """ + str(
root.find('backtracing/INITCC/BEFORE/posRank').text) + """ INITCC: """ + str(
root.find('backtracing/INITCC/BEFORE/initcc').text) + """ Top INITCC in Cluster """ + str(
root.find('backtracing/INITCC/BEFORE/cluster').text) + """: """ + str(
root.find('backtracing/INITCC/BEFORE/top_initcc').text) + """
\n"""
# AFTER REF
if root.find('backtracing/INITCC/AFTER') is not None:
html += """
After Refinement: Pos. in Rank: """ + str(
root.find('backtracing/INITCC/AFTER/posRank').text) + """ INITCC: """ + str(
root.find('backtracing/INITCC/AFTER/initcc').text) + """ Top INITCC in Cluster """ + str(
root.find('backtracing/INITCC/AFTER/cluster').text) + """: """ + str(
root.find('backtracing/INITCC/AFTER/top_initcc').text) + """
\n"""
html += """
\n"""
#EXP
if root.find('backtracing/EXP') is not None:
html += """\n
EXPANSION
\n"""
html += """
\n"""
# Cycle n:
html += """
Cycle """ + str(root.find('backtracing/EXP/cycle').text) + """:\n"""
if float(root.find('backtracing/EXP/finalcc').text) < 30.0:
html += """
Final CC: """ + str(
root.find('backtracing/EXP/finalcc').text) + """% N. Residues Traced: """ + str(
root.find('backtracing/EXP/restraced').text) + """
\n"""
else:
html += """
Final CC: """ + str(
root.find('backtracing/EXP/finalcc').text) + """% N. Residues Traced: """ + str(
root.find('backtracing/EXP/restraced').text) + """
\n"""
html += """
\n"""
html += """
\n"""
if root.find('backtracing/EXP') is not None:
if float(root.find('backtracing/EXP/finalcc').text) >= 30:
html += """
It seems you have a good solution! Here you can find the best solution and map for further refinement.
\n"""
SELSLIB2.SOLVED = True
else:
html += "
⚠ Information is not yet available
"
html += "
"
return html
def __insert_setup_log(root):
setup_name = root.find('configuration/bor_name').text
setup_path = root.find('configuration/bor_text').text
working_dir = os.path.dirname(setup_name)
html = """
Instruction file
"""
if os.path.isfile(setup_name):
html +="""
Input file at """+setup_name+""". Click here to download it
"""
html += """
"""+setup_path+"""
"""
log_path = setup_name.replace(os.path.basename(setup_name), "log.out")
if not os.path.isfile(log_path):
log_path = os.path.dirname(setup_name) + ".log"
html += """
Log file
"""
log_content = ""
if os.path.isfile(log_path):
html += """
Log file at """+log_path+""". Click here to download it
"""
with open(log_path, 'r') as infile:
log_content = [line for line in infile][:100]
f = subprocess.Popen(['tail','-100',log_path],\
stdout=subprocess.PIPE,stderr=subprocess.PIPE)
log_content += f.stdout.readlines()
log_content = ''.join(map(str, log_content)).decode('ascii', 'ignore').replace("<","<")
else:
log_content = "Log file has not been found."
timestamp = ""
listatime = root.find('TIME')
if listatime is not None:
timestamp += "Timestamp information\n"
timestamp += "\n"
listatime = json.loads(listatime.text)
for tim in listatime:
mode, step, ti = tim
timestamp += """Time MODE: """ + str(mode) + """ STEP: """ + str(step) + """ """ + str(ti) + """\n"""
timestamp += """\n"""
timestamp = ''.join(map(str, timestamp))
else:
timestamp += "Timestamp information has not been found."
html +="""
"""+log_content+timestamp+"""
"""
return html
def __insert_citation_lite():
html = """
Citations
Phaser crystallographic software.
McCoy, A. J., Grosse-Kunstleve, R. W., Adams, P. D., Winn, M. D., Storoni, L. C. & Read, R. J.
(2007) J Appl Cryst. 40, 658-674.
"""
return html
def __insert_citation_coil():
html = """
Citations
Phaser crystallographic software.
McCoy, A. J., Grosse-Kunstleve, R. W., Adams, P. D., Winn, M. D., Storoni, L. C. & Read, R. J.
(2007) J Appl Cryst. 40, 658-674.
ARCIMBOLDO on coiled coils.
Caballero, I., Sammito, M., Millan, C., Lebedev, A., Soler, N., & Uson, I.
(2018) Acta Cryst. D74, 194-204.
"""
return html
def __insert_citation_borges():
html = """
Citations
Phaser crystallographic software.
McCoy, A. J., Grosse-Kunstleve, R. W., Adams, P. D., Winn, M. D., Storoni, L. C. & Read, R. J.
(2007) J Appl Cryst. 40, 658-674.
"""
return html
def __insert_citation_shredder():
html = """
Citations
Phaser crystallographic software.
McCoy, A. J., Grosse-Kunstleve, R. W., Adams, P. D., Winn, M. D., Storoni, L. C. & Read, R. J.
(2007) J Appl Cryst. 40, 658-674.
Exploiting distant homologues for phasing through the generation of compact fragments, local fold refinement and partial solution combination.
Millan, C., Sammito, M., McCoy, A. J., Nascimento, A.F.Z., Petrillo, G., Oeffner, R., Dominguez-Gil, Teresa., Hermoso, A., Read, R. J. & Uson I.
"""
return html
def generateHTML(lock, current_directory, nameOutput, coiled_coil=False):
#def generateHTML(current_directory, nameOutput, coiled_coil=False):
htmlfile = os.path.join(current_directory, nameOutput + ".html")
html = ""
if os.path.exists(htmlfile):
os.remove(htmlfile)
print "Generation HTML....."
lock.acquire()
xmlfile = os.path.join(current_directory, nameOutput + ".xml")
htmlfile = os.path.join(current_directory, nameOutput + ".html")
if not os.path.exists(xmlfile):
lock.release()
return
tree = ET.parse(xmlfile)
root = tree.getroot()
coiled_coil = coiled_coil or root.find('VERIFICATION') is not None
html += __insert_header()
html += """"""
if root.tag == "arcimboldo" and root.find('LINKS') is None:
html += """
ARCIMBOLDO
\n"""
html += """"""
html += __insert_aside_lite(coiled_coil)
html += """"""
html += """
ARCIMBOLDO-LITE: Fragment search with PHASER and density modification and map interpretation with SHELXE
"""
html += __insert_summary(root, nameOutput, coiled_coil)
html += __insert_table_lite(root)
html += __backtracking_lite(root)
if coiled_coil is not False:
html += __verification_graph(root)
html += __insert_setup_log(root)
if coiled_coil is not False:
html += __insert_citation_coil()
else:
html += __insert_citation_lite()
elif root.tag == "borges-arcimboldo":
html += """
ARCIMBOLDO-BORGES
\n"""
html += """"""
html += __insert_aside_borges()
html += """"""
html += """
ARCIMBOLDO-BORGES: Library search with PHASER and density modification and map interpretation with SHELXE
"""
html += __insert_summary(root, nameOutput, coiled_coil)
html += __rotation_clustering(root)
html += __insert_table_borges(root)
html += __backtracking_borges(root)
html += __insert_setup_log(root)
html += __insert_citation_borges()
else:
html += """
ARCIMBOLDO-SHREDDER
\n"""
html += """"""
html += __insert_aside_shredder()
html += """"""
html += __insert_summary(root, nameOutput, coiled_coil)
html += __insert_setup_log(root)
html += __insert_citation_shredder()
html += __insert_support()
html +="""
"""
f = open(htmlfile, "w")
f.write(html)
f.close()
lock.release()
print "release the lock HTML!!!"
#if __name__ == "__main__":
# generateHTML("/cri4/pep/Documents/output_test","shredder")