Converting mothur's groups and names files into Unifrac sample ID mapping file

393 views
Skip to first unread message

Roey Angel

unread,
May 31, 2012, 10:32:01 AM5/31/12
to qiime...@googlegroups.com
Hi,
Does anyone here have a script (perl/ python) for converting mothur's groups and names files into Unifrac sample ID mapping file?

Thanks in advance,
Roey

Greg Caporaso

unread,
Jun 1, 2012, 4:12:26 PM6/1/12
to qiime...@googlegroups.com
Hi Roey,
We don't have anything like that in QIIME, but would be interested in
incorporating it if someone from the user community wants to
contribute one. On a related note, mothur now supports the biom
format, so it should be easy to move otu tables back and forth between
the tools.

Greg

Roey Angel

unread,
Jun 7, 2012, 12:17:29 PM6/7/12
to qiime...@googlegroups.com
Hi Greg,
Thanks for your reply.

For the R users, here's a quick function that would convert mothur's .count file (the output of count.seqs) to UniFrac sample ID mapping file.

in mothur, run something like
count.seqs(name=final.names, group=final.groups)

then in R

Counts2ID <- function(data, filename = "sample", convert = FALSE) {
  require(reshape2)
  sample.ID <- subset(data, select = -c(total)) # remove column 'total'
  sample.ID <- melt(sample.ID, id = "Representative_Sequence") # melt data frame
  names(sample.ID) <- c("Sequence.ID", "Sample.ID", "Sequence.abundance") # rename variables
  sample.ID <- sample.ID[sample.ID$Sequence.abundance > 0, ] # remove 0 values
  sample.ID <- sample.ID[order(sample.ID$Sequence.ID), ]
  write.table(sample.ID, file = paste(filename,".ID",sep = ""), quote = FALSE, sep = "\t", col.names = FALSE, row.names = FALSE)
  return()
}

filename <- "final.seq.count"
data <- read.table(filename, header=T) # read file
Counts2ID(data, filename)

I would've loved to contribute but haven't had the chance to properly learn python till now.

Roey

Greg Caporaso

unread,
Jun 7, 2012, 4:36:01 PM6/7/12
to qiime...@googlegroups.com
Thanks Roey!

Greg
Reply all
Reply to author
Forward
0 new messages