Qiime2r missing sample

Yes! Editing the Bob II.R fixed it.
Thanks so much for all your help. I really appreciate it.

1 Like

Hi,
I am facing a similar problem when importing my metadata. I've tried all the suggestions but still didn't find a solution for the problem.

metadata<-read_q2metadata("metadata4b.tsv")
Error in read_q2metadata("metadata4b.tsv") :
Metadata does not define types (ie second line does not start with #q2:types)

I have a metadata table with 74 samples. The first row are the identifiers of each column.
When I import using this command: metadata<-read.table("metadata4b.txt"), it works but it says that I have 75 observations instead of 74.

Then when I go on to generate some graphics I always get errors messages which I believe is because of this.

For example, when I try to generate barplots using this command:

metadata %>%
filter(!is.na(shannon)) %>%
ggplot(aes(x=season, y=shannon, fill=season)) +
stat_summary(geom="bar", fun.data=mean_se, color="black") + #here black is the outline for the bars
geom_jitter(shape=21, width=0.2, height=0) +
coord_cartesian(ylim=c(2,7)) + # adjust y-axis
facet_grid(~species) + # create a panel for each body site
xlab("Antibiotic Usage") +
ylab("Shannon Diversity") +
theme_q2r() +
scale_fill_manual(values=c("cornflowerblue","indianred","chocolate")) + #specify custom colors
theme(legend.position="none") #remove the legend as it isn't needed
ggsave("../../../images/Shannon_by_abx.pdf", height=3, width=4, device="pdf") # save a PDF 3 inches by 4 inches

I get this error:

Error: Problem with filter() input ..1.
x Input ..1 must be of size 75 or 1, not size 74.
i Input ..1 is !is.na(shannon).
Run rlang::last_error() to see where the error occurred.

Thank you,
Danilo

Hi,
I'm having the same problem too. I wanted to generate a heatmap.
image

Please help. Thank you!

Suet Li

Hey @suetli19, You can use two methods to solve this

  1. using manual method ( by adding an new row in excel and mentioning whether the data is categorical or numerical) and import it (or)
  2. use metadata<-readr::read_tsv("path of the file")
    For Reference check this link. Hope this helps

Best,
Sreevatshan

1 Like

Sreevatshan is on the money.

To be more clear on the conceptual side, read_q2metadata() is specifically designed for the q2 metadata format wherein the second line contains the data types (which starts with #q2:types. The error message you were both receiving is the result of the second line of your metadata not containing that definition line, and thus, not being appropriate for loading with read_q2metadata(). As such you can use any function to read your metadata (of which read_tsv is my favourite!).

If you try to read a q2 metadata file using read_tsv() you will see that it imports the definition line as its own sample with the id #q2:types which is probably not desirable in many cases.

Note @Danilo_Reis, in your example of using read.table() as opposed to read_tsv() you need to be sure to indicate that your columns have names as below. I would also specify that it is tab (\t) separated just to be safe:

read.table(“metadata4b.txt”, header=TRUE, sep="\t"),
2 Likes

Hi @Sreevatshan,
I added a new row using the manual method, and now it works!
Thank you so much!

Best regards,
Suet Li

1 Like

Hi @jbisanz ,
Thanks for your reply! It finally worked! :slight_smile:
But I still get some error messages when I try to generate the graph you show in your tutorial.
I am using this command to generate bar plots (shannon diversity in three seasons - spring, summer, autumn grouped by each plant species (A,B,C and D).

Do you have any idea what can be the reason?

metadata %>%
filter(!is.na(shannon)) %>%
ggplot(aes(x=season, y=shannon, fill=season)) +
stat_summary(geom=“bar”, fun.data=mean_se, color=“black”) + #here black is the outline for the bars
geom_jitter(shape=21, width=0.2, height=0) +
coord_cartesian(ylim=c(2,7)) + # adjust y-axis
facet_grid(~species) + # create a panel for each body site
xlab(“Seasons”) +
ylab(“Shannon Diversity”) +
theme_q2r() +
scale_fill_manual(values=c(“cornflowerblue”,“indianred”,“chocolate”)) + #specify custom colors
theme(legend.position=“none”) #remove the legend as it isn’t needed
ggsave("…/…/…/images/Shannon_by_abx.pdf", height=3, width=4, device=“pdf”) # save a PDF 3 inches by 4 inches

Don’t know how to automatically pick scale for object of type data.frame. Defaulting to continuous.
Error: Aesthetics must be either length 1 or the same as the data (74): y

Is shannon a column in your metadata table, or is it a separate table? It needs to be a column which might require joining metadata and shannon.

Hi @jbisanz ,
Now it worked! :slight_smile: I don’t know why but it generated a “shannon” column in the medatada but with a different name (shannon_entropy). That`s the reason why the last command was not working.

Thanks a lot!

2 Likes

How can you change the error in the shannon_vector.qza? I found my problem, but I don't know how to change it in the original file.

An off-topic reply has been merged into an existing topic: Qiime2R error while creating point and line plot

Please keep replies on-topic in the future.