Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions autoafids/workflow/envs/synthsr.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
---
name: synthsr
channels: [anaconda, conda-forge, defaults]
channels: [khanlab, anaconda, conda-forge, defaults]
dependencies:
- python=3.8
- tensorflow=2.2.0
- keras=2.3.1
- nibabel
- matplotlib
- numpy<1.20
- synthsr
44 changes: 9 additions & 35 deletions autoafids/workflow/scripts/run_synthsr.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,22 @@
import subprocess


# clone SynthSR repo
def clone_repo(download_dir, log_file):
repo = "https://github.com/mackenziesnyder/SynthSR"
branch = "mackenzie/scaled-down-repo"

repo_dir = os.path.join(download_dir, "SynthSR")
if os.path.exists(repo_dir):
logging.info(
f"SynthSR repository already exists at {repo_dir}. Skipping clone."
)
return repo_dir

with open(log_file, "a") as log:
try:
subprocess.run(
["git", "clone", "--branch", branch, repo, repo_dir],
check=True,
stdout=log,
stderr=log
)
except subprocess.CalledProcessError as e:
logging.error(f"Error cloning SynthSR repo: {e}")
raise

return repo_dir

# run SynthSR
def run_program(
repo_dir,
input_img,
output_img,
modality,
log_file
):
predict_script = os.path.join(
repo_dir,
"scripts",
"predict_command_line.py"
)
cmd = ["python", predict_script, input_img, output_img, "--cpu"]

cmd = [
"python",
"-m",
"SynthSR.scripts.predict_command_line",
input_img,
output_img,
"--cpu"
]

if modality == "ct":
cmd.append["--ct"]
Expand All @@ -66,10 +42,8 @@ def run_program(

log_file=snakemake.log[0]
download_dir=snakemake.params["download_dir"]
repo_dir = clone_repo(download_dir, log_file)

run_program(
repo_dir=repo_dir,
input_img=snakemake.input["im"],
output_img=snakemake.output["SynthSR"],
modality=snakemake.params["modality"],
Expand Down
Loading