-
Notifications
You must be signed in to change notification settings - Fork 0
/
tables
36 lines (27 loc) · 1.14 KB
/
tables
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
#load sequence table
sequencetable.nochim <- readRDS("sequencetable.nochim.rds")
#create ASV fasta file
#store sequences and asv headers to use in manipulating tables
asv_seqs <- colnames(sequencetable.nochim)
asv_headers <- vector(dim(sequencetable.nochim)[2], mode = "character")
#format headers for fasta file
for (i in 1:dim(sequencetable.nochim)[2]) {
asv_headers[i] <- paste(">ASV", i, sep = "_")
}
#create and write fasta table with sequences for each ASV
asv_fasta <- c(rbind(asv_headers, asv_seqs))
saveRDS(asv_fasta, "ASV_fasta.rds")
write(asv_fasta, "ASVs.fa")
#create counts table by transposing sequence table and changing row names
asv_tab <- t(sequencetable.nochim)
row.names(asv_tab) <- sub(">", "", asv_headers)
write.table(asv_tab, "ASV_counts.tsv", sep = "\t", quote = F, col.names = NA)
#create taxonomy table
# remove > from headers
asv_headers_tax <- sub('.', '', asv_headers)
taxonomy <- readRDS("taxonomy.rds")
#change row names from sequences to ASV numbers
rownames(taxonomy) <- asv_headers_tax
write.table(taxonomy, "ASV_taxonomy.tsv", sep = "\t", quote = F, col.names = NA)
module load R
Rscript --no-save ~/scripts/tables.R