EFETCH
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.9.0-14-g476823b/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
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)