2

Snakemake expand function

Hello, I have a list of lists such as :

list_ranges=[[0,9],[10,19],[20,29],[30,33]]

How can I used expand in Snakemake in order to create 4 arguments such as :

/user/Temp_dir/Ranges_0-9.tpm
/user/Temp_dir/Ranges_10-19.tpm
/user/Temp_dir/Ranges_20-29.tpm
/user/Temp_dir/Ranges_30-33.tpm

So far I tried ;

expand("/user/Temp_dir/Ranges_{range1}-{range2}.tpm", range1 = [x[0] for x in list_ranges] , range2 = [x[-1] for x in list_ranges]))
SultanOrazbayev
  • 14,900
  • 3
  • 16
  • 46
chippycentra
  • 3,396
  • 1
  • 6
  • 24
  • I'm not familiar with snakemake, but you can get a list just using `[f"/user/Temp_dir/Ranges_{range1}-{range2}.tpm" for range1, range2 in list_ranges]` - note the tuple expansion assignment in the `for` loop and the `f`-string. – alani Aug 23 '22 at 12:54
  • Don't use `expand`, the single most confusing feature of Snakemake. Learn Python basics and understand that rule inputs are just lists of filenames that can be produced whatever way is more convenient / fun / easy / readable / . – bli Aug 24 '22 at 19:10

1 Answers1

4

The easiest solution here is to use Python:

expanded = [f"/user/Temp_dir/Ranges_{r1}-{r2}.tpm" for r1, r2 in list_ranges]

If you insist on using expand, then you will want to pass zip argument:

expand("/user/Temp_dir/Ranges_{r1}-{r2}.tpm", zip, r1 = [x[0] for x in list_ranges] , r2 = [x[-1] for x in list_ranges]))
SultanOrazbayev
  • 14,900
  • 3
  • 16
  • 46