qiime2R visualization error message

Hi all,

I am using qiime2R to make some plots for my 16s data in R, and I am following the tutorial found in this forum:

But when I am creating phyloseq object from QIIME2 artifacts, an error came up:

Error in file(con, "r") : cannot open the connection

All these artifacts were imported into R successfully (in my opinon). Here is the commands I used to create the phyloseq:

pilot_physeq=qza_to_phyloseq("pilot_table_group.qza", "pilot_rooted-tree.qza", "pilot_taxonomy.qza", "metadata2_gorup")

Thank you in advance for your attention and help. I am not sure if it is appropriate to post the question here in this forum, because it is related to R, but also QIIME2R. But please correct me if this is something inappropriate.

Thanks again!

Could be two possibilities:
1- One or more of your files is not present, my intuition is “metadata2_gorup”, you can always use list.files() to see which files are present in your working directory.
2- It could be the order of the files. If you check the help (?qiime2R::qza_to_phyloseq), the expected order is features, tree, taxonomy, metadata. If you do not feed them in this order, you will need to specify as below:

pilot_physeq<-qza_to_phyloseq(
     features="pilot_table_group.qza", 
     tree="pilot_rooted-tree.qza", 
     taxonomy="pilot_taxonomy.qza", 
    metadata="metadata2_gorup"
)

Hopefully one of these solutions is correct, please let me know!

Jordan

Hi @jbisanz,
Thank you for your reply. Unfortunately, neither worked. I checked the presence of the files using list.files() and they are all in my folder.
As for the order of the artifacts, I have been using it in the same order you suggested, that is feature-tree-taxonomy-metadata. I also ran the command the other way, like

pilot_physeq<-qza_to_phyloseq(
     features="pilot_table_group.qza", 
     tree="pilot_rooted-tree.qza", 
     taxonomy="pilot_taxonomy.qza", 
    metadata="metadata2_gorup")

But did not work either. I was also wondering why the .qza is still needed in the script? Once these qiime2 artifacts are imported to R, R will be using the imported files (not .qza anymore literally) for further analysis, right? Or does R still retrieve data information back from the original qza file in my home directory? With this thought, I also ran the commands without adding .qza at the end of the file name. But did not work either. Any other possibilities? thank you very much for your time.

Ps: “did not work” here means the same error message returned.

Best

Ahh, I think I understand now. The qza_to_phyloseq function is a wrapper that uses read_qza function to separately read the artifacts from file, and then read.table to read in the metadata file separately. I imagine the issue then is that metadata2_gorup is an object in R, rather than a tsv file. You may instead make the phyloseq object the old fashion way which using the phyloseq() function specifying the otu_table, phy_tree, tax_table, and sample_data as are appropriate for your data.

Hi @jbisanz,
I am sorry for my delay. Thank you very much for your reply. The original metadata.tsv file was imported using read_tsv as written in your tutorial. The first row of the metadata was deleted and the modified metadata was named as metadata2_group. A phyloseq object was created when I reran the command using original metadata.tsv, and it worked! But this is not what I actually wanted. I have been trying to run grouped feature table using grouped metadata file. So when I ran:

pilot_physeq=qza_to_phyloseq("pilot_table_group.qza", "pilot_rooted-tree.qza", "pilot_taxonomy.qza","metadata_group.tsv")

It gave me an error:

Error in validObject(.Object) : invalid class “sample_data” object: Sample Data must have non-zero dimensions.

I am not sure if this is the way people group their samples when they have biological replicates for samples. What I did is to get grouped feature table in QIIME2, and then create a new metadata with sample names updated as group name. I have only sample-id column, since I don’t have other variable (only “group”). So when I tried to create phyloseq using grouped feature table and metadata file, it showed me the error above. Could you please give some suggestions on this? Thank you very much!

Could you send me the artifacts and I can take a closer look?

I don’t know exactly your study design, but I generally would not recommend grouping your biological replicates. If there is some sort of nested design, I think you should try to use stat approaches that account for this.

