Skip to content

Commit

Permalink
Merge pull request #106 from volkamerlab/more-fixes
Browse files Browse the repository at this point in the history
KLIFS: Drop remotely unavailable structures from local database
  • Loading branch information
dominiquesydow authored Sep 16, 2021
2 parents cdd450b + d8d6a6e commit 1f454e8
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions opencadd/databases/klifs/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from pathlib import Path

import pandas as pd
from bravado_core.exception import SwaggerMappingError

from . import remote
from .core import (
Expand Down Expand Up @@ -311,7 +312,7 @@ def _add_filepaths(klifs_metadata):

filepaths = []

for index, row in klifs_metadata.iterrows():
for _, row in klifs_metadata.iterrows():

# Depending on whether alternate model and chain ID is given build file path:
filepath = metadata_to_filepath(
Expand Down Expand Up @@ -354,16 +355,27 @@ def _add_klifs_ids(klifs_metadata):
klifs_metadata_with_ids["structure.klifs_id"].isna()
].iterrows():
# Get IDs from remote
structure = remote_structures.by_structure_pdb_id(
row["structure.pdb_id"],
row["structure.alternate_model"],
row["structure.chain"],
)
structure_klifs_id = structure["structure.klifs_id"][0]
kinase_klifs_id = structure["kinase.klifs_id"][0]
# Set IDs locally
klifs_metadata_with_ids.loc[index, "structure.klifs_id"] = structure_klifs_id
klifs_metadata_with_ids.loc[index, "kinase.klifs_id"] = kinase_klifs_id
try:
structure = remote_structures.by_structure_pdb_id(
row["structure.pdb_id"],
row["structure.alternate_model"],
row["structure.chain"],
)
structure_klifs_id = structure["structure.klifs_id"][0]
kinase_klifs_id = structure["kinase.klifs_id"][0]
# Set IDs locally
klifs_metadata_with_ids.loc[index, "structure.klifs_id"] = structure_klifs_id
klifs_metadata_with_ids.loc[index, "kinase.klifs_id"] = kinase_klifs_id
except SwaggerMappingError as e:
# If for some reason some structures are available locally but not remotely
# we will drop them!
_logger.error(
f"Local structure is not part of {KLIFS_CLIENT} (yet? any more?): "
f"{row['structure.pdb_id']}-"
f"{row['structure.alternate_model']}-"
f"{row['structure.chain']}"
)
_logger.error(e)
# Remove structures that have no KLIFS ID
klifs_metadata_with_ids.dropna(subset=["structure.klifs_id"], inplace=True)

Expand Down

0 comments on commit 1f454e8

Please sign in to comment.