Qiime2r missing sample

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

1 Like

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.

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,

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

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


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"),

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!


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.

Dear @jbisanz @Nicholas_Bokulich,
I'm also following the qiime2R tutorial. But in the step of creating a point and line plot. I have errors, and I'm not understanding how to solve this.

The metadata I'm using is
final_metadata.tsv (211.7 KB)

And the shannon_vector.qza file is,
shannon_vector.qza (160.5 KB)
after running the following code,

#Code for moving the sample names to a new column that matches the metadata sample_id
shannon<-shannon$data %>% rownames_to_column("SampleID")
#This allows shannon and metadata to be merged

Following shannon table is created.

Now the problem is when I'm trying to run the following code,

metadata %>%
  filter(!is.na(shannon)) %>%
  ggplot(aes(x=`Age [sample]`, y=shannon, color=`BMI_class [sample]`)) +
  stat_summary(geom="errorbar", fun.data=mean_se, width=0) +
  stat_summary(geom="line", fun.data=mean_se) +
  stat_summary(geom="point", fun.data=mean_se) +
  xlab("AGE") +
  ylab("Shannon Diversity") +
  theme_q2r() + # try other themes like theme_bw() or theme_classic()
  scale_color_viridis_d(name="BMI") # use different color scale which is color blind friendly
  ggsave("Shannon_by_time.pdf", height=3, width=4, device="pdf") # save a PDF 3 inches by 4 inches

the error showing is this,

Error in `filter()`:
ℹ In argument: `!is.na(shannon)`.
Caused by error:
! `..1` must be a logical vector, not a logical matrix.
  1. metadata %>% filter(!is.na(shannon)) %>% ...
 10. dplyr:::dplyr_internal_error(...)

Can you or anyone please tell me what is I'm missing here?