-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
223 changed files
with
62,871 additions
and
1,073 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#!/usr/bin/env python | ||
|
||
import csv | ||
import os | ||
import shutil | ||
|
||
from absl import flags | ||
from absl import app | ||
|
||
|
||
FLAGS = flags.FLAGS | ||
|
||
flags.DEFINE_string( | ||
'input_file', None, | ||
'Path to input ranking file.') | ||
|
||
flags.DEFINE_string( | ||
'output_file', None, | ||
'Path to the output the ordered ranking file.') | ||
|
||
flags.DEFINE_string( | ||
'cif_dir', None, | ||
'Path where to copy the cif files.') | ||
|
||
def order_ranking_scores_af3(ranking_scores): | ||
with open(ranking_scores, 'r') as csv_file: | ||
csv_reader = csv.DictReader(csv_file) # Use DictReader to work with named columns | ||
# Sort rows by 'ranking_score' in descending order | ||
sorted_rows = sorted(csv_reader, key=lambda row: float(row['ranking_score']), reverse=True) | ||
rank = 0 | ||
for row in sorted_rows: | ||
row['model'] = f"seed-{row['seed']}_sample-{row['sample']}" | ||
row['rank'] = rank | ||
rank = rank + 1 | ||
|
||
return sorted_rows | ||
|
||
def write_order_ranking_scores_af3(ordered_ranking_scores, ordered_ranking_scores_file): | ||
new_column_order = ['rank', 'model', 'seed', 'sample', 'ranking_score'] | ||
with open(ordered_ranking_scores_file, mode='w', newline='', encoding='utf-8') as outfile: | ||
# Create a DictWriter object with tab as the delimiter | ||
writer = csv.DictWriter(outfile, fieldnames=new_column_order, delimiter='\t') | ||
|
||
# Write the header row to the output file | ||
writer.writeheader() | ||
|
||
# Write rows from the DictReader to the output file | ||
for row in ordered_ranking_scores: | ||
writer.writerow({key: row[key] for key in new_column_order}) | ||
|
||
|
||
def main(argv): | ||
""" | ||
These functions are a combination of MassiveFold's team work and the following scripts from ColabFold repository and DeepMind colab notebook: | ||
https://github.com/sokrypton/ColabFold/blob/main/colabfold/plot.py | ||
https://github.com/sokrypton/ColabFold/blob/main/colabfold/colabfold.py | ||
https://colab.research.google.com/github/deepmind/alphafold/blob/main/notebooks/AlphaFold.ipynb | ||
Here are some basic commands: | ||
python MF_plots.py --input_path ./jobname --chosen_plots coverage,CF_PAEs | ||
-> regardless of the plot type, plot alignment coverage and group PAE for top 10 predictions | ||
""" | ||
FLAGS.input_file = os.path.realpath(FLAGS.input_file) | ||
FLAGS.output_file = os.path.realpath(FLAGS.output_file) | ||
FLAGS.cif_dir = os.path.realpath(FLAGS.cif_dir) | ||
|
||
sorted_scores = order_ranking_scores_af3(FLAGS.input_file) | ||
write_order_ranking_scores_af3(sorted_scores, FLAGS.output_file) | ||
|
||
for row in sorted_scores: | ||
cif_src = f"{os.path.dirname(FLAGS.input_file)}/{row['model']}/model.cif" | ||
cif_dest = f"{FLAGS.cif_dir}/ranked_{row['rank']}.cif" | ||
shutil.copy(cif_src, cif_dest) | ||
|
||
|
||
if __name__ == "__main__": | ||
app.run(main) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#! /usr/bin/env python | ||
|
||
""" Check the format of the json required by AlphaFold3 """ | ||
import json | ||
import re | ||
from absl import app, flags | ||
|
||
FLAGS = flags.FLAGS | ||
|
||
flags.DEFINE_string('json', None, 'Path to the JSON file') | ||
|
||
flags.mark_flag_as_required('json') | ||
|
||
|
||
""" | ||
This functions checks: | ||
- the file exists | ||
- it has the extension .json | ||
- the json is correctly formatted | ||
- the file name contains only allowd characters | ||
""" | ||
def is_valid_file(file_path): | ||
|
||
try: | ||
with open(file_path, 'r') as file: | ||
data = json.load(file) | ||
file_basename=file.name.split('/')[-1] | ||
except json.JSONDecodeError: | ||
print("ERROR: JSON file is not correctly formatted.") | ||
exit(1) | ||
except FileNotFoundError: | ||
print("ERROR: File not found.") | ||
exit(1) | ||
|
||
|
||
# Check if the file has a .json extension | ||
if file_basename.endswith('.json'): | ||
print("OK: The file has a .json extension.") | ||
else: | ||
print("ERROR: The file does not have a .json extension.") | ||
exit(1) | ||
|
||
# Define the allowed characters | ||
allowed_chars = re.compile(r'^[a-zA-Z0-9_.-]+$') | ||
|
||
# Find all invalid characters | ||
invalid_chars = re.findall(r'[^a-zA-Z0-9_.-]', file_basename) | ||
|
||
if invalid_chars: | ||
print(f"ERROR: Invalid characters found: \"{', '.join(invalid_chars)}\"") | ||
exit(1) | ||
else: | ||
return [data, file_basename] | ||
|
||
""" | ||
This functions checks: | ||
- the field name value corresponds to the filename without the extension | ||
- it sets the name value properly or add it if missing | ||
""" | ||
def check_and_update_json(data, file_basename): | ||
|
||
new_name = file_basename.rsplit('.',1)[0] | ||
if 'name' not in data: | ||
print("ERROR: 'name' field is missing in the JSON file.") | ||
exit(1) | ||
else: | ||
if data['name'] != new_name: | ||
print(f"ERROR: The content of the 'name' field in the JSON file must be set to '{new_name}' which is the name of the JSON file without its extension.") | ||
exit(1) | ||
|
||
|
||
def main(argv): | ||
del argv # Unused. | ||
[data, file_basename] = is_valid_file(FLAGS.json) | ||
check_and_update_json(data, file_basename) | ||
|
||
if __name__ == "__main__": | ||
app.run(main) | ||
|
Oops, something went wrong.