nextflow icon indicating copy to clipboard operation
nextflow copied to clipboard

Allow splitFasta generated filenames to be fasta record ids

Open msmootsgi opened this issue 9 years ago • 5 comments

It would be nice if the splitFasta operator had an option to save the fasta files it generates named with the fasta record id. This would only work in instances where splitFasta splits to one file and the record id is acceptable as a filename, but this is still a fairly common request that we see.

msmootsgi avatar Sep 29 '17 15:09 msmootsgi

It could be added a autoNames option. However fasta IDs tend to contain reserved linux/posix special characters eg. |, ', &, etc. How to sanitize it?

pditommaso avatar Nov 13 '17 11:11 pditommaso

I'd just do something like: header.replaceAll("[^a-zA-Z0-9]","") or header.replaceAll("[^a-zA-Z0-9]","_") and maybe emit a warning if a header needs to be changed. My feeling is that if someone wants to use fasta headers as filenames, then it's up to them to make the headers workable as filenames. Given that there is a very reasonable fallback (i.e. the current behavior) I don't think this option needs to go to great lengths to accommodate every edge case.

msmootsgi avatar Nov 13 '17 16:11 msmootsgi

I gave a try to this, but it's more complicated than it could seem and it cannot be always applied. For example: chunks can be pure textual ie. the fasta ID is not parsed or in the most common scenario fasta chunks contain more than a single fasta record (what ID should be used?).

I think it would be better to leave the user to manage this. #397 should simplify this.

pditommaso avatar Dec 05 '17 08:12 pditommaso

Do you have a branch with the code you experimented with? I'd like to better understand what's difficult.

msmootsgi avatar Dec 05 '17 19:12 msmootsgi

There isn't a specific branch. You can look at FastaSplitter and related classes.

pditommaso avatar Dec 06 '17 15:12 pditommaso