Hello @jbisanz,
Thank you very much for this tutorial.
I am having an issue when using qza_to_phyloseq. My 'phy' data is missing 1 sample; it contains 33 samples and there should be 34. This is the code I used:
Hi @helenaax2r,
I cannot speak to qiime2r specifically and will let @jbisanz reply but one possibility occurs to me. What does the header line of your sample metadata file look like? Does it begin with #SampleID? If so, try replacing with sample-id and see what happens... the former causes issues with R because the first line is interpreted as a comment line (but QIIME 2 can support multiple different formats — the #SampleID header line is a throwback from QIIME 1 that we support for backwards compatibility).
qiime2r may already check for and correct that issue — but pls give that a try. If it still does not work, let us know and we will see what @jbisanz has to say!
I too suspect that is the case regarding the second line defining the variable type. At some point I will try to bang out a new function to read qiime2 formatted metadata and preserve the data-types in a data.frame or tibble.
Can you confirm how many samples are in your table.qza artifact? Are you sure it was supposed to be 34? I am also aware there is an issue with the biomformat package in R that can cause issues if a sample has 0 counts.
I have pushed an update to qiime2R with a function called read_q2metadata() which will be used in qza_to_phyloseq() when the column specifications are found on the 2nd line of the file. Let me know if it works for you.
Thank you so much @Nicholas_Bokulich and @jbisanz for your fast responses!
I am sorry I didn't mention in my original post that I was using the table.qza and all files from the “Moving Pictures” tutorial, as suggested by the qiime2R tutorial.
I updated qiime2R and rerun it, and it works! I am now getting the same number of samples (34) by using the qza_to_phyloseq or the phyloseq method.
Thank you so much!
I still have a problem with the missing sample. If I leave in the # sign before SampleID, I get the following output with one sample missing as shown in the first part below. If I leave out the # sign before SampleID, I get an error as shown in the second part below. I have also attached my metadata file.met.tsv (570 Bytes)
Output with #SampleID in first line (missing sample 1)
I don't think your problem actually has to do with the header, I think the issue may lie in the fact that your sample names are only numbers. In my opinion nothing good can come from using numbers as sample IDs, I would recommend using something containing a more descript alpha-numeric unique identifier. It would appear based on my playing around that phyloseq does not take numbers as sample names so this is where your issue is. I would recommend reading your objects in separately, appending and appending something on like below:
#not actually tested, may need to fix a typo or two
table<-read_qza("table.qza")$data
meta<-read_q2metadata("met.tsv")
meta$SampleID<-paste0("Sample_", meta$SampleID)
colnames(table)<-paste0("Sample_", colnames(table))
#Then build your phyloseq object manually
Thank you for your help Jordan! When I try to build the phyloseq object manually, I get the following error after typing the command:
colnames(tax_table)<-c("Kingdom","Phylum","Class","Order","Family","Genus","Species")
Error in dimnames(x) <- dn :
length of 'dimnames' [2] not equal to array extent
I suspect this is because some of the entries in my tax_table go to only the genus level and some are unassigned. Anything I can do to make the above command work?
That sounds about correct, you could double check with length(colnames(tax_table)) or dim(tax_table). In this case, just remove the ,"Species" from your first line and the problem should be solved.
I have a similar error when I tried to read in my alpha diversity artifacts.
Could you please let me know how you resolved it?
shannon <- read_qza("shannon_vector.qza")
Error in scan(file = file, what = what, sep = sep, quote = quote, dec = dec, :
line 387 did not have 2 elements
Abby, I think your problem is quite different, my best guess is that it has something to do with odd characters in your samples names, or if your sample names are numbers. Can you create a copy of your artifact, change the name to shannon_vector.zip, unzip it, and then show me the top few lines of yourartifact/data/alpha-diversity.tsv?
hmm, nothing looks too strange, looking closer at the error, the issue is on line 387, is this the end of your alpha-diversity.tsv file? What are the sample names around this line?
shannon <- read_qza("shannon_vector.qza")
Error in scan(file = file, what = what, sep = sep, quote = quote, dec = dec, :
line 8 did not have 2 elements