Skip to content

Commit

Permalink
Minor bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kiwijuice56 committed Jan 17, 2024
1 parent 64c9391 commit 291191a
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 8 deletions.
File renamed without changes.
1 change: 1 addition & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<head>
<title>protein-visualizer</title>
<link rel="stylesheet" href="styles.css">
<link rel="icon" href="favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
Expand Down
Binary file added img/icon.ico
Binary file not shown.
File renamed without changes
10 changes: 7 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@
from ctypes import windll


print("protein-visualizer version 0.0, documentation: https://kiwijuice56.github.io/protein-visualizer/")
print("-" * 8)
print("Select a .pdb file to render.")

# Fix screen resolution
windll.shcore.SetProcessDpiAwareness(1)

root = tk.Tk()
root.iconbitmap("icon.ico")
root.iconbitmap("img/icon.ico")
root.withdraw()

# Initialize protein
Expand All @@ -25,8 +29,8 @@
# Initialize window
window = pyglet.window.Window(resizable=True)
window.set_caption("protein-visualizer")
icon_ico = pyglet.image.load("icon.ico")
icon_png = pyglet.image.load("icon.png")
icon_ico = pyglet.image.load("img/icon.ico")
icon_png = pyglet.image.load("img/icon.png")
window.set_icon(icon_ico, icon_png)

root.destroy()
Expand Down
16 changes: 11 additions & 5 deletions protein.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,11 @@ def __init__(self, pdb_path, chain_id=None, color_mode=CLUSTER_INDEX, color_pale
self.color_mode = color_mode
self.color_palette = color_palette

warnings.filterwarnings("ignore")

print("Loading protein structure.")

# Get the full 3D structure from the PDB file
warnings.filterwarnings("ignore", "'HEADER' line not found; can't determine PDB ID.")
bio_structure = Bio.PDB.PDBParser(QUIET=True).get_structure("struct", pdb_path)

# Choose default chain if none specified
Expand All @@ -87,6 +90,8 @@ def __init__(self, pdb_path, chain_id=None, color_mode=CLUSTER_INDEX, color_pale
f"Chain with ID '{chain_id}' could not be found within .pdb file."
f"Available chains: {[chain.get_id() for chain in chains]}.")

print(f"Rendering chain with ID '{chain_id}' from {[chain.get_id() for chain in chains]}")

# There are two methods of attaining an amino acid sequence from a PDB file: `atom` and `seqres`
# `atom` calculates the sequence from the available residues found in the 3D space
# `seqres` retrieves the sequence from the PDB file metadata
Expand All @@ -101,8 +106,7 @@ def __init__(self, pdb_path, chain_id=None, color_mode=CLUSTER_INDEX, color_pale
if other_record.annotations["chain"] == chain_id:
full_record = other_record
if full_record is None:
warnings.warn("Could not read SEQRES information; Continuing with sequence as determined from the 3D "
"structure.", stacklevel=2)
print("Could not read SEQRES info; Continuing with sequence as determined from the 3D structure.")
full_record = physical_record

prot_name = "".join(x for x in full_record.name if x.isalnum())
Expand Down Expand Up @@ -135,11 +139,11 @@ def __init__(self, pdb_path, chain_id=None, color_mode=CLUSTER_INDEX, color_pale

# Calculate embeddings with ProSE
if not os.path.isfile(f"data/{prot_name}_{chain_id}_embeddings.h5"):
print("Embeddings not found in `data` directory. Generating new embeddings.")
print("Embeddings not found in 'data' directory. Generating new embeddings.")
subprocess.call(["python", "prose/embed_sequences.py", '-o', f"data/{prot_name}_{chain_id}_embeddings.h5",
f"data/{prot_name}_{chain_id}.fa"], shell=True)
else:
print("Embeddings from previous session found in `data` directory.")
print("Embeddings from previous session found in 'data' directory.")

# Parse the embeddings file for the residues we will render
embedding_file = h5py.File(f"data/{prot_name}_{chain_id}_embeddings.h5", 'r')
Expand All @@ -148,6 +152,8 @@ def __init__(self, pdb_path, chain_id=None, color_mode=CLUSTER_INDEX, color_pale
for residue in self.residues:
realized_embeddings.append(embeddings[residue.seq_index - seq_index_offset])

print("Calculating 2D projection and clusters.")

# Use the t-SNE algorithm to transform the embeddings into 2D vectors
transform = TSNE(n_components=2, perplexity=3).fit_transform(np.array(realized_embeddings))
self.embedding_points = transform.flatten()
Expand Down

0 comments on commit 291191a

Please sign in to comment.