-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathGenerateSeqTables.R
38 lines (31 loc) · 1.32 KB
/
GenerateSeqTables.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env Rscript
suppressPackageStartupMessages(library(dada2))
suppressPackageStartupMessages(library(ShortRead))
seqtab <- readRDS("${st}")
if (as.logical('${params.sampleRegex}' != FALSE )) {
rownames(seqtab) <- gsub('${params.sampleRegex}', "\\\\1", rownames(seqtab), perl = TRUE)
}
# Generate table output
write.table(data.frame('SampleID' = row.names(seqtab), seqtab),
file = 'seqtab_final.txt',
row.names = FALSE,
col.names=c('#SampleID', colnames(seqtab)), sep = "\\t")
######################################################################
# Convert to simple table + FASTA, from
# https://github.com/LangilleLab/microbiome_helper/blob/master/convert_dada2_out.R#L69
######################################################################
# Generate OTU table output (rows = samples, cols = ASV)
write.table(data.frame('SampleID' = row.names(seqtab), seqtab),
file = 'seqtab_final.simple.txt',
row.names = FALSE,
col.names=c('#SampleID', colnames(seqtab)),
sep = "\\t")
# Generate OTU table for QIIME2 import (rows = ASVs, cols = samples)
write.table(
data.frame('Taxa' = colnames(seqtab), t(seqtab), check.names = FALSE),
file = 'seqtab_final.simple.qiime2.txt',
row.names = FALSE,
quote=FALSE,
sep = "\\t")
# Write modified data
saveRDS(seqtab, "seqtab_final.simple.RDS")