Skip to content

Commit

Permalink
revert to load_module for parsing af flags
Browse files Browse the repository at this point in the history
  • Loading branch information
DimaMolod committed Nov 13, 2023
1 parent 69bf6fa commit c6c9bef
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
5 changes: 2 additions & 3 deletions alphapulldown/create_individual_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
# This script is just to create msa and structural features for each sequences and store them in pickle
# #

from alphafold import run_alphafold as run_af
from alphapulldown.objects import MonomericObject
from alphafold.data.pipeline import DataPipeline
from alphafold.data.tools import hmmsearch
from alphafold.data import templates
from absl import logging, app
from alphapulldown.utils import save_meta_data, create_uniprot_runner, parse_fasta
from alphapulldown.utils import save_meta_data, create_uniprot_runner, parse_fasta, get_flags_from_af
import contextlib
from datetime import datetime
from pathlib import Path
Expand All @@ -25,7 +24,7 @@ def output_meta_file(file_path):
with open(file_path, "w") as outfile:
yield outfile.name

flags = run_af.flags
flags = get_flags_from_af()
flags.DEFINE_bool("save_msa_files", False, "save msa output or not")
flags.DEFINE_bool(
"skip_existing", False, "skip existing monomer feature pickles or not"
Expand Down
5 changes: 2 additions & 3 deletions alphapulldown/create_individual_features_with_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
# create_individual_features using custom multimeric templates
#

from alphafold import run_alphafold as run_af
from alphapulldown.objects import MonomericObject
from alphapulldown.utils import create_uniprot_runner
from alphapulldown.utils import create_uniprot_runner, get_flags_from_af
from alphapulldown.create_custom_template_db import create_db
from alphafold.data.pipeline import DataPipeline
from alphafold.data.tools import hmmsearch
Expand All @@ -19,7 +18,7 @@
from create_individual_features import create_and_save_monomer_objects, iter_seqs


flags = run_af.flags
flags = get_flags_from_af()

flags.DEFINE_integer("job_index", None, "index of job in the description file, starting from 1")

Expand Down
21 changes: 21 additions & 0 deletions alphapulldown/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import pickle
import logging
from alphapulldown.plot_pae import plot_pae
import alphafold
from alphafold.model import config
from alphafold.model import model
from alphafold.model import data
Expand All @@ -26,6 +27,7 @@
import re
import hashlib
import glob
import importlib

COMMON_PATTERNS = [
r"[Vv]ersion\s*(\d+\.\d+(?:\.\d+)?)", # version 1.0 or version 1.0.0
Expand All @@ -48,6 +50,25 @@
'ColabFold' : ["https://wwwuser.gwdg.de/~compbiol/colabfold/colabfold_envdb_202108.tar.gz"],
}

def get_flags_from_af():
"""
A function to load flags from alphafold imported as a module
"""
def load_module(file_name, module_name):
spec = importlib.util.spec_from_file_location(module_name, file_name)
module = importlib.util.module_from_spec(spec)
sys.modules[module_name] = module
spec.loader.exec_module(module)
return module
PATH_TO_RUN_ALPHAFOLD = os.path.join(os.path.dirname(alphafold.__file__), "run_alphafold.py")
try:
run_af = load_module(PATH_TO_RUN_ALPHAFOLD, "run_alphafold")
return run_af.flags
except FileNotFoundError:
PATH_TO_RUN_ALPHAFOLD = os.path.join(os.path.dirname(os.path.dirname(alphafold.__file__)), "run_alphafold.py")
run_af = load_module(PATH_TO_RUN_ALPHAFOLD, "run_alphafold")
return run_af.flags


def create_uniprot_runner(jackhmmer_binary_path, uniprot_database_path):
"""create a uniprot runner object"""
Expand Down

0 comments on commit c6c9bef

Please sign in to comment.