我开始使用Snakemake,我有一个非常基本的问题,我无法在snakemake教程中找到答案.
我想创建一个单一的规则snakefile来逐个下载linux中的多个文件.'expand'不能在输出中使用,因为需要逐个下载文件,并且不能使用通配符,因为它是目标规则.
在我看来,唯一的方法是这样的东西不能正常工作.我无法弄清楚如何使用{output}将下载的项目发送到具有特定名称的特定目录,例如'downloaded_files.dwn',以便在后面的步骤中使用:
links=[link1,link2,link3,....]
rule download:
output:
"outdir/{downloaded_file}.dwn"
params:
shellCallFile='callscript',
run:
callString=''
for item in links:
callString+='wget str(item) -O '+{output}+'\n'
call('echo "' + callString + '\n" >> ' + params.shellCallFile, shell=True)
call(callString, shell=True)
Run Code Online (Sandbox Code Playgroud)
我很欣赏任何关于如何解决这个问题的提示以及我不太了解的蛇形部分.
我第一次使用snakemake 是为了使用cutadapt、bwa 和GATK(修剪;映射;调用)构建一个基本的管道。我想在目录中包含的每个 fastq 文件上运行此管道,而无需在蛇文件或配置文件中指定它们的名称或任何内容。我想成功地做到这一点。
前两个步骤(cutadapt 和 bwa/修剪和映射)运行良好,但我在使用 GATK 时遇到了一些问题。
首先,我必须从 bam 文件生成 g.vcf 文件。我正在使用以下规则执行此操作:
configfile: "config.yaml"
import os
import glob
rule all:
input:
"merge_calling.g.vcf"
rule cutadapt:
input:
read="data/Raw_reads/{sample}_R1_{run}.fastq.gz",
read2="data/Raw_reads/{sample}_R2_{run}.fastq.gz"
output:
R1=temp("trimmed_reads/{sample}_R1_{run}.fastq.gz"),
R2=temp("trimmed_reads/{sample}_R2_{run}.fastq.gz")
threads:
10
shell:
"cutadapt -q {config[Cutadapt][Quality_value]} -m {config[Cutadapt][min_length]} -a {config[Cutadapt][forward_adapter]} -A {config[Cutadapt][reverse_adapter]} -o {output.R1} -p '{output.R2}' {input.read} {input.read2}"
rule bwa_map:
input:
genome="data/genome.fasta",
read=expand("trimmed_reads/{{sample}}_{pair}_{{run}}.fastq.gz", pair=["R1", "R2"])
output:
temp("mapped_bam/{sample}_{run}.bam")
threads:
10
params:
rg="@RG\\tID:{sample}\\tPL:ILLUMINA\\tSM:{sample}"
shell:
"bwa mem -t 2 -R '{params.rg}' {input.genome} {input.read} | samtools view -Sb - > {output}" …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用执行以下操作的Snakefile:
rule split_files:
input:
'{pop}.bam'
output:
dynamic('{pop}_split/{chrom}.sam')
shell:
"something"
rule work:
input:
sam='{pop}_split/{chrom}.sam',
snps='snps/{chrom}_snps'
output:
'{pop}_split/{chrom}_parsed.sam'
shell:
"something"
rule combine:
input:
dynamic('{pop}_split/{chrom}_parsed.sam')
output:
'{pop}_merged.sam'
shell:
"something"
Run Code Online (Sandbox Code Playgroud)
这导致错误:
Missing input files for rule work:
snps/__snakemake_dynamic___snps
Run Code Online (Sandbox Code Playgroud)
将dynamic工作规则的两个输入相加会导致相同的错误。
我需要执行此操作,因为某些种群有chrY,而其他种群则没有,所以我不能仅仅通过染色体列表进行扩展(实际上我可以在当前正在使用的其他方法上进行扩增,但是这样做很麻烦)。
我在这里扯头发,希望有人可以帮助我。
运行snakemake 4.8.0
我有一个snakemake管道,它与两个conda env和--use-conda一起运行,并且在作为独立管道运行时可以正常工作。
但是,当我在集群上运行时,出现错误:
“'conda'命令在$ PATH中不可用。”
现在。Anaconda已安装在我们的集群上,但是我们需要使用以下命令在节点上激活它:
module load anaconda
Run Code Online (Sandbox Code Playgroud)
另外,模块被定义为一个函数,因此我首先要介绍一些东西。因此,在我的snakefile的顶部,我有:
shell.prefix("source $HOME/.bashrc; source /etc/profile; module load anaconda; )
Run Code Online (Sandbox Code Playgroud)
这不能解决问题。
我甚至把module load anaconda我的.bashrc,而且仍然无法正常工作。仅在群集执行时,我收到关于找不到conda的错误。
我的其他更改.bashrc都由snakemake提取,因此我不知道为什么它在conda上有问题。
我什至创建了一个conda env,将snakemake和conda加载到该env中,在提交脚本和Snakefile中激活该env:
shell.prefix("source $HOME/.bashrc; source /etc/profile; module load anaconda; source activate MAGpy-3.5; ")
Run Code Online (Sandbox Code Playgroud)
它仍然显示 “'conda'命令在$ PATH中不可用”。
从字面上把我的头发扯掉。
顺便说一句,我提交qsub -S /bin/bash并同时使用,shell.executable("/bin/bash")但是在其中创建的temp shell脚本由.snakemake运行/bin/sh-是预期的吗?
请帮我!
这个问题是我之前提出的一个问题,它涉及了解如何使用Snakemake正确访问配置文件。我有一个特定的问题,我需要首先解决,而在理解索引工作原理方面则是一个普遍的问题,其次我要问。
我正在使用snakemake进行运行,并从Alignment / QC到动机分析运行ATAC-seq管道。
答:具体问题
我正在尝试添加一条规则,trim_galore_pe以在对齐之前从我的fastq文件中修剪适配器,并从snakemake引发错误语句,因为生成的输出文件的名称与snakemake期望的名称trim galore不匹配。这是因为我无法解决如何在snakemake文件中正确写入输出文件语句以使名称匹配。
由TRIM GALORE包含SRA号生成的名称的示例,例如:
trimmed_fastq_files/SRR2920475_1_val_1.fq.gz
snakemake期望的文件包含示例引用,并且应显示为:
trimmed_fastq_files/Corces2016_4983.7B_Mono_1_val_1.fq.gz
这也会影响规则之后的后续规则trim_galore_pe。我需要找到一种方法来使用配置文件中的信息来生成所需的输出文件。
对于Snakefile中显示的规则之后的所有规则,我需要使用示例名称(即)来命名文件Corces2016_4983.7A_Mono。对于下面的Snakefile中显示的所有FAST_QC和MULTIQC规则,在输出文件名结构中具有示例名称也将很有用,它们在当前Snakefile中都已经执行了。
但是,Bowtie2,FASTQC规则的输入以及规则的输入和输出trim_galore_pe需要包含SRA编号。问题始于trim_galore并影响所有下游规则。
尽管我在以前的规则中已经提取了SRA编号,但是当不使用fastq_files配置文件中明确说明的文件夹时,我不确定如何执行此操作。通过引入trim_galore_pe规则,我已将一组新的SRA文件有效地移到了新文件trimmed_fastq_files夹中。如何从包含旧文件夹名称的SRA文件配置文件列表中仅提取SRA编号,同时引用trimmed_fastq_filesSnakefile中的新文件夹是我问题的症结所在。
我希望这很清楚。
这是我的配置文件:
samples:
Corces2016_4983.7A_Mono: fastq_files/SRR2920475
Corces2016_4983.7B_Mono: fastq_files/SRR2920476
cell_types:
Mono:
- Corces2016_4983.7A
index: /home/genomes_and_index_files/hg19
Run Code Online (Sandbox Code Playgroud)
这是我的Snakefile:
# read config info into this namespace
configfile: "config.yaml"
print (config['samples'])
rule all:
input: …Run Code Online (Sandbox Code Playgroud) 是否可以通过蛇形规则中的特定规则来限制要运行的作业数量?--jobs全局控制一次允许运行多少个作业,但是我想通过特定规则进行限制。
这是因为,我有一个特定的规则,该规则最多可以同时用于两个作业。但是,如果我设置--jobs为20,则会导致该特定规则中的工具崩溃。我在LSF群集中使用snakemake v5.2.0。
我有一个规则,它遍历文件会拉出 Fastq 文件路径并在 Fastq 文件上运行 trimGalore。但是,某些文件已损坏/被截断,因此 trimGalore 无法处理它们。它继续在剩余文件上运行,但整体规则失败并删除包含成功处理文件的输出文件夹。如何保留输出文件夹?
我尝试更改 shell 命令以忽略退出状态,但 snakemake 似乎set -euo pipefail在运行的 shell 元素中强制执行。
rule trimGalore:
"""
This module takes in the temporary file created by parse sampleFile rule and determines if libraries are single end or paired end.
The appropriate step for trimGalore is then ran and a summary of the runs is produced in summary_tg.txt
"""
input:
rules.parse_sampleFile.output[1]+"singleFile.txt", rules.parse_sampleFile.output[1]+"pairFile.txt"
output:
directory(projectDir+"/trimmed_reads/")
log:
projectDir+"/logs/"+stamp+"_trimGalore.log"
params:
p = trimGaloreParams
shell:
"""
(awk -F "," '{{print …Run Code Online (Sandbox Code Playgroud) 我正在使用 slurm 的 HPC 上运行一条蛇形管道。管道相当长,包含约 22 个步骤。定期,snakemake 在尝试提交作业时会遇到问题。这导致错误
sbatch: error: Batch job submission failed: Socket timed out on send/recv operation
Error submitting jobscript (exit code 1):
Run Code Online (Sandbox Code Playgroud)
我通过带有以下蛇形调用的 sbatch 文件运行管道
snakemake -j 999 -p --cluster-config cluster.json --cluster 'sbatch --account {cluster.account} --job-name {cluster.job-name} --ntasks-per-node {cluster.ntasks-per-node} --cpus-per-task {threads} --mem {cluster.mem} --partition {cluster.partition} --time {cluster.time} --mail-user {cluster.mail-user} --mail-type {cluster.mail-type} --error {cluster.error} --output {cluster.output}'
Run Code Online (Sandbox Code Playgroud)
这不仅会导致snakemake sbatch 作业的输出,还会导致snakemake 创建的作业的输出。上述错误出现在 sbatch 文件的 slurm.out 中。
错误指示的特定作业步骤将成功运行,并给出输出,但管道失败。作业步骤的日志显示作业 ID 运行没有问题。我在谷歌上搜索了这个错误,它似乎经常在 slurm 中发生,尤其是当调度程序处于高 IO 时,这表明这将是不可避免且经常发生的。我希望有人遇到过这个问题,并且可以提供解决方法的建议,这样整个管道就不会失败。
我有一个奇怪的问题,它来来去去,我真的不知道什么时候以及为什么。
我正在运行这样的蛇形管道:
conda activate $myEnv
snakemake -s $snakefile --configfile test.conf.yml --cluster "python $qsub_script" --latency-wait 60 --use-conda -p -j 10 --jobscript "$job_script"
Run Code Online (Sandbox Code Playgroud)
我在 conda 环境中安装了 snakemake 5.9.1(也尝试降级到 5.5.4)。
如果我只运行这个命令,这工作正常,但是当我将此命令 qsub 到我正在使用的 PBS 集群时,我收到一个错误。我的 qsub 脚本如下所示:
#PBS stuff...
source ~/.bashrc
hostname
conda activate PGC_de_novo
cd $workDir
snakefile="..."
qsub_script="pbs_qsub_snakemake_wrapper.py"
job_script="..."
snakemake -s $snakefile --configfile test.conf.yml --cluster "python $qsub_script" --latency-wait 60 --use-conda -p -j 10 --jobscript "$job_script" >out 2>err
Run Code Online (Sandbox Code Playgroud)
我得到的错误信息是:
...
Traceback (most recent call last):
File "/path/to/pbs_qsub_snakemake_wrapper.py", line 6, in <module>
from snakemake.utils …Run Code Online (Sandbox Code Playgroud) 我在建设有一个管道snakemake,并使用conda和singularity环境以确保可重复性。我遇到了一个错误,我的绘图上的文本被矩形替换

在 Linux 和 Mac 系统上试验管道并禁用奇异容器后,问题似乎源于缺少字体库,因为当我仅在 Mac 上仅使用conda( --use-conda)运行管道时,文本绘制正常。
奇点容器是从这个使用 Debian GNU/Linux 的miniconda docker镜像构建的。我设法创建了一个最小的示例管道,其中没有绘制文本。
# Snakefile
singularity: "docker://continuumio/miniconda3"
rule all:
input:
"mtcars-plot.png"
rule plot_mtcars:
output:
"mtcars-plot.png"
conda:
"minimal.yaml"
script:
"mtcars-test.R"
Run Code Online (Sandbox Code Playgroud)
# mtcars-test.R
library(ggplot2)
png("mtcars-plot.png")
ggplot(mtcars, aes(factor(cyl), mpg)) + geom_boxplot()
dev.off()
Run Code Online (Sandbox Code Playgroud)
# minimal.yaml
channels:
- bioconda
- conda-forge
- defaults
dependencies:
- r-base =3.6
- r-ggplot2
Run Code Online (Sandbox Code Playgroud)
要绘制断开的图,请运行管道
snakemake --use-conda --use-singularity
Run Code Online (Sandbox Code Playgroud)
在 Debian GNU/Linux 上使用 R 正确绘制文本时,我可能缺少哪些软件包/库?