|
4 | 4 |
|
5 | 5 | import logging |
6 | 6 | import sys |
| 7 | +import warnings |
7 | 8 | from pathlib import Path |
8 | 9 | from typing import Optional, Union |
9 | 10 |
|
10 | 11 | from Bio.PDB.Chain import Chain |
11 | 12 | from Bio.PDB.MMCIFParser import MMCIFParser |
| 13 | +from Bio.PDB.PDBExceptions import PDBConstructionWarning |
12 | 14 | from Bio.PDB.PDBParser import PDBParser |
13 | 15 | from Bio.PDB.Polypeptide import PPBuilder, is_aa |
14 | 16 | from Bio.PDB.Structure import Structure |
15 | 17 |
|
| 18 | +warnings.filterwarnings("ignore", category=PDBConstructionWarning) |
16 | 19 | log = logging.getLogger("Prodigy") |
17 | 20 |
|
18 | 21 |
|
| 22 | +def get_parser(input_f: Path) -> Union[PDBParser, MMCIFParser]: |
| 23 | + if input_f.suffix == ".cif": |
| 24 | + return MMCIFParser() |
| 25 | + else: |
| 26 | + return PDBParser() |
| 27 | + |
| 28 | + |
19 | 29 | def validate_structure( |
20 | 30 | s: Structure, selection: Optional[list[str]] = None, clean: bool = True |
21 | 31 | ) -> Structure: |
| 32 | + |
22 | 33 | # setup logging |
23 | 34 | logger = logging.getLogger("Prodigy") |
24 | 35 |
|
@@ -132,29 +143,24 @@ def parse_structure(path: str) -> tuple[Structure, int, int]: |
132 | 143 | ) |
133 | 144 | sys.exit(1) |
134 | 145 |
|
135 | | - parser: Union[MMCIFParser, PDBParser] |
136 | | - if extension == ".cif": |
137 | | - parser = MMCIFParser() |
138 | | - else: |
139 | | - parser = PDBParser() |
140 | | - |
| 146 | + parser = get_parser(Path(path)) |
141 | 147 | structure_name = Path(path).stem |
142 | 148 | structure_path = Path(path) |
143 | 149 | try: |
144 | | - structure = parser.get_structure(structure_name, structure_path) |
| 150 | + original_structure = parser.get_structure(structure_name, structure_path) |
145 | 151 | except Exception as e: |
146 | 152 | log.exception(e) |
147 | 153 | sys.exit(1) |
148 | 154 |
|
149 | | - assert isinstance(structure, Structure) |
| 155 | + assert isinstance(original_structure, Structure) |
150 | 156 |
|
151 | | - # Validate the structure |
152 | | - validated_structure = validate_structure(structure) |
| 157 | + structure = validate_structure(original_structure) |
153 | 158 |
|
154 | 159 | # Get number of chains |
155 | | - number_of_chains = len(set([c.id for c in validated_structure.get_chains()])) |
| 160 | + number_of_chains = len(set([c.id for c in structure.get_chains()])) |
156 | 161 |
|
157 | 162 | # Get number of residues |
158 | | - number_of_residues = len(list(validated_structure.get_residues())) |
| 163 | + number_of_residues = len(list(structure.get_residues())) |
159 | 164 |
|
160 | | - return (validated_structure, number_of_chains, number_of_residues) |
| 165 | + # structure, n_chains, n_res = parse_structure(path=str(struct_path)) |
| 166 | + return (structure, number_of_chains, number_of_residues) |
0 commit comments