Skip to content

Commit bdf1030

Browse files
committed
Updated script to use only structures on the ranking file
1 parent 16d55f1 commit bdf1030

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

bin/post/lgd_filter_restraints.py

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import sys
77
import os
88
import argparse
9-
import glob
109
import shutil
1110
import re
1211
from prody.measure.contacts import Contacts
@@ -22,8 +21,15 @@
2221
log = LoggingManager.get_logger('lgd_filter_restraints')
2322

2423

25-
def get_structures(dir_path):
26-
return glob.glob(os.path.join(dir_path, 'swarm_*', '*.pdb'))
24+
def get_structures(ranking, base_path='.'):
25+
structures = []
26+
for rank in ranking:
27+
swarm_id = rank.id_cluster
28+
glowworm_id = rank.id_glowworm
29+
structures.append(os.path.join(base_path,
30+
'swarm_{}'.format(swarm_id),
31+
'lightdock_{}.pdb'.format(glowworm_id)))
32+
return structures
2733

2834

2935
def get_restraints(restraints_file):
@@ -44,16 +50,14 @@ def parse_command_line():
4450
"""Parses command line arguments"""
4551
parser = argparse.ArgumentParser(prog='lgd_filter_restraints')
4652

47-
parser.add_argument("structures_path", help="Path of generated structures", metavar="structures_path")
53+
parser.add_argument("ranking_file", help="Path of ranking to be used", metavar="ranking_file")
4854
parser.add_argument("restraints_file", help="File including restraints", metavar="restraints_file")
4955
parser.add_argument("receptor_chains", help="Chains on the receptor partner", metavar="receptor_chains")
5056
parser.add_argument("ligand_chains", help="Chains on the receptor partner", metavar="ligand_chains")
5157
parser.add_argument("--cutoff", "-cutoff", "-c", help="Interaction cutoff",
5258
dest="cutoff", type=float, default=5.0)
5359
parser.add_argument("--fnat", "-fnat", "-f", help="Structures with at least this fraction of native contacts",
5460
dest="fnat", type=float)
55-
parser.add_argument("--rank", "-rank", "-r", help="Ranking file",
56-
dest="ranking_file")
5761

5862
return parser.parse_args()
5963

@@ -65,8 +69,12 @@ def parse_command_line():
6569

6670
log.info("Calculating interface at {:3.1f}A".format(args.cutoff))
6771

72+
# Get ranking
73+
ranking = read_ranking_file(args.ranking_file)
74+
6875
# Get all the PDB structures in a given directory
69-
structures = get_structures(args.structures_path)
76+
base_path = os.path.abspath(os.path.dirname(args.ranking_file))
77+
structures = get_structures(ranking, base_path)
7078

7179
restraints_receptor, restraints_ligand = get_restraints(args.restraints_file)
7280

@@ -123,14 +131,12 @@ def parse_command_line():
123131
log.error('Filtering has failed for structure {}. Please see error:'.format(pdb_file))
124132
log.error(str(e))
125133

126-
if args.ranking_file:
127-
print(filter_passed)
128-
ranking = read_ranking_file(args.ranking_file)
129-
filtered_ranking = os.path.join(filtered_folder, 'rank_filtered.list')
130-
with open(filtered_ranking, 'w') as handle:
131-
for rank in ranking:
132-
print(rank)
133-
if rank.id_cluster in filter_passed and rank.id_glowworm in filter_passed[rank.id_cluster]:
134-
handle.write('swarm_{}_{}.pdb {:5.3f} {:5.3f}'.format(rank.id_cluster,
135-
rank.id_glowworm, rank.scoring, percentages[(rank.id_cluster, rank.id_glowworm)]) + os.linesep)
136134

135+
print(filter_passed)
136+
filtered_ranking = os.path.join(filtered_folder, 'rank_filtered.list')
137+
with open(filtered_ranking, 'w') as handle:
138+
for rank in ranking:
139+
print(rank)
140+
if rank.id_cluster in filter_passed and rank.id_glowworm in filter_passed[rank.id_cluster]:
141+
handle.write('swarm_{}_{}.pdb {:5.3f} {:5.3f}'.format(rank.id_cluster,
142+
rank.id_glowworm, rank.scoring, percentages[(rank.id_cluster, rank.id_glowworm)]) + os.linesep)

0 commit comments

Comments
 (0)