Fore sure. I am attaching several things here. I really appreciate that you could take a closer look into my question. Briefly, I would like to do community compositional analysis of oral microbiota using 16s sequencing. I used qiime 2 for QC and basic analysis. I have 24 samples in total, some have no replicates, some have 2,3 or 6 replicates, due to sample availability. Regardless of the fact, I still wanted to do all analysis including all possible replicates. I have only 1 variable, that is “Group” as follows, and I grouped my feature table using “qiime feature-table group” function.

![40%20PM|240x500](upload://2kmqloVaOeP14g8AElSenlnDhLx.png) 

The reason of my using “feature-table group” is that when I plotted taxa-bar-plot using phyloseq in R, the relative abundance for each group was different from each other. Data for each replicates were stacked up, not averaged. Like this:

![12%20PM|690x251](upload://eoOi0n00mFOnHlmFEYQcPoCtKL0.png) 

All bars should be stretched up to 100% on y axis, but my bar plot did not, since the group with 6 replicates reached 600% and the group with 2 replicates reached 200%, and so on. Since I am doing relative abundance, no matter what the abundance is, the max relative abundance for each group should be 100%, no more than that. Because this is microbiota data, which is compositional, I thought it is inappropriate to take average of the OTU/sequence number for replicates and plot that in the final bar graph. tha’s why I tried to use “qiime feature-table group” and and get a separate table_group.qza for my data. No matter the feature is grouped or not, they should have the same taxonomy.qza and root-tree.qza. So what I am attaching here are:

pilot_table.qza (ungrouped OTU table)
pilot_table_group.qza (grouped)
pilot_taxonomy.qza
pilot_root-tree.qza
metadata.tsv (metadata for ungrouped feature table)
metadata_group.tsv (metadata for grouped feature table)

That’s why I wanted to create another phyloseq object using pilot_table_group.qza and metada_group.tsv, and it did not work. if this is not the right way to do the job, could you please suggest anything? thanks so much!
metadata_group.tsv (90 Bytes) metadata.tsv (509 Bytes) pilot_rooted-tree.qza (46.5 KB) pilot_table_group.qza (33.0 KB) pilot_table.qza (29.7 KB) pilot_taxonomy.qza (49.5 KB)

I can’t see the images I uploaded after posing on my end. Please let m know if you can’t see them either. Thanks!

I believe the issue lies in not in having a column describing the group and that the sample name and group were one and the same. This fixes it for your group metadata:

sample-id	group
#q2:types	categorical
GF	GF
OG_VF	OG_VF
OG_FC	OG_FC
inoc_VF	inoc_VF
ExNeg	ExNeg
inoc_FC	inoc_FC
Colony	Colony
Conventional	Conventional
NTC	NTC

I’ve gotcha re the grouping, in this case it makes sense but careful in the interpretation of true differences from this plot.

Hi @jbisanz,
It worked well. Thank you for very much for your help. Much appreciated.

Best.

Hi @jbisanz,
At the very end of your qiime2R tutorial, I was directed to MicrobeR tutorial. I am still using the same set of data, hoping to make some bar plots as in your tutorial, while got stuck in the summarize.taxa step. I ran following commands:

summarized.taxa=Summarize.Taxa(pilot_table_group, pilot_taxonomy)

and got following error message:

Error in TAXONOMY[rownames(FEATURES), ] : incorrect number of dimensions

I thought this might be caused by the taxonomy column, which is not separated into “kingdom”, “phylum”…“Species”. So I ran the commands to separate the taxon column in taxonomy file following your way mentioned in your qiim2R tutorial, and it worked. The new taxonomy file was “taxtable”. Then, I rerun the command using taxtable instead:

summarized.taxa=Summarize.Taxa(pilot_table_group, taxtable)

then I got another error message:

Error in gsum(FEATURES) : GForce sum can only be applied to columns, not .SD or similar. To sum all items in a list such as .SD, either add the prefix base::sum(.SD) or turn off GForce optimization using options(datatable.optimize=1). More likely, you may be looking for 'DT[,lapply(.SD,sum),by=,.SDcols=]'
6.
gsum(FEATURES)
5.
gforce(thisEnv, jsub, o__, f__, len__, irows)
4.
`[.data.table`(SUMMARIZED.TAXA[[level]], , lapply(.SD, sum), by = TaxaString)
3.
SUMMARIZED.TAXA[[level]][, lapply(.SD, sum), by = TaxaString]
2.
as.data.frame(SUMMARIZED.TAXA[[level]][, lapply(.SD, sum), by = TaxaString])
1.
Summarize.Taxa(pilot_table_group, taxtable)

could you please let me know what happened for this step and how this could be fixed? Thank you very much.

Can you post the output of the following:
head(pilot_table_group) and head(taxtable)?

Hi @jbisanz,
Here is the output for head(pilot_table_group)

> head(pilot_table_group)
$uuid
[1] "b77d4a10-6277-42e2-97b9-c30b38c34ddf"

$type
[1] "FeatureTable[Frequency]"

$format
[1] "BIOMV210DirFmt"

$contents

$version

$data
                                   GF OG_VF OG_FC inoc_VF ExNeg inoc_FC Colony
45ddbfd3d07aee0fd8143d09b2af14e8 2471 15156  5222    2368  1867       3      0
fb96c296bb4e6ac1e8260adb3c188be3  112  1141   468    5125  4265      50  15209
1049d7d17f5ca428dbcd5377f18d7da7 1350  6885  1555    1986  1200       0      0
84975317a8c1172222f4302fcede7639 1049  4105  1770     869   524       0      0
ab7e61945bab3909f50909c32c7068ad 1165  2926   972     796   564       0      0
5a321c0b774bd4bbcdfe17d2fa42ceb6    0  3781   824      67     0     275   1360
5dd54d2191324443e4f4dfad53f22aff  292  1598   773     559   389       0      0
79e6c1edd3ef4d7eeaab1df31f92a9fb   26    98    76     150    51       0      0
a6dc0c1c93445042a671d97b01834f7b  107   474   316     229    89       0      0
fc185378fbec874b1fdd9a09ce4134af  245   798   369     156     0       0      0
1f62f14c6d32bab284a1f4ddb7ef0f86  185   755    75     137   334       0      0
eb6f1ef8123a3f39fde80a286a0552a6    0    15     0       5     0    1784      0
c1f442f804c9daaa63de92c3b9479418    0     0     0       0     0    1764      0
b3100bb7c50c79d5e6b7d83c8b63bf86  165   644   469      43    92       0      0
050a2913232d49c6c3d64a75ed1ab9f8  125   709   357      11    12       0      0
da70fcb2e98db9b733090cf3976926c3    0     0     0       0     0    1442      0
49daf5febec9796bf7fa98ce1e5484ee  272   460   189     243    69       0      0
e9efa56e056bfac022c545d7eddb0d5e   98   349   336      83   264       0      0
762d97a48eb326b75467dc9905535763  289   527   140     136    73       0      0
3ac144ca9124a4ed17778d567cf81cf5    0     0    52       0     0    1127      0
c76a04b13ea1daa6e86b6fb905541926  157   510    50     154    67       0      0
901917c888efcf0dc8c8d3ff1c59f2d0   71   316     0      56    94       0      2
25fd33feb5344f76bc1c4aa542c0a948  194   228   140      32     0       0      0
7f968afc9874c3c3c21c2c0a8bcf466d    0     0     0       0     0     924      0
64ae4ca85d86e50579a0ce888c70216f   16   242   220      98   122       0      0
b8788a9179a3e68d957c1384196c098b    0   353   139     142     0       0      0
dd65e2c3ca1f8466840f7e362557d8c0    0     0     0       7     0     804      0
2142a68611b23113dd0a8843bbcca774    0   795     0       0     0       0      0
e7cc229c19773ba9e802e09a129e560c    0     0     0     161     0       0    245
5704ebb9634fcf0c0ccaa7078fff5928  189   129    10     194     7       0      0
c2f01b197e7bd96d0008e4dceabc3b45    0     0     0       0     0     635      0
f638f61e23a2f0e6f0ed7ec9fca673c9   14   277   122      23     0       0      0
3a8d9d81c680ff3572a8fd072fd67198   93   101    20     331     0       0      0
08b4507f69b58ecc43ce91b3e9ff2b6f    0     0     0     118   330       0      0
aea3e38015c19e8f1d34dadddbc6e5cc   70   166    11     120    26       0      0
bc594caab289baa949fb4e2136cf4b36  138   180     0       0     0       0      0
f235b287e85f12f4211d60379905788a    0     0     0       0     0     376      0
17038ca085a43eed78b8c3ea9ebebe0a    0     0     8       0     0     328      0
955c450f208dff9351630a5fcc7706dc    3   180     0      33     0       0    115
f9eec41e23afbd9931b18013abe9e2b9    0   334     0       0     0       0      0
fa5c17f3c93a6c7791a6fe82402be5cf    0     0   229      66     0       0      0
4a3509111348f231de7288f90725730d    0    71     0       0     0     219      0
8ce909427a3147618d2e6557af708d74    0     0     0       0     0     284      0
f33c1ca6142229599fbd1700ac708c25   39   167    52       0     0       0      0
f2058e14b6a7601639b33c49cdb9583b    0     0     0       0     0       0    101
ad31f30a6d504fa8a27ea6726d175e77    0    38     0     196     0       0      0
2b2c0381f8d9a95c1b5c377e8ab5ffbe   22    43    13       9     4       0      0
e9f0d42c7d96c0b524054456f75e7c97   62     0   143       0     0       0      0
259efc442fb9bb1ae37be2c0270f0347    0     0     0       0     0     200      0
b9066f213cba9c0fcc4be3e0b28e08e1    0     0     0       0     0     196      0
bb66d560a170d917b2ce4b965e86ed49    0     0     0       0     0     196      0
edb9f3d53d3b0f582bcfc1972416bc51   20     0     0       0     0       0      0
95e2d0006c1797d72b926c619fa9d296    0   177     0       0     0       0      0
c6bcd092c661f880891f9c8d603b876c    0     0     0       0     0       0      0
e860e045c92ccc9246953926d07afbc0    0   155     0      14     0       0      0
54dee059e7bc541a213110698fef220f    0    21     7      41    98       0      0
d9a5f1de36b21f8b36326e8e6fc223a4    0     0     0      23     0     144      0
e8001767a006455ff8dd21b023d0913c    0     0     0       0     0       0      0
d89b319c95fffe32fda4f2f495ba7da0    0     0     0       0     0     159      0
52f4e61c8167fa140d7d71fba699c8e5    0   134     0       9    15       0      0
e5c4c38e6d4fd954fd42054096ee3126    0     0     0       0     0     157      0
6ef4d7123e307c829be3d10bbb20c176    0     0     3       0     0     146      0
b04341da7640e25caae082aff32853c3    7    87     0      37     9       0      0
af9658d3e891e36b7163b3fbf63d7a3c    0     0   137       0     0       0      0
6a7e30492d38e32b30ccf26f1ce6bc2a   17    76     0      22     8       0      0
15812bce78196981b7495375da36d5ed  130     0     0       0     0       0      0
92961bdffd4b23974c855de660b35d4a    0   130     0       0     0       0      0
298708eaeda166f87b4d55264cbe2990    0     0     0      35     0      92      0
8bfe6e9c6476e7e4a41a11c1b9c2ea5e    0     0     0       0     0       0      0
27daa3126720edd2f2ba6a48023ec8dc    5     0     0      43    71       0      0
8534cf00464fb4c071d860204633bcc4    0    83     0       0     0      34      0
a6099aa64bbe5dfc9eaf388a5b699bc1    0   117     0       0     0       0      0
0118e7559010fb5b7793cb79bf1eb381    0     0     0       0     0       0      0
403733ed4c0ebc812b5a081a1ab4928f    0     0     0     115     0       0      0
ad148e740b454eff45dc3f5e571eb963    0     0     0      24    89       0      0
fb1f8ad47be563788d40068587c67600   97     0     0      15     0       0      0
bce30a861ebdf3f123960c33d7206916    0     0     0       0     0     109      0
35ccea46b68bc086686f0a82870d81b0    0     0     0     108     0       0      0
08eee3ea7487ba50f3a162a2f28f2b33    0     0     0      33    73       0      0
f5b1aca35145dd7a81706e08ce599863    0     0     0      14    91       0      0
ea0e6b7f76733ad4ad2a3e4c49bd3a0c    0     0     0     102     0       0      0
eebceaafa0029010b406bd8967daadf2    0    37    63       0     0       0      0
5a59fb55239c752b4f8874047d281cd6    0     0     0      34    59       0      0
7fa4b88873c4ce054fdb3aadfdbb5bdb    0    87     0       0     0       0      0
30df4be2be3443caf34ec51a24b4205d    0    87     0       0     0       0      0
51e5f648518612ffc8912fdb68fa3880    5     0     0      34    43       0      0
becd70c1d0596316baea16282dcaafe3    0     0     0       0     0      82      0
7a75be15a04722766fb43ed7529936c3    0     0     0      16    63       0      0
49745bb4ca82f07647268850ce508304    0     0     0      66    11       0      0
7ff68a1af7c78551da73275f3d78d7d5    0    76     0       0     0       0      0
645ca8bbf072d95fe6edffe2531c3648    0     0    73       0     0       0      0
f168006c11a79747acf3d389c7f23e26    0     0    72       0     0       0      0
81a7e7b10e7e9ea2b67fa127df5e693b    0     0     0       0     0      72      0
cb201b9aaf0dba72164daa4774bb119c    0     0     0      71     0       0      0
7936a3707ec7b0e2853f55c5333670a2    0     0     0       0     0      71      0
a42198b34a6c67182c9c78d5f3b8ec1f   70     0     0       0     0       0      0
12c78d4b73784f979e28706dd6f77122    0     0     0      70     0       0      0
98b12c8f1012856458bbed13d03bb238    0     0     0       0     0      70      0
cf62a980df41f5bfbf047f5396ae3f1f    0    68     0       0     0       0      0
3beceac7adb1fc3b952340e3e951c788    0     0     0       0     0       0      0
5e240e3c6c0caf0e9f8d1580d9d381b5    0     0     0       0     0       0      0
367998f45226e06489d409cea4d58dd1    0     4     0      61     0       0      0
92271a003e2d298014a13ac9b73af737    0     0     0      65     0       0      0
f80a77623cedad745980d3aaad7b9ddb    0     0     0      65     0       0      0
cda573f4558f7bdf5dd4fc78084cd05f    0     0     0      27    37       0      0
fdfebf6cb4a3606c7dee1a5f613915fa    0    63     0       0     0       0      0
a08fb9dcc22f5666274107cb34b994dc    0     0     0       0     0      62      0
60a2e43f707140924958076fb9e8ac88    0     0    61       0     0       0      0
ae4334e6b1a45414c6e29f01aba16515   60     0     0       0     0       0      0
4868b82ac51a538efea4b6ea366ecc18    0     0    60       0     0       0      0
5833b07833ee501c61c3320845b47bca    0    59     0       0     0       0      0
                                 Conventional  NTC
45ddbfd3d07aee0fd8143d09b2af14e8         3817 4514
fb96c296bb4e6ac1e8260adb3c188be3            0 5044
1049d7d17f5ca428dbcd5377f18d7da7         1570 1780
84975317a8c1172222f4302fcede7639         1135 2042
ab7e61945bab3909f50909c32c7068ad         1055  646
5a321c0b774bd4bbcdfe17d2fa42ceb6            0 1593
5dd54d2191324443e4f4dfad53f22aff          327  548
79e6c1edd3ef4d7eeaab1df31f92a9fb         3636    0
a6dc0c1c93445042a671d97b01834f7b          840    0
fc185378fbec874b1fdd9a09ce4134af          171  228
1f62f14c6d32bab284a1f4ddb7ef0f86          166  202
eb6f1ef8123a3f39fde80a286a0552a6            0    0
c1f442f804c9daaa63de92c3b9479418            0    0
b3100bb7c50c79d5e6b7d83c8b63bf86            0  226
050a2913232d49c6c3d64a75ed1ab9f8          282    0
da70fcb2e98db9b733090cf3976926c3            0    0
49daf5febec9796bf7fa98ce1e5484ee           73    0
e9efa56e056bfac022c545d7eddb0d5e          119    0
762d97a48eb326b75467dc9905535763           40    0
3ac144ca9124a4ed17778d567cf81cf5            0    0
c76a04b13ea1daa6e86b6fb905541926           70  156
901917c888efcf0dc8c8d3ff1c59f2d0            0  486
25fd33feb5344f76bc1c4aa542c0a948          355    0
7f968afc9874c3c3c21c2c0a8bcf466d            0    0
64ae4ca85d86e50579a0ce888c70216f          205    0
b8788a9179a3e68d957c1384196c098b          198    0
dd65e2c3ca1f8466840f7e362557d8c0            0    0
2142a68611b23113dd0a8843bbcca774            0    0
e7cc229c19773ba9e802e09a129e560c           28  351
5704ebb9634fcf0c0ccaa7078fff5928          155    0
c2f01b197e7bd96d0008e4dceabc3b45            0    0
f638f61e23a2f0e6f0ed7ec9fca673c9          162    0
3a8d9d81c680ff3572a8fd072fd67198            0    0
08b4507f69b58ecc43ce91b3e9ff2b6f            0    0
aea3e38015c19e8f1d34dadddbc6e5cc           33    0
bc594caab289baa949fb4e2136cf4b36           58    0
f235b287e85f12f4211d60379905788a            0    0
17038ca085a43eed78b8c3ea9ebebe0a            0    0
955c450f208dff9351630a5fcc7706dc            4    0
f9eec41e23afbd9931b18013abe9e2b9            0    0
fa5c17f3c93a6c7791a6fe82402be5cf            0    0
4a3509111348f231de7288f90725730d            0    0
8ce909427a3147618d2e6557af708d74            0    0
f33c1ca6142229599fbd1700ac708c25            0    0
f2058e14b6a7601639b33c49cdb9583b            0  135
ad31f30a6d504fa8a27ea6726d175e77            0    0
2b2c0381f8d9a95c1b5c377e8ab5ffbe           80   42
e9f0d42c7d96c0b524054456f75e7c97            0    0
259efc442fb9bb1ae37be2c0270f0347            0    0
b9066f213cba9c0fcc4be3e0b28e08e1            0    0
bb66d560a170d917b2ce4b965e86ed49            0    0
edb9f3d53d3b0f582bcfc1972416bc51          157    0
95e2d0006c1797d72b926c619fa9d296            0    0
c6bcd092c661f880891f9c8d603b876c            0  171
e860e045c92ccc9246953926d07afbc0            0    0
54dee059e7bc541a213110698fef220f            0    0
d9a5f1de36b21f8b36326e8e6fc223a4            0    0
e8001767a006455ff8dd21b023d0913c            0  160
d89b319c95fffe32fda4f2f495ba7da0            0    0
52f4e61c8167fa140d7d71fba699c8e5            0    0
e5c4c38e6d4fd954fd42054096ee3126            0    0
6ef4d7123e307c829be3d10bbb20c176            0    0
b04341da7640e25caae082aff32853c3            0    0
af9658d3e891e36b7163b3fbf63d7a3c            0    0
6a7e30492d38e32b30ccf26f1ce6bc2a           11    0
15812bce78196981b7495375da36d5ed            0    0
92961bdffd4b23974c855de660b35d4a            0    0
298708eaeda166f87b4d55264cbe2990            0    0
8bfe6e9c6476e7e4a41a11c1b9c2ea5e            0  127
27daa3126720edd2f2ba6a48023ec8dc            0    0
8534cf00464fb4c071d860204633bcc4            0    0
a6099aa64bbe5dfc9eaf388a5b699bc1            0    0
0118e7559010fb5b7793cb79bf1eb381          116    0
403733ed4c0ebc812b5a081a1ab4928f            0    0
ad148e740b454eff45dc3f5e571eb963            0    0
fb1f8ad47be563788d40068587c67600            0    0
bce30a861ebdf3f123960c33d7206916            0    0
35ccea46b68bc086686f0a82870d81b0            0    0
08eee3ea7487ba50f3a162a2f28f2b33            0    0
f5b1aca35145dd7a81706e08ce599863            0    0
ea0e6b7f76733ad4ad2a3e4c49bd3a0c            0    0
eebceaafa0029010b406bd8967daadf2            0    0
5a59fb55239c752b4f8874047d281cd6            0    0
7fa4b88873c4ce054fdb3aadfdbb5bdb            0    0
30df4be2be3443caf34ec51a24b4205d            0    0
51e5f648518612ffc8912fdb68fa3880            0    0
becd70c1d0596316baea16282dcaafe3            0    0
7a75be15a04722766fb43ed7529936c3            0    0
49745bb4ca82f07647268850ce508304            0    0
7ff68a1af7c78551da73275f3d78d7d5            0    0
645ca8bbf072d95fe6edffe2531c3648            0    0
f168006c11a79747acf3d389c7f23e26            0    0
81a7e7b10e7e9ea2b67fa127df5e693b            0    0
cb201b9aaf0dba72164daa4774bb119c            0    0
7936a3707ec7b0e2853f55c5333670a2            0    0
a42198b34a6c67182c9c78d5f3b8ec1f            0    0
12c78d4b73784f979e28706dd6f77122            0    0
98b12c8f1012856458bbed13d03bb238            0    0
cf62a980df41f5bfbf047f5396ae3f1f            0    0
3beceac7adb1fc3b952340e3e951c788            0   67
5e240e3c6c0caf0e9f8d1580d9d381b5            0   66
367998f45226e06489d409cea4d58dd1            0    0
92271a003e2d298014a13ac9b73af737            0    0
f80a77623cedad745980d3aaad7b9ddb            0    0
cda573f4558f7bdf5dd4fc78084cd05f            0    0
fdfebf6cb4a3606c7dee1a5f613915fa            0    0
a08fb9dcc22f5666274107cb34b994dc            0    0
60a2e43f707140924958076fb9e8ac88            0    0
ae4334e6b1a45414c6e29f01aba16515            0    0
4868b82ac51a538efea4b6ea366ecc18            0    0
5833b07833ee501c61c3320845b47bca            0    0
 [ reached getOption("max.print") -- omitted 143 rows ]

The output for head(tatable) is as follows:

> head(taxtable)
# A tibble: 6 x 9
  Feature.ID      Kingdom  Phylum    Class    Order    Family    Genus   Species Confidence
  <fct>           <chr>    <chr>     <chr>    <chr>    <chr>     <chr>   <chr>        <dbl>
1 45ddbfd3d07aee… k__Bact… p__Prote… c__Gamm… o__Pseu… f__Pseud… g__Pse… s__          0.857
2 fb96c296bb4e6a… k__Bact… p__Firmi… c__Baci… o__Lact… f__Strep… g__Str… s__          0.993
3 1049d7d17f5ca4… k__Bact… p__Prote… c__Beta… o__Burk… f__Comam… g__Cur… s__          0.960
4 84975317a8c117… k__Bact… p__Prote… c__Gamm… o__Ente… f__Enter… NA      NA           1.000
5 ab7e61945bab39… k__Bact… p__Prote… c__Gamm… o__Pseu… f__Pseud… g__Pse… s__          0.884
6 5a321c0b774bd4… k__Bact… p__Firmi… c__Baci… o__Lact… f__Lacto… g__Lac… NA           1.000

Thank you very much.

ahh i see the issue, the pilot_table_group is the imported artifact which is actually a named list. You need to feed the actual data to the function (.$data). Secondarily if you check the documentation for the function, it expects the feature names to be in the row names of the taxonomy table. Something like the following code should work:

summarized.taxa=Summarize.Taxa(
pilot_table_group$data, 
pilot_taxonomy %>% as.data.frame() %>% column_to_rownames("Feature.ID"))

On a side note, for analyses such as these, it might be preferable to use the qiime taxa barplot functionality unless there is a lot of customizing you need to do. Depending on how big your dataset is, you might also find that using a vector graphics editor like illustrator or inkscape would help to rearrange samples, change colors, etc.

Hi @jbisanz, thank you for your timely reply. I came up with another error when I ran that command:

Error in (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE,  : 
  arguments imply differing number of rows: 1, 0

I am sorry for this. I really don’t know what these errors mean.

Actually qiime taxa barplot is what I mostly wanted to use. But I found the barplot can not be customized as I wanted and a bit away from being publishable, like this:

![15%20PM|655x500](upload://oo5kBqJVzX3Xw8Mbglzrq8GW0JN.png) 

The graph is long and narrow, legend could not be customized either while it is very powerful for basic analysis (not for publishing). So I posted a question a few days ago regarding this:

https://forum.qiime2.org/t/taxa-bar-plot-visualization/10674?u=arlandan

And I was suggested to use other tools rather than qiime taxa barplot, since it is less customizable. I found your MicrobeR shows a nice barplot as well as other useful graph and decided to give it a try. Could you please clarify me a bit more as to the use of qiime taxa barplot? Did you mean run qiime taxa barplot in qiime2 and get the taxa-bar-plots.qzv from there and then further customize this qzv file in R or other tools? or download the csv when visualizing the taxa-barplot.qzv and plot it in excel or something like that? or otherwise? Thank you for your time and effort.

All the best.

I’m not 100% sure what the problem is, but I ran it on my own computer using the files you provided earlier and all looked good. I made some additional aesthetic tweaks to show how you might customize some of the things you are interested in. Hopefully this can be a loose template for you or others in the future. Also, don’t under estimate what you can do with a vector graphics editing program. Every figure I make has been modified in some way using adobe illustrator.

In the future, can you please post the full reproducible version of the code you are trying to run as it would greatly help in spotting errors and/or bugs.

library(qiime2R)
library(tidyverse)
library(MicrobeR)

table<-read_qza("~/Desktop/test/pilot_table_group.qza")
metadata<-read_q2metadata("~/Desktop/test/metadata_group.tsv") %>% 
  as.data.frame() %>% 
  remove_rownames() %>% 
  column_to_rownames("SampleID") # %>%
  #mutate(Group=factor(levels=c(""))) #  type the order you would want them  in the list here , ie c("GF","Colony",...)


tax<-read_qza("pilot_taxonomy.qza")$data %>% 
  separate(Taxon, c("Kingdom","Phylum","Class","Order","Family","Genus","Species"), sep="; ") %>%
  mutate_if(is.character, function(x) if_else(
    grepl("^[pcofgs]__$", x) | is.na(x), # treating both s__ and NA as not assigned, you might have a different philosophy
    true="Not_Assigned",
    false=x
    )
  ) %>%
  column_to_rownames("Feature.ID")

taxsum<-Summarize.Taxa(table$data, tax)

Microbiome.Barplot(taxsum$Genus, metadata, 10, "group") + #samples already are the groups, so don't need to provide metadata, I only do it here because this will let you change the order of samples if you make it a factor
  theme_MicrobeR() + #makes font sizes more publication friendly
  coord_cartesian(expand=F) + # removes padding from edges
  theme(
    strip.text = element_blank(), #these are just the same as the X labels so removing them
    axis.text.x=element_text(angle=90, hjust=1), # rotate text 90 degrees
    legend.text = element_text(size=6)
  )

ggsave("yourplot.pdf", height=4, width=9, device="pdf")

yourplot.pdf (6.1 KB)

2 Likes

Hi @jbisanz,
I really appreciate help. Thanks so much for writing these codes, which are very helpful. I need some time to digest though :sweat_smile: Not a command line person. Thanks again and have a great weekend.

Best.