Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F79797269
hello_world_pipeline.snake
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Aug 28, 07:13
Size
2 KB
Mime Type
text/x-python
Expires
Fri, Aug 30, 07:13 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
20232095
Attached To
R2915 eSCT pipeline interoperability
hello_world_pipeline.snake
View Options
##########################################
## Basic hello world Snakemake pipeline ##
##########################################
#
# @author: Balazs Laurenczy
# @date: 2017
########
# INIT #
########
import os, logging
from timeit import default_timer as t
from datetime import datetime
# set up logging
logging.basicConfig(level = logging.INFO, format = '#%(asctime)s | %(levelname)-7s | %(filename)-20s: %(message)s')
logging.info('Starting Snakemake pipeline ...')
# get config parameters
N_FILES = int(config.get('n', 4))
OUT_FOLDER = config.get('output_folder', 'output')
if OUT_FOLDER[:-1] != '/': OUT_FOLDER += '/' # add ending slash to folder path
REF_FOLDER = config.get('ref_folder', 'ref_output')
if REF_FOLDER[:-1] != '/': REF_FOLDER += '/' # add ending slash to folder path
#########
# RULES #
#########
rule all:
input:
expand(OUT_FOLDER + 'helloworld_{w}.log', w = range(N_FILES))
run:
logging.info('Pipeline completed.')
rule write_hello:
output:
OUT_FOLDER + 'hello_{w}.log'
shell:
'echo "hello{wildcards.w}" > {output}'
rule write_world:
output:
OUT_FOLDER + 'world_{w}.log'
shell:
'echo "world{wildcards.w}" > {output}'
rule write_hello_world:
input:
hello = OUT_FOLDER + 'hello_{w}.log',
world = OUT_FOLDER + 'world_{w}.log'
output:
OUT_FOLDER + 'helloworld_{w}.log'
shell:
'cat {input.hello} {input.world} > {output}'
onsuccess:
logging.info('Pipeline completed successfully.')
if not os.path.exists(REF_FOLDER):
exit('Cannot check validity of pipeline as there is no reference folder at path "{}". Aborting.'.format(REF_FOLDER))
# test if output folders are identical
shell('cd {OUT_FOLDER} && find . -regex ".*.log" -type f -exec md5sum {{}} \; | sort -k2 > content.md5')
try:
shell('diff {OUT_FOLDER}content.md5 {REF_FOLDER}content.md5')
logging.info('Pipeline is valid.'.format(REF_FOLDER))
except Exception:
logging.error('Some differences (see above) exist between the current pipeline\'s output ' +
'and the reference output at path "{}". Pipeline is *not* valid.'.format(REF_FOLDER))
onerror:
logging.info('Pipeline failed.')
Event Timeline
Log In to Comment