Skip to content

Commit f347171

Browse files
Merge pull request #6 from MPI-Dortmund/tsv-as-argument
AM database as argument
2 parents 57e2077 + b61285e commit f347171

3 files changed

Lines changed: 69 additions & 12 deletions

File tree

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pip install pymissense
2929

3030
Generate usage is:
3131
```
32-
usage: pymissense [-h] [--pdbpath PDBPATH] [--maxacid MAXACID] uniprot_id output_path
32+
usage: pymissense[-h] [--tsv TSV] [--pdbpath PDBPATH] [--maxacid MAXACID] uniprot_id output_path
3333
3434
AlphaMissense plot and pdb generator
3535
@@ -39,13 +39,14 @@ positional arguments:
3939
4040
options:
4141
-h, --help show this help message and exit
42+
--tsv TSV You can provide the path to the tsv file if you want to skip the download. (default: None)
4243
--pdbpath PDBPATH If defined, it will write the pathogencity as bfactor in that PDB. If its not defined or not existing it will instead download the alphafold predicted PDB (default: None)
43-
--maxacid MAXACID Maximum squence number to use. (default: None)
44+
--maxacid MAXACID Maximum squence number to use in the plot. (default: None)
4445
```
4546

4647
You can provide the optional argument `--pdbpath` if you want to use an experimental PDB, otherwise it will instead download the alphafold predicted PDB.
4748

48-
For example, to reproduce [Figure 3D](https://www.science.org/doi/10.1126/science.adg7492#F3) (the middle one) and the generate the PDB shown in [Figure 3E](https://www.science.org/doi/10.1126/science.adg7492#F3) do:
49+
For example, to reproduce [Figure 3D](https://www.science.org/doi/10.1126/science.adg7492#F3) (the middle one) and generates the PDB shown in [Figure 3E](https://www.science.org/doi/10.1126/science.adg7492#F3) do:
4950

5051
```
5152
wget https://files.rcsb.org/download/7UPI.pdb

missense/missense.py

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -401,11 +401,13 @@ def gen_image(pos_to_val) -> np.array:
401401
return img
402402

403403

404-
def get_data_tuple(uniprot_id: str):
404+
def get_data_tuple(uniprot_id: str, tsv_path: str = None):
405405
"""
406406
Extracts the raw data for the plot from the tsv file.
407407
"""
408-
with open(os.path.join(tempfile.gettempdir(), "alpha.tsv"), encoding="utf-8") as f:
408+
if tsv_path is None:
409+
tsv_path = os.path.join(tempfile.gettempdir(), "alpha.tsv")
410+
with open(tsv_path, encoding="utf-8") as f:
409411
doc = f.read()
410412
m = re.findall(uniprot_id.upper() + r"\t(.\d+.)\t(\d.\d+)", doc)
411413
pos_to_val = []
@@ -457,6 +459,13 @@ def create_parser() -> argparse.ArgumentParser:
457459
help="Output folder",
458460
)
459461

462+
parser.add_argument(
463+
"--tsv",
464+
type=str,
465+
help="You can provide the path to the tsv file if you want to skip the download.",
466+
default=None
467+
)
468+
460469
parser.add_argument(
461470
"--pdbpath",
462471
type=str,
@@ -547,8 +556,17 @@ def create_modified_pdb(img: np.array, uniprot_id: str, output_path: str, pdb_pt
547556
else:
548557
out_file.write(f'{line}')
549558

550-
def _run(uniprot_id: str, output_path: str, pdbpath: str, maxacid: int):
551-
download_missense_data()
559+
def _run(uniprot_id: str,
560+
output_path: str,
561+
tsvpath: str,
562+
pdbpath: str,
563+
maxacid: int):
564+
565+
if tsvpath is None or os.path.exists(tsvpath)==False:
566+
tsvpath=None
567+
download_missense_data()
568+
569+
552570
os.makedirs(output_path, exist_ok=True)
553571

554572
chain = None
@@ -559,7 +577,11 @@ def _run(uniprot_id: str, output_path: str, pdbpath: str, maxacid: int):
559577
print(f"Cant find chain for {uniprot_id} in {pdbpath}")
560578
sys.exit(1)
561579

562-
pos_to_val = get_data_tuple(uniprot_id)
580+
pos_to_val = get_data_tuple(uniprot_id=uniprot_id, tsv_path=tsvpath)
581+
582+
if len(pos_to_val) == 0:
583+
print(f"Could not find any data in the AlphaMissense database for uniprot id {uniprot_id}")
584+
sys.exit(1)
563585

564586
out_fig_pth = os.path.join(output_path, f"{uniprot_id}.pdf")
565587
img_raw_data = make_and_save_plot(pos_to_val, out_fig_pth, maxacid)
@@ -570,7 +592,11 @@ def _run(uniprot_id: str, output_path: str, pdbpath: str, maxacid: int):
570592

571593
def _main_():
572594
args = create_parser().parse_args()
573-
_run(args.uniprot_id, args.output_path, args.pdbpath, args.maxacid)
595+
_run(uniprot_id=args.uniprot_id,
596+
output_path=args.output_path,
597+
pdbpath=args.pdbpath,
598+
maxacid=args.maxacid,
599+
tsvpath=args.tsv)
574600

575601

576602

tests/test_run.py

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,35 @@ def test_pdf_and_and_are_generated(self):
2828
ms._run(uniprot_id="Q9UQ13",
2929
output_path=tmpdirname,
3030
maxacid=200,
31-
pdbpath=None
31+
pdbpath=None,
32+
tsvpath=None
33+
)
34+
35+
self.assertEqual(True, os.path.exists(os.path.join(tmpdirname,"Q9UQ13.pdf")))
36+
self.assertEqual(True, os.path.exists(os.path.join(tmpdirname, "Q9UQ13-edit.pdb")))
37+
38+
def test_pdf_and_and_are_generated_non_existing_uniprot(self):
39+
40+
shutil.copyfile(os.path.join(os.path.dirname(__file__), "../resources/tests/Q9UQ13/alpha.tsv"),
41+
os.path.join(tempfile.gettempdir(), "alpha.tsv"))
42+
43+
with tempfile.TemporaryDirectory() as tmpdirname:
44+
with self.assertRaises(SystemExit):
45+
ms._run(uniprot_id="Q9UQ13234234",
46+
output_path=tmpdirname,
47+
maxacid=200,
48+
pdbpath=None,
49+
tsvpath=None
50+
)
51+
52+
def test_pdf_and_and_are_generated_tsv_by_path(self):
53+
54+
with tempfile.TemporaryDirectory() as tmpdirname:
55+
ms._run(uniprot_id="Q9UQ13",
56+
output_path=tmpdirname,
57+
maxacid=200,
58+
pdbpath=None,
59+
tsvpath=os.path.join(os.path.dirname(__file__), "../resources/tests/Q9UQ13/alpha.tsv")
3260
)
3361

3462
self.assertEqual(True, os.path.exists(os.path.join(tmpdirname,"Q9UQ13.pdf")))
@@ -43,7 +71,8 @@ def test_pdb_check_with_reference(self):
4371
ms._run(uniprot_id="Q9UQ13",
4472
output_path=tmpdirname,
4573
maxacid=200,
46-
pdbpath=None
74+
pdbpath=None,
75+
tsvpath=None
4776
)
4877

4978
ref_pth = os.path.join(os.path.dirname(__file__), "../resources/tests/Q9UQ13/Q9UQ13-edit.pdb")
@@ -62,7 +91,8 @@ def test_pdb_check_with_reference_with_pdb(self):
6291
ms._run(uniprot_id="Q9UQ13",
6392
output_path=tmpdirname,
6493
maxacid=200,
65-
pdbpath=os.path.join(os.path.dirname(__file__), "../resources/tests/Q9UQ13-with-pdb/7upi.pdb")
94+
pdbpath=os.path.join(os.path.dirname(__file__), "../resources/tests/Q9UQ13-with-pdb/7upi.pdb"),
95+
tsvpath=None
6696
)
6797

6898
ref_pth = os.path.join(os.path.dirname(__file__), "../resources/tests/Q9UQ13-with-pdb/Q9UQ13-edit.pdb")

0 commit comments

Comments
 (0)