Skip to content

Instantly share code, notes, and snippets.

@jfear
Created April 21, 2016 19:50
Show Gist options
  • Save jfear/5fdf5acdd5920e2455e25a1e13f46142 to your computer and use it in GitHub Desktop.
Save jfear/5fdf5acdd5920e2455e25a1e13f46142 to your computer and use it in GitHub Desktop.
starting point for wrapping rail-rna
#!/usr/bin/env python
import os
import sys
import subprocess
import time
import logging
import ipyparallel
TEMPLATE="""#!/bin/sh
#SBATCH --ntasks={n}
#SBATCH --mem={mem}
#SBATCH --time={timelimit}
#SBATCH --partition={queue}
#SBATCH --job-name=ipy-engine-{cluster_id}
module load openmpi/1.10.0/gcc-4.9.1
mpiexec -np {n} %s -m ipyparallel.engine --profile-dir="{profile_dir}" --cluster-id="{cluster_id}"
""" % sys.executable
def start_cluster(profile, walltime, partition, mem, n):
""" Use ipyparallel to start a cluster job. """
cmd = """ipcluster start \\
-n {n} \\
--ip=* \\
--delay=2 \\
--profile={profile} \\
--engines=Slurm \\
--clean-logs=True \\
--IPClusterEngines.early_shutdown=100 \\
--SlurmEngineSetLauncher.batch_template="{template}" \\
--SlurmEngineSetLauncher.timelimit="{walltime}" \\
--SlurmEngineSetLauncher.mem="{mem}" \\
--SlurmEngineSetLauncher.queue="{partition}" \\
""".format(profile=profile, walltime=walltime, partition=partition, mem=mem, n=n, template=TEMPLATE)
proc = subprocess.Popen(cmd, shell=True)
time.sleep(10)
return proc
def rail(profile):
cmd = """source activate rail
rail-rna go parallel \\
-x ./Drosophila_melanogaster/UCSC/dm3/Sequence/BowtieIndex/genome \\
./Drosophila_melanogaster/UCSC/dm3/Sequence/Bowtie2Index/genome \\
-m https://raw.githubusercontent.com/nellore/rail/master/ex/dm3_example.manifest \\
-f \\
--max-task-attempts 10 \\
--ipython-profile={profile} \\
#--scratch /home/fearjm/data/railtest/tmp \\
#--bowtie1 bowtie \\
#--bowtie1-build bowtie-build \\
#--bowtie2 bowtie2 \\
#--bowtie2-build bowtie2-build \\
#--samtools samtools \\
#--bedgraphtobigwig bedGraphToBigWig \\
""".format(profile=profile)
os.system(cmd)
def stop_cluster(profile):
os.system(""" ipcluster stop \\
--profile={profile} \\
""".format(profile=profile))
if __name__ == '__main__':
profile='slurm'
walltime='1:00:00'
partition = 'niddk'
mem = '4g'
n = '60'
try:
# Start the cluster
print('starting cluster')
cproc = start_cluster(profile, walltime, partition, mem, n)
# Wait until engines can start
print('wiating for engines')
c = ipyparallel.Client(profile=profile)
while len(c.ids) == 0:
time.sleep(1)
print('All OK')
print(c.ids)
print('Starting Rail')
rail(profile)
except KeyboardInterrupt:
pass
finally:
# Stope the cluster
print('stoping cluster')
stop_cluster(profile)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment