-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
automatic official FASTA file fetching, several new utility functions related to structure including flexible 3d alignment that supports different length chains to be aligned! #101
Merged
Merged
Changes from all commits
Commits
Show all changes
147 commits
Select commit
Hold shift + click to select a range
7563e3e
adding deduplication and cluster generation generic tool
bef1c25
renamed few arguments
7140781
...
68647da
PR comments
3011c2c
printing key generating output files in cluster
8647a06
Merge branch 'main' of https://github.com/BiomedSciAI/fuse-drug into …
b3bcd11
static code checker fixes
1485738
reduced dependencies and did some cleanup
91a98fd
added visualizations utils for antibodies
f77178b
static code check fixes
a7bccd3
black mypy flake8 fixes
8db8791
dealing with large fasta files
2305539
returning a consistent amount of elements in tuple
8705282
when clustering with mmseqs2, now also outputting a FASTA file with t…
19bd0fe
moved all mmseqs DB to a workspace to avoid clutter
bed6a90
renamed
9a0b4a4
solved conflicts
bfe4ba5
better conflict merge
5da1694
added splitting based on cluster.tsv
9aeeeb2
better docstring
a3f6033
static checkers fixes
41546df
PR coments
56fafdd
balanced sampling and mmap lines reader
8579b30
...
50c3dc8
solved a flipped file creations in cluster_using_mmseqs and refactori…
63f1cb4
added proper caching of return answer from cluster
c31a5f1
solved conflict
075b4c8
splits and clusters
1fa7507
pdb clustering related and also adding requirements
cb01191
pdb prepare_data related
1ab88e3
Merge branch 'main' of https://github.com/BiomedSciAI/fuse-drug into …
e02c357
pdb prepare_data ddfb related
b10d033
static code checkers fixes
834e5bb
fixed cluster balancing code
4fc16d0
...
c1ddcd5
Merge branch 'main' of https://github.com/BiomedSciAI/fuse-drug into …
3601591
...
25f42cc
removing a dep
250b6b5
solving CUDA mismatch issue in unit tests
72049a4
...
ff315fc
solving CI/CD stuff
fd7a0a2
solving auto tests issues
4293c89
...
2d66c04
restored pytoda
ac9b1c7
Merge branch 'main' of https://github.com/BiomedSciAI/fuse-drug into …
771a7af
added a method to provide the max observed token ID in a fast tokenizer
1f95800
...
77ab96a
added another method to fast tokenizer, allowing to extract sentinal …
b530614
static code checkers
f660fbb
...
d69d6ce
unit tests
0d7cd36
...
a7cfb3c
solved conflicts
8b7b60d
...
d6588de
fixed a typo and added abnumber requirement
fd2468b
solved conflict
4ebc2b8
Merge branch 'main' of https://github.com/BiomedSciAI/fuse-drug into …
ec730fd
added pseudo beta loading
872f871
...
756f92b
...
b6a3f7c
adding ablang embedding extraction
5d96384
...
887c813
...
b5ad9f1
cleanup
c09b063
...
1292931
adding metrics for pairwise protein sequences comparison
68db74f
Merge branch 'main' of https://github.com/BiomedSciAI/fuse-drug into …
3921c50
Merge branch 'main' of https://github.com/BiomedSciAI/fuse-drug into …
500f371
added utility to get antibody regions
8be708c
Merge branch 'main' of https://github.com/BiomedSciAI/fuse-drug into …
f2c2abe
pairwise sequence metrics and added sapiens humanness score
f0aa9f2
static code
1edb7be
PR comments
5f08672
Merge branch 'main' of https://github.com/BiomedSciAI/fuse-drug into …
e49702e
drastic reduction of needed memory in indexed_fasta_custom hdf5 offse…
7ff1148
Merge branch 'yoels' of https://github.com/BiomedSciAI/fuse-drug into…
0d1fb4f
avoiding parsing mmcif twice, added more flexible pdb writing allowin…
5eaf047
solved conflicts
0f40b5d
...
e4a9ef3
added the function that stores trajectory into a single PDB file
aa5cded
Merge branch 'main' of https://github.com/BiomedSciAI/fuse-drug into …
ff9da56
adding a class for protein complex which will also handle negative pairs
b58641a
added flatten to protein_complex
78d0855
multimer spatial crop
b95be12
deprecated get_chain_native_features()
1d1adb1
Merge branch 'main' of https://github.com/BiomedSciAI/fuse-drug into …
8f47dff
...
f6813bf
multimer
0210eae
Merge branch 'yoels' of https://github.com/BiomedSciAI/fuse-drug into…
abc7477
multimer
1e83440
moving to tiny_openfold
af5847b
extracting residues types info, and information about presence of rna…
3e0010c
...
dfc12be
adding support in spatial crop for K>2 chains
624d176
basic spatial crop works
018cc53
spatial crop was tested on few cases and verified to work
480982b
...
7c97c6b
no spatial crop if already less than needed size
5f1f616
fallbacking to regular crop when there is no intersection
19352c1
added residue_index and chain_index
a6ab950
residue_index and chain_index were added twice
906372e
...
f44743b
fixed requirement and disallowed positional args in load_protein_stru…
c236bbc
fixing requirements
6bb199e
PR suggestions
1b16848
fixing requirements
f4cb0b6
Merge branch 'main' of https://github.com/BiomedSciAI/fuse-drug into …
c45514a
removed readlines()
15df396
Merge branch 'main' of https://github.com/BiomedSciAI/fuse-drug into …
e0f17a7
proper cores auto deduction
89d4f8e
Merge branch 'main' of https://github.com/BiomedSciAI/fuse-drug into …
b10492a
extended modulartokenizer to support local (per section) max length
63131e3
Merge branch 'main' of https://github.com/BiomedSciAI/fuse-drug into …
d3cfd36
PR fix
9db980e
Merge branch 'main' of https://github.com/BiomedSciAI/fuse-drug into …
33199b6
Merge branch 'main' of https://github.com/BiomedSciAI/fuse-drug into …
3f34a82
...
0d15e3d
Merge branch 'main' of https://github.com/BiomedSciAI/fuse-drug into …
d8b73cb
...
98996a4
...
c4d9c65
Merge branch 'main' of https://github.com/BiomedSciAI/fuse-drug into …
769b249
...
35fa988
advancing on flexible multi chain alignment
d808fca
flexible alignment
fcceb44
flexible structure alignment is working well!
2b8fdca
...
25600ab
...
fe6105e
Merge branch 'yoels' of https://github.com/BiomedSciAI/fuse-drug into…
7ddd58e
flexible align on multiple with table as input
e4b76bc
advanced on flexible align
00b17f5
Merge branch 'main' of https://github.com/BiomedSciAI/fuse-drug into …
e9f6140
Merge branch 'yoels' of https://github.com/BiomedSciAI/fuse-drug into…
ae667b6
flexible multiple align and also extracting and optionally renaming c…
1307305
...
8a280b3
supporting saving pdb when given atom37 pos as input
70d722d
Merge branch 'yoels' of https://github.com/BiomedSciAI/fuse-drug into…
fb0cfe1
Merge branch 'main' of https://github.com/BiomedSciAI/fuse-drug into …
6adcb61
Merge branch 'yoels' of https://github.com/BiomedSciAI/fuse-drug into…
72ca1f0
complex protein
7c22f43
Merge branch 'yoels' of https://github.com/BiomedSciAI/fuse-drug into…
a635acc
...
77f27ad
Merge branch 'yoels' of https://github.com/BiomedSciAI/fuse-drug into…
87e3ff5
Merge branch 'main' of https://github.com/BiomedSciAI/fuse-drug into …
34c865a
static code tests fixes
72b2328
fixed handling of bfactors - they are per atom, not per residue!
a0a6c02
Merge branch 'main' of https://github.com/BiomedSciAI/fuse-drug into …
43a9a34
PR comments
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from io import StringIO | ||
from Bio import SeqIO | ||
from urllib.request import urlopen | ||
from typing import Dict | ||
|
||
|
||
def get_fasta_from_rcsb(pdb_id: str) -> Dict: # TODO: consider adding caching | ||
""" | ||
Given some pdb_id, (like "7vux"), we will retrieve its fasta file from rcsb database and return it as a dict {chain: sequence}. | ||
""" | ||
fasta_data = ( | ||
urlopen(f"https://www.rcsb.org/fasta/entry/{pdb_id.upper()}") | ||
.read() | ||
.decode("utf-8") | ||
) | ||
fasta_file_handle = StringIO(fasta_data) | ||
chains_full_seq = SeqIO.to_dict( | ||
SeqIO.parse(fasta_file_handle, "fasta"), | ||
key_function=lambda rec: _description_to_author_chain_id(rec.description), | ||
) | ||
chains_full_seq = {k: str(d.seq) for (k, d) in chains_full_seq.items()} | ||
return chains_full_seq | ||
|
||
|
||
def _description_to_author_chain_id(description: str) -> str: | ||
loc = description.find(" ") | ||
assert loc >= 0 | ||
description = description[loc + 1 :] | ||
loc = description.find(",") | ||
if loc >= 0: | ||
description = description[:loc] | ||
|
||
token = "auth " | ||
loc = description.find(token) | ||
if loc >= 0: | ||
return description[loc + len(token)] | ||
|
||
return description[0] |
104 changes: 104 additions & 0 deletions
104
fusedrug/data/protein/structure/align_multiple_antibodies.py
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,104 @@ | ||
from os.path import join, dirname | ||
from fusedrug.data.protein.structure.flexible_align_chains_structure import ( | ||
flexible_align_chains_structure, | ||
) | ||
from jsonargparse import CLI | ||
import pandas as pd | ||
from typing import Optional | ||
import numpy as np | ||
|
||
|
||
def main( | ||
input_excel_filename: str, | ||
unique_id_column: str, | ||
reference_heavy_chain_pdb_filename_column: str, | ||
reference_heavy_chain_id_column: str, | ||
heavy_chain_pdb_filename_column: str, | ||
heavy_chain_id_column: str, | ||
light_chain_pdb_filename_column: str, | ||
light_chain_id_column: str, | ||
aligned_using_only_heavy_chain: bool = True, | ||
output_structure_file_prefix: str = "aligned_antibody_", | ||
output_excel_filename: Optional[str] = None, | ||
output_excel_aligned_heavy_chain_pdb_filename_column: str = "aligned_heavy_chain_pdb_filename", | ||
output_excel_aligned_heavy_chain_id_column: str = None, | ||
output_excel_aligned_light_chain_pdb_filename_column: str = "aligned_light_chain_pdb_filename", | ||
output_excel_aligned_light_chain_id_column: str = None, | ||
) -> pd.DataFrame: | ||
|
||
assert ( | ||
aligned_using_only_heavy_chain | ||
), "only supporting aligned_using_only_heavy_chain=True for now. Note that flexible_align_chains_structure is indeed flexible enough to support this, if needed." | ||
|
||
df = pd.read_excel(input_excel_filename, index_col=unique_id_column) | ||
|
||
# base = '/dccstor/dsa-ab-cli-val-0/2024_feb_delivery/top_100_with_indels/antibody_dimers_af2_predicted_structure' | ||
# reference_heavy_chain = '/dccstor/dsa-ab-cli-val-0/targets/PD-1/7VUX/relaxed_complex/PD1_7VUX_H_eq.pdb' | ||
|
||
df[output_excel_aligned_heavy_chain_pdb_filename_column] = np.nan | ||
df[output_excel_aligned_heavy_chain_id_column] = np.nan | ||
df[output_excel_aligned_light_chain_pdb_filename_column] = np.nan | ||
df[output_excel_aligned_light_chain_id_column] = np.nan | ||
|
||
for index, row in df.iterrows(): | ||
reference_heavy_chain_pdb_filename = row[ | ||
reference_heavy_chain_pdb_filename_column | ||
] | ||
reference_heavy_chain_id = row[reference_heavy_chain_id_column] | ||
# reference_light_chain_id = row[reference_light_chain_id_column] | ||
|
||
# heavy chain | ||
heavy_chain_pdb_filename = row[heavy_chain_pdb_filename_column] | ||
heavy_chain_id = row[heavy_chain_id_column] # 'A' | ||
# light chain | ||
light_chain_pdb_filename = row[light_chain_pdb_filename_column] | ||
light_chain_id = row[light_chain_id_column] # 'B' | ||
|
||
output_aligned_fn = join( | ||
dirname(heavy_chain_pdb_filename), output_structure_file_prefix | ||
) | ||
|
||
if not isinstance(reference_heavy_chain_pdb_filename, str): | ||
print( | ||
f"ERROR: expected reference_heavy_chain_pdb_filename to be string, but got {reference_heavy_chain_pdb_filename} of type {type(reference_heavy_chain_pdb_filename)}" | ||
) | ||
continue | ||
|
||
if len(reference_heavy_chain_pdb_filename) < 2: | ||
print( | ||
f'ERROR: expected reference_heavy_chain_pdb_filename to be string, but got a suspicious empty or extremely short one: "{reference_heavy_chain_pdb_filename}"' | ||
) | ||
continue | ||
|
||
flexible_align_chains_structure( | ||
dynamic_ordered_chains=[(heavy_chain_pdb_filename, heavy_chain_id)], | ||
apply_rigid_transformation_to_dynamic_chain_ids=[ | ||
(heavy_chain_pdb_filename, heavy_chain_id), | ||
(light_chain_pdb_filename, light_chain_id), | ||
], | ||
static_ordered_chains=[ | ||
(reference_heavy_chain_pdb_filename, reference_heavy_chain_id) | ||
], | ||
output_pdb_filename_extentionless=output_aligned_fn, | ||
) | ||
|
||
# heavy chain | ||
df.loc[index, output_excel_aligned_heavy_chain_pdb_filename_column] = ( | ||
output_aligned_fn + f"_chain_{heavy_chain_id}.pdb" | ||
) | ||
df.loc[index, output_excel_aligned_heavy_chain_id_column] = heavy_chain_id | ||
# light chain | ||
df.loc[index, output_excel_aligned_light_chain_pdb_filename_column] = ( | ||
output_aligned_fn + f"_chain_{light_chain_id}.pdb" | ||
) | ||
df.loc[index, output_excel_aligned_light_chain_id_column] = light_chain_id | ||
|
||
if output_excel_filename is not None: | ||
df.to_excel(output_excel_filename) | ||
print("saved ", output_excel_filename) | ||
|
||
return df | ||
|
||
|
||
if __name__ == "__main__": | ||
CLI(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,71 @@ | ||
from jsonargparse import CLI | ||
from fusedrug.data.protein.structure.structure_io import ( | ||
load_pdb_chain_features, | ||
save_structure_file, | ||
) | ||
from typing import Optional | ||
|
||
|
||
def main( | ||
*, | ||
input_pdb_path: str, | ||
orig_name_chains_to_extract: str, | ||
output_pdb_path_extensionless: str, | ||
output_chain_ids_to_extract: Optional[str] = None, | ||
) -> None: | ||
""" | ||
|
||
Takes an input PDB files and splits it into separate files, one per describe chain, allowing to rename the chains if desired | ||
|
||
Args: | ||
input_pdb_path: | ||
input_chain_ids_to_extract: '_' separated chain ids | ||
output_chain_ids_to_extract: '_' separated chain ids | ||
if not provided, will keep original chain ids | ||
|
||
""" | ||
|
||
orig_name_chains_to_extract = orig_name_chains_to_extract.split("_") | ||
if output_chain_ids_to_extract is None: | ||
output_chain_ids_to_extract = orig_name_chains_to_extract.split("_") | ||
else: | ||
output_chain_ids_to_extract = output_chain_ids_to_extract.split("_") | ||
|
||
assert len(orig_name_chains_to_extract) > 0 | ||
assert len(orig_name_chains_to_extract) == len(output_chain_ids_to_extract) | ||
assert len(orig_name_chains_to_extract[0]) == 1 | ||
|
||
loaded_chains = {} | ||
for orig_chain_id in orig_name_chains_to_extract: | ||
loaded_chains[orig_chain_id] = load_pdb_chain_features( | ||
input_pdb_path, orig_chain_id | ||
) | ||
|
||
mapping = dict(zip(orig_name_chains_to_extract, output_chain_ids_to_extract)) | ||
|
||
loaded_chains_mapped = { | ||
mapping[chain_id]: data for (chain_id, data) in loaded_chains.items() | ||
} | ||
|
||
save_structure_file( | ||
output_filename_extensionless=output_pdb_path_extensionless, | ||
pdb_id="unknown", | ||
chain_to_atom14={ | ||
chain_id: data["atom14_gt_positions"] | ||
for (chain_id, data) in loaded_chains_mapped.items() | ||
}, | ||
chain_to_aa_str_seq={ | ||
chain_id: data["aasequence_str"] | ||
for (chain_id, data) in loaded_chains_mapped.items() | ||
}, | ||
chain_to_aa_index_seq={ | ||
chain_id: data["aatype"] | ||
for (chain_id, data) in loaded_chains_mapped.items() | ||
}, | ||
save_cif=False, | ||
mask=None, # TODO: check | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
CLI(main) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is this script for? please explain in the comments section.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added this desc in the docstring:
"Takes an input PDB files and splits it into separate files, one per describe chain, allowing to rename the chains if desired"