Python 在多个并行样本上循环蛇行规则

Python 在多个并行样本上循环蛇行规则,python,python-3.x,snakemake,Python,Python 3.x,Snakemake,我已经开始使用snakemake构建一个工作流,在一个样本列表上运行bwa mem。下面是我的配置文件结构和实际数据 sample1: -参数:0 日志:/home/nsm/Desktop/nsm/nsm backend/media/user_2_animesh_singh21/file/6e8c3cdf-1cad-4426-a005-91d3c4d5f691/sample1/sample1_fcl1_lane1_aln.log 名称:fcl1_lane1 输出:/home/nsm/Deskto

我已经开始使用snakemake构建一个工作流,在一个样本列表上运行bwa mem。下面是我的配置文件结构和实际数据

sample1:
-参数:0
日志:/home/nsm/Desktop/nsm/nsm backend/media/user_2_animesh_singh21/file/6e8c3cdf-1cad-4426-a005-91d3c4d5f691/sample1/sample1_fcl1_lane1_aln.log
名称:fcl1_lane1
输出:/home/nsm/Desktop/nsm/nsm backend/media/user_2_animesh_singh21/file/6e8c3cdf-1cad-4426-a005-91d3c4d5f691/sample1/sample1_fcl1_lane1_aln.sam
参数:'-t1-M-R'@RG\tID:POP1\u L3\tPL:Illumina\tPU:D0AW3ACXX.3\tLB:POP1.TruSeq\tSM:POP1''
read1:/home/nsm/Desktop/nsm/nsm backend/media/user_2_animesh_singh21/file/POP1_R1.fastq
read2:/home/nsm/Desktop/nsm/nsm backend/media/user_2_animesh_singh21/file/POP1_R2.fastq
参考:/home/nsm/Desktop/nsm/nsm backend/media/global\u space/NCBI37\u DECOY.fa
-参数:0
日志:/home/nsm/Desktop/nsm/nsm backend/media/user_2_animesh_singh21/file/6e8c3cdf-1cad-4426-a005-91d3c4d5f691/sample1/sample1_fcl1_lane2_aln.log
名称:fcl1_lane2
输出:/home/nsm/Desktop/nsm/nsm backend/media/user_2_animesh_singh21/file/6e8c3cdf-1cad-4426-a005-91d3c4d5f691/sample1/sample1_fcl1_lane2_aln.sam
参数:'-t1-M-R'@RG\tID:POP1\u L3\tPL:Illumina\tPU:D0AW3ACXX.3\tLB:POP1.TruSeq\tSM:POP1''
read1:/home/nsm/Desktop/nsm/nsm backend/media/user_2_animesh_singh21/file/POP1_R1.fastq
read2:/home/nsm/Desktop/nsm/nsm backend/media/user_2_animesh_singh21/file/POP1_R2.fastq
参考:/home/nsm/Desktop/nsm/nsm backend/media/global\u space/NCBI37\u DECOY.fa
-参数:0
日志:/home/nsm/Desktop/nsm/nsm backend/media/user_2_animesh_singh21/file/6e8c3cdf-1cad-4426-a005-91d3c4d5f691/sample1/sample1_fcl2_lane2_aln.log
名称:fcl2_lane2
输出:/home/nsm/Desktop/nsm/nsm backend/media/user_2_animesh_singh21/file/6e8c3cdf-1cad-4426-a005-91d3c4d5f691/sample1/sample1_fcl2_lane2_aln.sam
参数:'-t1-M-R'@RG\tID:POP1\u L3\tPL:Illumina\tPU:D0AW3ACXX.3\tLB:POP1.TruSeq\tSM:POP1''
read1:/home/nsm/Desktop/nsm/nsm backend/media/user_2_animesh_singh21/file/POP1_R1.fastq
read2:/home/nsm/Desktop/nsm/nsm backend/media/user_2_animesh_singh21/file/POP1_R2.fastq
参考:/home/nsm/Desktop/nsm/nsm backend/media/global\u space/NCBI37\u DECOY.fa
sample1的每个条目都包含
['reference','read1','read2','output','log','params','name','argument']

我编写了以下snakefile来运行bwa mem:

sample_name=list(config.keys())[0]
规则所有:
消息:“生成循环输出”
输入:
配置['output']
规则bwa_运行:
消息:“正在运行BWA MEM”
输出:[i['output']用于配置中的i[sample\u name]]
线程:4
运行:
对于配置[sample_name]中的i:
shell(f“bwamem{i['reference']}{i['read1']}{i['read2']}-t{threads}{i['params']}>{i['output']}2>{i['log']}”)
这项工作做得很好,但我知道事实上,这不会并行运行。for循环避免了这种情况。我需要帮助找出如何把它变成一个并行运行的蛇形文件

我试图通过查看stackoverflow中的一些其他答案来完成以下工作

通配符约束:
计数器=“\d+”
示例_name=list(config.keys())[0]
def input_all(通配符):
返回[
配置[sample_name][int(wildcards.counter)]['reference'],
配置[sample_name][int(wildcards.counter)]['read1'],
配置[sample_name][int(wildcards.counter)]['read2'],
]   
规则所有:
消息:“生成循环输出”
输入:
展开(“{output}{counter}”,counter=range(len(配置[sample_name])),output=[i['output']表示配置[sample_name]]中的i)
规则bwa_运行:
消息:“正在运行BWA MEM”
输入:
全部输入
输出:“{output}{counter}”
运行:
shell(“bwamem{input}-t{threads}>{output}”)
它确实可以工作,但我需要在
规则all
中同时使用
{counter}
{output}
,如果没有这两个规则,我将无法访问
通配符。counter
。它还为
sample1
中的每个条目循环3次,并更改我的输出文件名。必须有更好的方法来做到这一点。 任何想法都将不胜感激。谢谢你

你需要进一步调查。您的配置不应该映射所有的值,像{output}{counter}这样的文件名将很难使用。对于3次复制,请尝试使用。如果您只使用bash命令,并且将输入函数放在更接近规则的位置,那么请使用shell指令。