EFETCH

https://img.shields.io/github/issues-pr/snakemake/snakemake-wrappers/bio/entrez/efetch?label=version%20update%20pull%20requests

Obtain data from NCBI and Genbank using Entrez efetch

URL: https://www.ncbi.nlm.nih.gov/books/NBK179288/

Example

This wrapper can be used in the following way:

rule get_fasta:
    output:
        "test.fasta",
    log:
        "logs/get_fasta.log",
    params:
        id="KY785484",
        db="nuccore",
        format="fasta",
        # optional mode
        mode=None,
    wrapper:
        "v3.8.0-1-g149ef14/bio/entrez/efetch"

Note that input, output and log file paths can be chosen freely.

When running with

snakemake --use-conda

the software dependencies will be automatically deployed into an isolated environment before execution.

Software dependencies

  • entrez-direct=21.6

Authors

  • Johannes Köster

Code

import subprocess as sp
import sys

if snakemake.log:
    sys.stderr = open(snakemake.log[0], "w")

cmd = ["efetch"]


def add_param(param, required=False):
    if snakemake.params.get(param):
        cmd.extend(["-" + param, snakemake.params[param]])
    elif required:
        raise ValueError("Missing required parameter: " + param)
    else:
        return []


add_param("id", required=True)
for param in ["db", "format", "mode"]:
    add_param(param)

with open(snakemake.output[0], "w") as out:
    sp.run(cmd, stderr=sp.STDOUT, stdout=out, check=True)