Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

re-format taxonomy training data for use in R (dada2)? #2

Closed
maxfarrell opened this issue Jun 1, 2018 · 2 comments
Closed

re-format taxonomy training data for use in R (dada2)? #2

maxfarrell opened this issue Jun 1, 2018 · 2 comments

Comments

@maxfarrell
Copy link

Hi, I'm trying to re-format the training data to have 7 consistent taxonomy levels (Kindgom, Phylum, Class, Order, Family, Genus, Species), but I'm unsure how to parse the "mytaxon.txt" file or FASTA headers into a format that I can easily manipulate them in R.

Essentially, I want to use your database with the RDP classifier included with the DADA2 pipeline, but I need to reformat the sequence names to have this format.

Any thoughts or suggestions would be greatly appreciated, and thanks for all your work putting this reference DB together.

@maxfarrell
Copy link
Author

So I figured out a way to do this within R by directly manipulating the headers, and using a few system calls in bash. I thought I'd share in case others are interested.

# Starting with a separate file of headers speeds things up 
# (compared to reading from a system call directly)
system("grep  \">\" mytrainseq.fasta > headers.txt")
tax <- read.table("headers.txt", sep=";")
seqid <- sub(" .*$","", tax[,1])
tax[,1] <- sub("^.* ","", tax[,1])
tax <- cbind(seqid,tax)
names(tax) <- c("seqid","cellular","domain","kingdom","phylum","class","order","family","genus","species") 

seqnames <- with(tax, paste0(">",phylum,";",class,";",order,";",family,";",genus,";",species))
write.table(seqnames,file="dada2_headers.txt",sep="\n",row.names=FALSE, quote = FALSE, col.names=FALSE)

# generating dada2trainseq.fasta via bash
# modified from https://www.biostars.org/p/103089/ to also convert to uppercase nucleotides
system("awk 'NR%2==0' mytrainseq.fasta | tr [a-z] [A-Z] | paste -d'\\n' dada2_headers.txt - > dada2trainseq.fasta")

Likely this database is too large to properly allocate memory, but the dada2 developers are working on this. You can subset to a particular taxonomic group with grep or something similar in bash.

grep -A 1 "Chordata" dada2trainseq.fasta > dada2trainseq_chordata.fasta

@cjfields
Copy link

This is brilliant, thanks @maxfarrell !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants