There appears to be a syntax error in your code. I’m afraid there’s only so far I can go with this without you supplying the full code base.
The answer to the initial question is you must separate your samples by channels. Filter them, separate, branch. Get each sample in a separate channel then just pass that channel into the relevant process. This can be a tricky concept for people unfamiliar with functional programming, but once you get it Nextflow will become fluid and easy.