Dear QIIME 2 community,
I am encountering some difficulties with using the ancombc
action from the composition plugin, and I would appreciate some help. I have two separate issues that I am experiencing:
- When I tried to use the
ancombc
action through the command line interface, I encountered the same problem as in this post (ANCOM-BC plugin error). However, I did not have a.condarc
file. To resolve this issue, I modified the/miniconda3/envs/qiime2-2023.2/bin/run_ancombc.R
so it starts like this:
# error handling -----------------
options(error = function() {
sink(stderr())
on.exit(sink(NULL))
traceback(3)
if (!interactive()) {
q(status = 1)
}
})
# load libraries -----------------
suppressWarnings(library(phyloseq))
if (!requireNamespace("conflicted", quietly = TRUE)) {
options(repos = "https://cloud.r-project.org")
install.packages("conflicted")
}
library(conflicted)
library(tidyverse)
conflict_prefer("filter", "dplyr")
conflict_prefer("lag", "dplyr")
suppressWarnings(library(ANCOMBC))
library("optparse")
library("frictionless")
# load arguments ----------------
- However, I am still having issues with the Python API. When I run the command:
import qiime2
from qiime2.plugins.composition.actions import ancombc
example = qiime2.Artifact.import_data('FeatureTable[Frequency]', 'example_data/ancombc-single-formula/feature-table.biom')
example_meta = qiime2.Metadata.load('example_data/ancombc-single-formula/metadata.tsv')
ancombc(example, example_meta, 'bodysite')
I got the following
Running external command line application(s). This may print messages to stdout and/or stderr.
The command(s) being run are below. These commands cannot be manually re-run as they will depend on temporary files that no longer exist.
Command: run_ancombc.R --inp_abundances_path /tmp/tmp_gdn1qw9/input.biom.tsv --inp_metadata_path /tmp/tmp_gdn1qw9/input.map.txt --formula host_group --p_adj_method holm --prv_cut 0.1 --lib_cut 0 --reference_levels --neg_lb False --tol 1e-05 --max_iter 100 --conserve False --alpha 0.05 --output_loaf /tmp/q2-DataLoafPackageDirFmt-fxtzf7zu
...
FileNotFoundError: [Errno 2] No such file or directory: 'run_ancombc.R'
To address this, I modified the _ancombc function in miniconda3/envs/qiime2-2023.2/lib/python3.8/site-packages/q2_composition/_ancombc.py
to include
#changed command, so it will work with the Python API
conda_path = '/'.join(sys.prefix.split('/')[:-2])
conda_env = sys.prefix.split('/')[-1]
cmd = [f'{conda_path}/bin/conda run -n {conda_env}',
f'Rscript {sys.prefix}/bin/run_ancombc.R',
But I still get the following error
Command: /homes/mbeck/miniconda3/bin/conda run -n qiime2-2023.2 Rscript /homes/mbeck/miniconda3/envs/qiime2-2023.2/bin/run_ancombc.R --inp_abundances_path /tmp/tmpq1whnk31/input.biom.tsv --inp_metadata_path /tmp/tmpq1whnk31/input.map.txt --formula bodysite --p_adj_method holm --prv_cut 0.1 --lib_cut 0 --reference_levels --neg_lb False --tol 1e-05 --max_iter 100 --conserve False --alpha 0.05 --output_loaf /tmp/q2-DataLoafPackageDirFmt-p1djgs61
---------------------------------------------------------------------------
ValidationError Traceback (most recent call last)
Cell In[13], line 20
16 example_meta = qiime2.Metadata.load('example_data/ancombc-single-formula/metadata.tsv')
19 #collapsed_table = collapse(rarefied_table, taxonomy_artifact,level=6)
---> 20 ancombc(example, example_meta, 'bodysite')
File <decorator-gen-56>:2, in ancombc(table, metadata, formula, p_adj_method, prv_cut, lib_cut, reference_levels, neg_lb, tol, max_iter, conserve, alpha)
File ~/miniconda3/envs/qiime2-2023.2/lib/python3.8/site-packages/qiime2/sdk/action.py:234, in Action._bind.<locals>.bound_callable(*args, **kwargs)
230 warn(self._build_deprecation_message(),
231 FutureWarning)
233 # Execute
--> 234 outputs = self._callable_executor_(scope, callable_args,
235 output_types, provenance)
237 if len(outputs) != len(self.signature.outputs):
238 raise ValueError(
239 "Number of callable outputs must match number of "
240 "outputs defined in signature: %d != %d" %
241 (len(outputs), len(self.signature.outputs)))
File ~/miniconda3/envs/qiime2-2023.2/lib/python3.8/site-packages/qiime2/sdk/action.py:408, in Method._callable_executor_(self, scope, view_args, output_types, provenance)
405 prov = provenance.fork(name)
406 scope.add_reference(prov)
--> 408 artifact = qiime2.sdk.Artifact._from_view(
409 spec.qiime_type, output_view, spec.view_type, prov)
410 artifact = scope.add_parent_reference(artifact)
412 output_artifacts.append(artifact)
File ~/miniconda3/envs/qiime2-2023.2/lib/python3.8/site-packages/qiime2/sdk/result.py:349, in Artifact._from_view(cls, type, view, view_type, provenance_capture, validate_level)
346 recorder = provenance_capture.transformation_recorder('return')
347 transformation = from_type.make_transformation(to_type,
348 recorder=recorder)
--> 349 result = transformation(view, validate_level)
351 if type_raw in pm.validators:
352 validation_object = pm.validators[type]
File ~/miniconda3/envs/qiime2-2023.2/lib/python3.8/site-packages/qiime2/core/transform.py:68, in ModelType.make_transformation.<locals>.transformation(view, validate_level)
66 def transformation(view, validate_level='min'):
67 view = self.coerce_view(view)
---> 68 self.validate(view, level=validate_level)
70 new_view = transformer(view)
72 new_view = other.coerce_view(new_view)
File ~/miniconda3/envs/qiime2-2023.2/lib/python3.8/site-packages/qiime2/core/transform.py:143, in FormatType.validate(self, view, level)
140 raise TypeError("%r is not an instance of %r."
141 % (view, self._view_type))
142 # Formats have a validate method, so defer to it
--> 143 view.validate(level)
File ~/miniconda3/envs/qiime2-2023.2/lib/python3.8/site-packages/qiime2/plugin/model/directory_format.py:177, in DirectoryFormat.validate(self, level)
173 collected_paths = {p: None for p in self.path.glob('**/*')
174 if not p.name.startswith('.') and
175 p.is_file()}
176 for field in self._fields:
--> 177 getattr(self, field)._validate_members(collected_paths, level)
179 for path, value in collected_paths.items():
180 if value:
File ~/miniconda3/envs/qiime2-2023.2/lib/python3.8/site-packages/qiime2/plugin/model/directory_format.py:109, in BoundFile._validate_members(self, collected_paths, level)
107 self.format(path, mode='r').validate(level)
108 if not found_members and not self.optional:
--> 109 raise ValidationError(
110 "Missing one or more files for %s: %r"
111 % (self._directory_format.__class__.__name__, self.pathspec))
ValidationError: Missing one or more files for DataLoafPackageDirFmt: '.+\\.csv'
At this point, I am considering writing a wrapper function around the command line interface using the subprocess
module to bypass the issues I am encountering with the Python API. Nonetheless, I would appreciate any insights or guidance that the community can provide regarding this issue.
Thank you in advance for your help.