Skip to content

Commit 0c46ed2

Browse files
committed
fix: formatting and stabelized
1 parent 1b91529 commit 0c46ed2

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

workflow/scripts/prepareDocking.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import os
77

88
input_directory = snakemake.input.in_dir
9-
output_directory = snakemake.config["OUTPUT_DIR"]
9+
output_directory = snakemake.output.
1010

1111
if "ZINC" in snakemake.config["DATABASE"]:
1212
weightLog = input_directory[-2:]

workflow/scripts/prepareReceptor.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
"""preparation of proteins specified in configfile"""
22

33
import os
4+
import tempfile
45
from Bio.PDB import PDBParser, PDBIO
56

7+
# Redirect all stdout/stderr to the log file
8+
sys.stdout = open(snakemake.log[0], 'w', buffering=1) # line buffering
9+
sys.stderr = sys.stdout
610

711
def removeChains(model, chainlist):
812
"""
@@ -39,18 +43,31 @@ def prepareRec(inputfile, outputfile, target):
3943
"""
4044
select chains to delete depending on config definition
4145
"""
42-
print(target)
46+
print(f"Preparing target: {target}")
47+
# target might be a gzipped file
48+
if inputfile.endswith(".gz"):
49+
import gzip
50+
import shutil
51+
# the unzipped file needs to be temporary
52+
with tempfile.NamedTemporaryFile(delete=False) as f:
53+
print(f" Unzipping {inputfile} to temporary file.")
54+
ungzipped = f.name
55+
with gzip.open(inputfile, "rb") as f_in:
56+
with open(ungzipped, "wb") as f_out:
57+
shutil.copyfileobj(f_in, f_out)
58+
inputfile = ungzipped
4359
ID = target.split(",")
4460
chains = ID[1].split(" ")
4561
parser = PDBParser() # MMCIFParser()
4662
structure = parser.get_structure(ID[0], inputfile)
4763
model = structure[0]
64+
print(f" Removing chains not in: {chains}")
4865
removeChains(model, chains)
4966

5067
io = PDBIO()
5168
io.set_structure(structure)
5269
out = outputfile
53-
print("printing outfile")
70+
print(f" Printing outfile: {out}")
5471
io.save(out)
5572

5673

0 commit comments

Comments
 (0)