Skip to content

Commit

Permalink
Merge pull request #184 from ziadbkh/reports
Browse files Browse the repository at this point in the history
model names in lower case
  • Loading branch information
JoseEspinosa authored Oct 4, 2024
2 parents 7789713 + 2048797 commit 0d4f92c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
36 changes: 23 additions & 13 deletions bin/generate_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,12 @@ def pdb_to_lddt(pdb_files, generate_tsv):
print("Starting...")

version = "1.0.0"
model_name = {
"esmfold": "ESMFold",
"alphafold2": "AlphaFold2",
"colabfold": "ColabFold",
}

parser = argparse.ArgumentParser()
parser.add_argument("--type", dest="in_type")
parser.add_argument(
Expand All @@ -294,7 +300,7 @@ def pdb_to_lddt(pdb_files, generate_tsv):
parser.add_argument("--html_template", dest="html_template")
parser.add_argument("--version", action="version", version=f"{version}")
parser.set_defaults(output_dir="")
parser.set_defaults(in_type="ESMFOLD")
parser.set_defaults(in_type="esmfold")
parser.set_defaults(name="")
args = parser.parse_args()

Expand All @@ -316,26 +322,28 @@ def pdb_to_lddt(pdb_files, generate_tsv):
io.save(ref_structure_path)
aligned_structures[0] = ref_structure_path

alphafold_template = open(args.html_template, "r").read()
alphafold_template = alphafold_template.replace("*sample_name*", args.name)
alphafold_template = alphafold_template.replace("*prog_name*", args.in_type)
proteinfold_template = open(args.html_template, "r").read()
proteinfold_template = proteinfold_template.replace("*sample_name*", args.name)
proteinfold_template = proteinfold_template.replace(
"*prog_name*", model_name[args.in_type.lower()]
)

args_pdb_array_js = ",\n".join([f'"{model}"' for model in structures])
alphafold_template = re.sub(
proteinfold_template = re.sub(
r"const MODELS = \[.*?\];", # Match the existing MODELS array in HTML template
f"const MODELS = [\n {args_pdb_array_js}\n];", # Replace with the new array
alphafold_template,
proteinfold_template,
flags=re.DOTALL,
)

averages_js_array = f"const LDDT_AVERAGES = {lddt_averages};"
alphafold_template = alphafold_template.replace(
proteinfold_template = proteinfold_template.replace(
"const LDDT_AVERAGES = [];", averages_js_array
)

i = 0
for structure in aligned_structures:
alphafold_template = alphafold_template.replace(
proteinfold_template = proteinfold_template.replace(
f"*_data_ranked_{i}.pdb*", open(structure, "r").read().replace("\n", "\\n")
)
i += 1
Expand All @@ -347,22 +355,24 @@ def pdb_to_lddt(pdb_files, generate_tsv):
else f"{args.output_dir}/{args.name + ('_' if args.name else '')}seq_coverage.png"
)
with open(image_path, "rb") as in_file:
alphafold_template = alphafold_template.replace(
proteinfold_template = proteinfold_template.replace(
"seq_coverage.png",
f"data:image/png;base64,{base64.b64encode(in_file.read()).decode('utf-8')}",
)
else:
pattern = r'<div id="seq_coverage_container".*?>.*?(<!--.*?-->.*?)*?</div>\s*</div>'
alphafold_template = re.sub(pattern, "", alphafold_template, flags=re.DOTALL)
proteinfold_template = re.sub(pattern, "", proteinfold_template, flags=re.DOTALL)

with open(
f"{args.output_dir}/{args.name + ('_' if args.name else '')}coverage_LDDT.html",
"r",
) as in_file:
lddt_html = in_file.read()
alphafold_template = alphafold_template.replace(
proteinfold_template = proteinfold_template.replace(
'<div id="lddt_placeholder"></div>', lddt_html
)

with open(f"{args.output_dir}/{args.name}_{args.in_type.lower()}_report.html", "w") as out_file:
out_file.write(alphafold_template)
with open(
f"{args.output_dir}/{args.name}_{args.in_type.lower()}_report.html", "w"
) as out_file:
out_file.write(proteinfold_template)
4 changes: 2 additions & 2 deletions main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ workflow NFCORE_PROTEINFOLD {
ch_multiqc = ALPHAFOLD2.out.multiqc_report
ch_versions = ch_versions.mix(ALPHAFOLD2.out.versions)
ch_report_input = ch_report_input.mix(
ALPHAFOLD2.out.pdb.join(ALPHAFOLD2.out.msa).map{it[0]["model"] = "ALPHAFOLD2"; it}
ALPHAFOLD2.out.pdb.join(ALPHAFOLD2.out.msa).map{it[0]["model"] = "alphafold2"; it}
)

}
Expand Down Expand Up @@ -191,7 +191,7 @@ workflow NFCORE_PROTEINFOLD {
ch_multiqc = ESMFOLD.out.multiqc_report
ch_versions = ch_versions.mix(ESMFOLD.out.versions)
ch_report_input = ch_report_input.mix(
ESMFOLD.out.pdb.combine(Channel.fromPath("$projectDir/assets/NO_FILE")).map{it[0]["model"] = "ESMFOLD"; it}
ESMFOLD.out.pdb.combine(Channel.fromPath("$projectDir/assets/NO_FILE")).map{it[0]["model"] = "esmfold"; it}
)
}
//
Expand Down

0 comments on commit 0d4f92c

Please sign in to comment.