-
-
Save meowcat/9a1c64acdcbfc15298b3af8553379483 to your computer and use it in GitHub Desktop.
Writing spectra files with templates
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
NAME: meta.name | |
GUGUS: gaga | |
{%- if exists("meta.polarity") -%}POLARITY: {{ meta.polarity }} | |
{% endif -%} | |
{%- if exists("meta.antipolarity") -%}ANTIPOLARITY: {{ meta.antipolarity }} | |
{% endif -%} | |
{%- for key, value in meta.ms -%} | |
AC$MASS_SPECTROMETRY: {{key}} {{value}} | |
{% endfor -%} | |
Num Peaks: {{ length(peaks) }} | |
{%- for p in peaks -%}{{p.mz}} {{p.intensity}}{%- if not loop.is_last -%}, {%- endif -%}{%- endfor -%} |
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
library(tidyverse) | |
library(jinjar) | |
template <- read_file("test.j") | |
meta <- list( | |
name = "Specname", | |
ms = list(collision = 33, ionization = "[M+H]+", sda="next"), | |
polarity = "positive" | |
) | |
peaks <- tribble( | |
~ mz, ~ intensity, | |
123.1234, 111, | |
234.2345, 222, | |
555.4321, 1 | |
) | |
rendered <- template %>% render(meta = meta, peaks = peaks) | |
write_lines(rendered, "spectrum.txt") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment