Skip to content

Commit

Permalink
feat: do everything with the foldseek folder
Browse files Browse the repository at this point in the history
  • Loading branch information
xnought committed Feb 1, 2024
1 parent b99c94d commit 67d03c8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
7 changes: 5 additions & 2 deletions backend/src/api/similar.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@
pdb_file_name,
revert_pdb_filename,
)
from ..foldseek import easy_search, create_db
from ..foldseek import easy_search, external_db

router = APIRouter()


PDB = external_db("PDB", "foldseek/dbs/pdb")


@router.get("/similar-pdb/{protein_name:str}", response_model=list[SimilarProtein])
def get_similar_pdb(protein_name: str):
global PDB
query_name = pdb_file_name(protein_name)
PDB = create_db("PDB", "pdb")
similar = easy_search(query_name, PDB, out_format="target,prob")
return [SimilarProtein(name=s[0].split(".")[0], prob=s[1]) for s in similar]

Expand Down
26 changes: 25 additions & 1 deletion backend/src/foldseek.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class GenerateDirName:
def __enter__(self):
global active_caches
active_caches += 1
self.temp_dir = ".foldseek_cache_" + str(active_caches)
self.temp_dir = "foldseek/temp_dir_" + str(active_caches)
return self.temp_dir

def __exit__(self, *args):
Expand Down Expand Up @@ -93,6 +93,30 @@ def easy_search(
return to_columnar_array(parsed_output) if columnar else parsed_output


def external_db(
external_db_name: str,
db_name: str,
foldseek_executable="foldseek/bin/foldseek",
print_stdout=False,
):
if external_db_name not in EXTERNAL_DATABASES:
raise Exception(f"Directory {external_db_name} not found")

with GenerateDirName() as temp_dir:
try:
bash_cmd(f"ls {db_name}")
except Exception:
if dir not in EXTERNAL_DATABASES:
cmd = f"{foldseek_executable} createdb {external_db_name} {db_name}"
else:
cmd = f"{foldseek_executable} databases {external_db_name} {db_name} {temp_dir}"
stdout = bash_cmd(cmd)
if print_stdout:
print(stdout)

return db_name


def create_db(
dir: str,
db_name: str,
Expand Down

0 comments on commit 67d03c8

Please sign in to comment.