You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

R语言as.matrix()报错解决:18S数据OTU表创建问题排查

解决18S测序数据生成OTU表的报错问题

问题背景

处理带bootstrap置信度的18S测序分类/序列表时,执行生成OTU表的代码触发如下报错:

Error in h(simpleError(msg, call)) :
error in evaluating the argument 'object' in selecting a method for function 'otu_table': error in evaluating the argument 'x' in selecting a method for function 'as.matrix': `.data` must be a data frame without row names.

报错原因

原数据框本身已存在行名(长序列字符串),执行column_to_rownames("OTUNumber")替换行名后,数据框仍保留行名属性,后续as.matrix处理时触发dplyr的限制——要求输入无行名的数据框。

修正方案

调整操作顺序,先筛选出非bootstrap的样本计数数值列,再设置OTU编号为行名,最后转换为矩阵并生成otu_table:

OTU <- seqtab.nochim_18S %>%  
  # 筛选数值型列,排除带_boot后缀的bootstrap置信度列
  select(where(is.numeric), -contains("_boot")) %>%
  # 将OTUNumber设为行名,自动移除原有行名
  column_to_rownames("OTUNumber") %>% 
  as.matrix() %>%  
  otu_table(taxa_are_rows = TRUE)

补充说明

如果需要保留分类信息(Kingdom、Genus等),需单独提取为分类注释表,OTU表仅需保留样本计数数据即可,两者通过OTU编号关联。

内容的提问来源于stack exchange,提问作者NOCTA

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 05:35:20