объединение результатов ABRICATE csv в файл snakemake - PullRequest
0 голосов
/ 28 марта 2020

Я хотел бы объединить результаты нескольких файлов CSV из программы ABRICATE (github.com/tseemann/abricate) в один файл CSV.

Следующий snakefile запускает папку с файлами fasta, создавая отдельные csv для каждого fast. Я хотел бы объединить эти результаты в один CSV-файл, но не уверен, как создать «все правила».

Есть предложения?
Ниже мой рабочий файл змеи. Спасибо

########################### snakefile making dictionary
import os
import yaml

file_list = []
### location assumes that data is in results_fasta/ folder
for entry in os.scandir("results_fasta/"):
    if entry.is_file():
        file_list.append(entry.name)

#### this tells split the file for use in dictionary creation
config_dict = {"samples":{i.split(".")[0]:"results_fasta/"+i for i in file_list}}

with open("config_abricate_resfinder.yaml","w") as handle:
    yaml.dump(config_dict,handle)

###### dictionary created using all files located in results_fasta folder
configfile: "config_abricate_resfinder.yaml"

##### not needed but used to say what is currently running
print("Starting abricate workflow")

##### rule all is a general rule that says this is the results we are lookin for in the end.
rule all:
    input:
        expand("abricate_resfinder/{sample}_abricate_resfinder.csv", sample = config["samples"])

##### Abricate resfinder
rule resfinder:
    input:
        lambda wildcards: config["samples"][wildcards.sample]
    params:
        db_resfinder = "leaveblank",  ### for resfinder DB is default so leave blank
        type = "csv"
    output:
        res = "abricate_resfinder/{sample}_abricate_resfinder.csv",
######## log file is empty.  need to print stdout to log
    log:
        "logs/{sample}_resfinder.log"
    shell:
        "abricate {input} --{params.type} > {output.res}"

1 Ответ

0 голосов
/ 29 марта 2020

Если файлы не имеют заголовков и совпадают поля, объединение может быть выполнено командой cat:

rule all:
    input:
        expand("abricate_resfinder/{sample}_abricate_resfinder.csv", sample = config["samples"])
    output:
        out.csv
    shell:
        "cat {input} > {output}"

Если есть заголовки, вам нужно сначала подумать, какой результат вам действительно нужен. Простейшим было бы вообще удалить все заголовки. Вы можете попробовать это:

    "cat {input} | sed '/^#/d' > {output}"
...