Last active
January 15, 2022 19:45
-
-
Save charlesreid1/b49ef8a365782ea55c2f8ae65a1677d0 to your computer and use it in GitHub Desktop.
Example Jinja template for yaml config files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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