-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
55 lines (40 loc) · 1.74 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# app.py
import os
import tempfile
import urllib
from typing import List
import networkx as nx
import matplotlib.pyplot as plt
from Bio.PDB import PDBParser
from descriptors.peptide import Peptide
from descriptors.utils.phychem import PhysicoChemical
def load_structure(filename: str):
try:
complex = parser.get_structure("XXX", filename)
peptide_chain: List = [chain for chain in complex.get_chains() if len(list(chain.get_residues())) < 51]
return peptide_chain
except Exception as e:
pass
parser: PDBParser = PDBParser(PERMISSIVE=1)
if __name__ == '__main__':
with open(os.path.join(os.getcwd(), "data/pdbs.txt"), 'r') as lines:
for line in lines:
pdb = line.strip("\n").strip()
file_name: str
with tempfile.NamedTemporaryFile(delete=False) as tmp:
url: str = f"https://files.rcsb.org/download/{pdb}.pdb"
urllib.request.urlretrieve(url, tmp.name)
file_name = tmp.name
chains: List = load_structure(filename=file_name)
for i, chain in enumerate(chains):
cycle_found: bool
peptide: Peptide = Peptide(chain=chain)
peptide.generate_peptide_graph()
graph = peptide.get_graph()
physico_chemical = PhysicoChemical(chain=chain, residues=chain, sequence=peptide.get_one_letter_sequence())
try:
cycle_found = any(nx.find_cycle(graph, orientation="ignore"))
except:
cycle_found = False
print(pdb, cycle_found, peptide.get_sequence(), physico_chemical.get_mass())
os.remove(file_name)