Mercurial > repos > guerler > springsuite
comparison spring_cross.py @ 37:0be0af9e695d draft
"planemo upload commit c716195a2cc1ed30ff8c4936621091296a93b2fc"
author | guerler |
---|---|
date | Wed, 25 Nov 2020 14:35:35 +0000 |
parents | |
children | 80a4b98121b6 |
comparison
equal
deleted
inserted
replaced
36:2fe8ffff530d | 37:0be0af9e695d |
---|---|
1 #! /usr/bin/env python3 | |
2 import argparse | |
3 from os import system | |
4 | |
5 from spring_package.DBKit import createFile | |
6 from spring_package.Molecule import Molecule | |
7 | |
8 | |
9 def getId(line): | |
10 line = line.split()[0] | |
11 return line[:4].upper() + line[4:6] | |
12 | |
13 | |
14 def main(args): | |
15 logFile = open(args.log, "w") | |
16 system("mkdir -p %s" % args.temp) | |
17 pdbCount = 0 | |
18 partnerList = set() | |
19 entries = list() | |
20 with open(args.list) as file: | |
21 for line in file: | |
22 entries.append(getId(line)) | |
23 logFile.write("Found %s template entries.\n" % len(entries)) | |
24 for entryId in entries: | |
25 pdb = entryId[:4].lower() | |
26 pdbChain = entryId[5:6] | |
27 pdbFile = "%s/temp.pdb" % args.temp | |
28 pdbDatabaseId = "%s.pdb" % pdb | |
29 createFile(pdbDatabaseId, args.index, args.database, pdbFile) | |
30 try: | |
31 mol = Molecule(pdbFile) | |
32 except Exception: | |
33 logFile.write("Warning: File '%s' not found.\n" % pdbDatabaseId) | |
34 continue | |
35 pdbCount = pdbCount + 1 | |
36 logFile.write("Processing %s, chain %s.\n" % (pdb, pdbChain)) | |
37 logFile.write("Found %d biomolecule(s).\n" % len(mol.biomol.keys())) | |
38 for biomolNumber in mol.biomol: | |
39 if biomolNumber == 0: | |
40 logFile.write("Processing biomolecule.\n") | |
41 bioMolecule = mol | |
42 else: | |
43 logFile.write("Processing biomolecule %d.\n" % biomolNumber) | |
44 bioMolecule = mol.createUnit(biomolNumber) | |
45 nChains = len(bioMolecule.calpha.keys()) | |
46 print("Found %d chain(s)." % nChains) | |
47 if nChains > 1 and pdbChain in bioMolecule.calpha: | |
48 for bioChain in bioMolecule.calpha: | |
49 if bioChain == pdbChain: | |
50 continue | |
51 partnerPdbChain = "%s_%s" % (pdb.upper(), bioChain[:1]) | |
52 partnerList.add("%s\t%s" % (entryId, partnerPdbChain)) | |
53 else: | |
54 logFile.write("Skipping: Chain not found or single chain [%s].\n" % pdbChain) | |
55 logFile.flush() | |
56 with open(args.output, 'w') as output_file: | |
57 for entry in sorted(partnerList): | |
58 output_file.write("%s\n" % entry) | |
59 | |
60 | |
61 if __name__ == "__main__": | |
62 parser = argparse.ArgumentParser(description='List filtering.') | |
63 parser.add_argument('-l', '--list', help='List of PDB chains [PDB_CHAIN]', required=True) | |
64 parser.add_argument('-i', '--index', help='PDB Database Index file (dbkit_index)', required=True) | |
65 parser.add_argument('-d', '--database', help='PDB Database files (dbkit)', required=True) | |
66 parser.add_argument('-o', '--output', help='Output file', required=True) | |
67 parser.add_argument('-t', '--temp', help='Temporary Directory', required=True) | |
68 parser.add_argument('-g', '--log', help='Log File', required=True) | |
69 args = parser.parse_args() | |
70 main(args) |