diff --git a/bidscoin/bcoin.py b/bidscoin/bcoin.py index cb71e6a5..b604a4d8 100755 --- a/bidscoin/bcoin.py +++ b/bidscoin/bcoin.py @@ -51,20 +51,18 @@ def update_to(self, b=1, bsize=1, tsize=None): self.update(b * bsize - self.n) # will also set self.n = b * bsize -def drmaa_nativespec(specs: str) -> str: +def drmaa_nativespec(specs: str, session) -> str: """ Converts native Torque walltime and memory specifications to the DRMAA implementation (currently only Slurm is supported) - :param specs: Native Torque walltime and memory specifications, e.g. '-l walltime=00:10:00,mem=2gb' - :return: The converted native specifications + :param specs: Native Torque walltime and memory specifications, e.g. '-l walltime=00:10:00,mem=2gb' + :param session: The DRMAA session + :return: The converted native specifications """ - import drmaa # Lazy import to avoid import error on non-HPC systems + jobmanager = session.drmaaImplementation - with drmaa.Session() as session: - implementation = session.drmaaImplementation - - if 'Slurm' in implementation and '-l ' in specs: + if 'Slurm' in jobmanager and '-l ' in specs: specs = (specs.replace('-l ', '') .replace(',', ' ') .replace('walltime', '--time') diff --git a/bidscoin/bidsapps/deface.py b/bidscoin/bidsapps/deface.py index 6631fea0..6aba53d2 100755 --- a/bidscoin/bidsapps/deface.py +++ b/bidscoin/bidsapps/deface.py @@ -70,7 +70,7 @@ def deface(bidsfolder: str, pattern: str, participant: list, force: bool, output jt = pbatch.createJobTemplate() jt.jobEnvironment = os.environ jt.remoteCommand = shutil.which('pydeface') - jt.nativeSpecification = drmaa_nativespec(cluster) + jt.nativeSpecification = drmaa_nativespec(cluster, pbatch) jt.joinFiles = True # Loop over bids subject/session-directories diff --git a/bidscoin/bidsapps/medeface.py b/bidscoin/bidsapps/medeface.py index 7aa15023..e21d7802 100755 --- a/bidscoin/bidsapps/medeface.py +++ b/bidscoin/bidsapps/medeface.py @@ -76,7 +76,7 @@ def medeface(bidsfolder: str, pattern: str, maskpattern: str, participant: list, jt = pbatch.createJobTemplate() jt.jobEnvironment = os.environ jt.remoteCommand = shutil.which('pydeface') - jt.nativeSpecification = drmaa_nativespec(cluster) + jt.nativeSpecification = drmaa_nativespec(cluster, pbatch) jt.joinFiles = True # Loop over bids subject/session-directories to first get all the echo-combined deface masks diff --git a/bidscoin/bidsapps/skullstrip.py b/bidscoin/bidsapps/skullstrip.py index 01b61a5e..e8f253de 100755 --- a/bidscoin/bidsapps/skullstrip.py +++ b/bidscoin/bidsapps/skullstrip.py @@ -84,7 +84,7 @@ def skullstrip(bidsfolder: str, pattern: str, participant: list, masked: str, ou jt = pbatch.createJobTemplate() jt.jobEnvironment = os.environ jt.remoteCommand = shutil.which('mri_synthstrip') - jt.nativeSpecification = drmaa_nativespec(cluster) + jt.nativeSpecification = drmaa_nativespec(cluster, pbatch) jt.joinFiles = True # Loop over bids subject/session-directories diff --git a/bidscoin/bidsapps/slicereport.py b/bidscoin/bidsapps/slicereport.py index 2e2c60e0..043a8f7c 100755 --- a/bidscoin/bidsapps/slicereport.py +++ b/bidscoin/bidsapps/slicereport.py @@ -123,13 +123,13 @@ def slicer_append(inputimage: Path, operations: str, outlineimage: Path, mainopt jt = pbatch.createJobTemplate() jt.jobEnvironment = os.environ jt.remoteCommand = str(script) - jt.nativeSpecification = drmaa_nativespec(cluster) + jt.nativeSpecification = drmaa_nativespec(cluster, pbatch) jt.joinFiles = True jt.jobName = 'slicereport' jt.outputPath = f"{os.getenv('HOSTNAME')}:{workdir}/{jt.jobName}.out" jobid = pbatch.runJob(jt) - pbatch.deleteJobTemplate(jt) - LOGGER.info(f"Your slicereport job has been submitted with ID: {jobid}") + pbatch.deleteJobTemplate(jt) + LOGGER.info(f"Your slicereport job has been submitted with ID: {jobid}") else: LOGGER.bcdebug(f"Command: {command}") diff --git a/bidscoin/bidscoiner.py b/bidscoin/bidscoiner.py index 6e462817..02d5a7c5 100755 --- a/bidscoin/bidscoiner.py +++ b/bidscoin/bidscoiner.py @@ -143,7 +143,7 @@ def bidscoiner(sourcefolder: str, bidsfolder: str, participant: list=(), force: jt = pbatch.createJobTemplate() jt.jobEnvironment = os.environ jt.remoteCommand = shutil.which('bidscoiner') or __file__ - jt.nativeSpecification = drmaa_nativespec(cluster) + jt.nativeSpecification = drmaa_nativespec(cluster, pbatch) jt.joinFiles = True jobids = []