Skip to content

Instantly share code, notes, and snippets.

@charlesreid1
Last active January 15, 2022 19:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save charlesreid1/b49ef8a365782ea55c2f8ae65a1677d0 to your computer and use it in GitHub Desktop.
Save charlesreid1/b49ef8a365782ea55c2f8ae65a1677d0 to your computer and use it in GitHub Desktop.
Example Jinja template for yaml config files
from jinja2 import Environment, PackageLoader, select_autoescape
def process(**kwargs):
# set up Jinja env
env = Environment(
loader=PackageLoader(''),
autoescape=select_autoescape(['html', 'xml'])
)
for i,t in enumerate(tsv_inputs):
# render the template contents as a string into the var contents
contents = env.get_template('test_config.yaml.j2').render(
tsv_input = t,
**kwargs
)
# write to a file (or do whatever else)
with open('test_config_%d.yaml'%(i+1),'w') as f:
f.write(contents)
if __name__=="__main__":
process(bananas="this is bananas")
# nema: a non-random subset of data from Tulin et al. (2013), that can
# be used to do assembly and comparative expression analysis.
# this sets the output directory name:
basename: 'nema'
# this describes the samples:
samples: "{{ tsv_input }}"
{{ bananas }}
# this says to download samples specified as Web URLs:
get_data:
download_data: True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment