dada2 dada2 add-species

dada2 add-species

Version:
1.16
Identifier: TL_cbf4cc_da.69
Tool
1# __author__ = "Charlie Pauvert"
2# __copyright__ = "Copyright 2020, Charlie Pauvert"
3# __email__ = "cpauvert@protonmail.com"
4# __license__ = "MIT"
5
6# Snakemake wrapper for adding species-level 
7# annotation using dada2 assignTaxonomy function.
8
9# Sink the stderr and stdout to the snakemake log file
10# https://stackoverflow.com/a/48173272
11log.file<-file(snakemake@log[[1]],open="wt")
12sink(log.file)
13sink(log.file,type="message")
14
15library(dada2)
16
17# Prepare arguments (no matter the order)
18args<-list(
19           taxtab = readRDS(snakemake@input[["taxtab"]]),
20           refFasta = snakemake@input[["refFasta"]]
21           )
22# Check if extra params are passed
23if(length(snakemake@params) > 0 ){
24       # Keeping only the named elements of the list for do.call()
25       extra<-snakemake@params[ names(snakemake@params) != "" ]
26       # Add them to the list of arguments
27       args<-c(args, extra)
28} else{
29    message("No optional parameters. Using default parameters from dada2::addSpecies()")
30}
31
32# Learn errors rates for both read types
33taxa.sp<-do.call(addSpecies, args)
34
35# Store the taxonomic assignments as a RDS file
36saveRDS(taxa.sp, snakemake@output[[1]],compress = T)
37
38# Proper syntax to close the connection for the log file
39# but could be optional for Snakemake wrapper
40sink(type="message")
41sink()
42