Problems with ANCOMBC Composition Plugin in Qiime2: CLI partially fixed, but Python API still problematic

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:

  1. 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 ----------------
  1. 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.

1 Like

Update:

The command obviously worked at least once. Otherwise I would not have the results artifact in my directory.

Anyways, now however I try to execute the command

(qiime2-2023.2) PATH$ qiime composition ancombc \
>   --i-table example_data/ancombc-single-formula/table.qza \
>   --m-metadata-file example_data/ancombc-single-formula/metadata.tsv \
>   --p-formula 'bodysite' \
>   --o-differentials exmple_singel.qza

I get something like this

Plugin error from composition:

  Missing one or more files for DataLoafPackageDirFmt: '.+\\.csv'

Debug info has been saved to /tmp/qiime2-q2cli-err-7rjtxcm0.log

The logfile looking like

['/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/tmp_qivbb5i/input.biom.tsv', '--inp_metadata_path', '/tmp/tmp_qivbb5i/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-tf_8st91']
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: /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/tmp_qivbb5i/input.biom.tsv --inp_metadata_path /tmp/tmp_qivbb5i/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-tf_8st91

Traceback (most recent call last):
  File "/homes/mbeck/miniconda3/envs/qiime2-2023.2/lib/python3.8/site-packages/q2cli/commands.py", line 352, in __call__
    results = action(**arguments)
  File "<decorator-gen-56>", line 2, in ancombc
  File "/homes/mbeck/miniconda3/envs/qiime2-2023.2/lib/python3.8/site-packages/qiime2/sdk/action.py", line 234, in bound_callable
    outputs = self._callable_executor_(scope, callable_args,
  File "/homes/mbeck/miniconda3/envs/qiime2-2023.2/lib/python3.8/site-packages/qiime2/sdk/action.py", line 408, in _callable_executor_
    artifact = qiime2.sdk.Artifact._from_view(
  File "/homes/mbeck/miniconda3/envs/qiime2-2023.2/lib/python3.8/site-packages/qiime2/sdk/result.py", line 349, in _from_view
    result = transformation(view, validate_level)
  File "/homes/mbeck/miniconda3/envs/qiime2-2023.2/lib/python3.8/site-packages/qiime2/core/transform.py", line 68, in transformation
    self.validate(view, level=validate_level)
  File "/homes/mbeck/miniconda3/envs/qiime2-2023.2/lib/python3.8/site-packages/qiime2/core/transform.py", line 143, in validate
    view.validate(level)
  File "/homes/mbeck/miniconda3/envs/qiime2-2023.2/lib/python3.8/site-packages/qiime2/plugin/model/directory_format.py", line 177, in validate
    getattr(self, field)._validate_members(collected_paths, level)
  File "/homes/mbeck/miniconda3/envs/qiime2-2023.2/lib/python3.8/site-packages/qiime2/plugin/model/directory_format.py", line 109, in _validate_members
    raise ValidationError(
qiime2.core.exceptions.ValidationError: Missing one or more files for DataLoafPackageDirFmt: '.+\\.csv'

I will now try a fresh coda environment without any modifications.

It seems like the modifacation of the miniconda3/envs/qiime2-2023.2/lib/python3.8/site-packages/q2_composition/_ancombc.py file indroduced some of the Problems.

Without my changes the CLI works!

Unfortunately, the Python API problem persists. When running the code snippet below, the error message is still present:

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')

prints

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/tmplxsuk9bf/input.biom.tsv --inp_metadata_path /tmp/tmplxsuk9bf/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-3_jav067

and gives the error message

---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
Cell In[24], line 6
      4 example = qiime2.Artifact.import_data('FeatureTable[Frequency]', 'example_data/ancombc-single-formula/feature-table.biom')
      5 example_meta = qiime2.Metadata.load('example_data/ancombc-single-formula/metadata.tsv')
----> 6 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:381, in Method._callable_executor_(self, scope, view_args, output_types, provenance)
    380 def _callable_executor_(self, scope, view_args, output_types, provenance):
--> 381     output_views = self._callable(**view_args)
    382     output_views = tuplize(output_views)
    384     # TODO this won't work if the user has annotated their "view API" to
    385     # return a `typing.Tuple` with some number of components. Python will
    386     # return a tuple when there are multiple return values, and this length
   (...)
    389     # due to how Python handles multiple returns, and can be worked around
    390     # by using something like `typing.List` instead.

File ~/miniconda3/envs/qiime2-2023.2/lib/python3.8/site-packages/q2_composition/_ancombc.py:41, in ancombc(table, metadata, formula, p_adj_method, prv_cut, lib_cut, reference_levels, neg_lb, tol, max_iter, conserve, alpha)
     35 def ancombc(table: pd.DataFrame, metadata: qiime2.Metadata, formula: str,
     36             p_adj_method: str = 'holm', prv_cut: float = 0.1, lib_cut: int = 0,
     37             reference_levels: str = None, neg_lb: bool = False,
     38             tol: float = 1e-05, max_iter: int = 100, conserve: bool = False,
     39             alpha: float = 0.05) -> DataLoafPackageDirFmt:
---> 41     return _ancombc(
     42         table=table,
     43         metadata=metadata,
     44         formula=formula,
     45         p_adj_method=p_adj_method,
     46         prv_cut=prv_cut,
     47         lib_cut=lib_cut,
     48         reference_levels=reference_levels,
     49         neg_lb=neg_lb,
     50         tol=tol,
     51         max_iter=max_iter,
     52         conserve=conserve,
     53         alpha=alpha,
     54     )

File ~/miniconda3/envs/qiime2-2023.2/lib/python3.8/site-packages/q2_composition/_ancombc.py:182, in _ancombc(table, metadata, formula, p_adj_method, prv_cut, lib_cut, reference_levels, neg_lb, tol, max_iter, conserve, alpha)
    164 cmd = [#f'{conda_path}/bin/conda run -n {conda_env}',
    165        f'run_ancombc.R',
    166        '--inp_abundances_path', biom_fp,
   (...)
    178        '--output_loaf', str(output_loaf)
    179        ]
    181 try:
--> 182     run_commands([cmd])
    183 except subprocess.CalledProcessError as e:
    184     raise Exception('An error was encountered while running ANCOM-BC'
    185                     ' in R (return code %d), please inspect stdout and'
    186                     ' stderr to learn more.' % e.returncode)

File ~/miniconda3/envs/qiime2-2023.2/lib/python3.8/site-packages/q2_composition/_ancombc.py:32, in run_commands(cmds, verbose)
     30     print('\nCommand:', end=' ')
     31     print(' '.join(cmd), end='\n\n')
---> 32 subprocess.run(cmd, check=True)

File ~/miniconda3/envs/qiime2-2023.2/lib/python3.8/subprocess.py:493, in run(input, capture_output, timeout, check, *popenargs, **kwargs)
    490     kwargs['stdout'] = PIPE
    491     kwargs['stderr'] = PIPE
--> 493 with Popen(*popenargs, **kwargs) as process:
    494     try:
    495         stdout, stderr = process.communicate(input, timeout=timeout)

File ~/miniconda3/envs/qiime2-2023.2/lib/python3.8/subprocess.py:858, in Popen.__init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors, text)
    854         if self.text_mode:
    855             self.stderr = io.TextIOWrapper(self.stderr,
    856                     encoding=encoding, errors=errors)
--> 858     self._execute_child(args, executable, preexec_fn, close_fds,
    859                         pass_fds, cwd, env,
    860                         startupinfo, creationflags, shell,
    861                         p2cread, p2cwrite,
    862                         c2pread, c2pwrite,
    863                         errread, errwrite,
    864                         restore_signals, start_new_session)
    865 except:
    866     # Cleanup if the child failed starting.
    867     for f in filter(None, (self.stdin, self.stdout, self.stderr)):

File ~/miniconda3/envs/qiime2-2023.2/lib/python3.8/subprocess.py:1704, in Popen._execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, restore_signals, start_new_session)
   1702     if errno_num != 0:
   1703         err_msg = os.strerror(errno_num)
-> 1704     raise child_exception_type(errno_num, err_msg, err_filename)
   1705 raise child_exception_type(err_msg)

FileNotFoundError: [Errno 2] No such file or directory: 'run_ancombc.R'

Hi @Kami-Katze, I just want to confirm - this is with a fresh install of QIIME 2 2023.2? In other words, you haven't made any modifications to you conda environment? We'll try to reproduce this locally and let you know what we find.

Hi,
Thank you for the effort. This is the Qiime environment that I modified (importantly only the changes in the run_ancombc.R file are remaining). This thread describes the problems I encountered while trying to use the ancombc action.

However, I just tried to replicate it in a freshly installed Qiime 2023.2 environment without any changes.

After using

# Load example data
q_path='export PATH=/homes/mbeck/miniconda3/envs/qiime2-2023.2/bin:$PATH'
!$q_path; qiime composition ancombc --example-data example_data
from qiime2.plugins.composition.methods import ancombc
table = qiime2.Artifact.load('example_data/ancombc-single-formula/table.qza')
metadata = qiime2.Metadata.load('example_data/ancombc-single-formula/metadata.tsv')
ancombc(table, metadata, 'bodysite')

I got this error

---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
Cell In[15], line 4
      2 table = qiime2.Artifact.load('example_data/ancombc-single-formula/table.qza')
      3 metadata = qiime2.Metadata.load('example_data/ancombc-single-formula/metadata.tsv')
----> 4 ancombc(table, metadata, 'bodysite')

File <decorator-gen-36>: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-no-mod/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-no-mod/lib/python3.8/site-packages/qiime2/sdk/action.py:381, in Method._callable_executor_(self, scope, view_args, output_types, provenance)
    380 def _callable_executor_(self, scope, view_args, output_types, provenance):
--> 381     output_views = self._callable(**view_args)
    382     output_views = tuplize(output_views)
    384     # TODO this won't work if the user has annotated their "view API" to
    385     # return a `typing.Tuple` with some number of components. Python will
    386     # return a tuple when there are multiple return values, and this length
   (...)
    389     # due to how Python handles multiple returns, and can be worked around
    390     # by using something like `typing.List` instead.

File ~/miniconda3/envs/qiime2-2023.2-no-mod/lib/python3.8/site-packages/q2_composition/_ancombc.py:41, in ancombc(table, metadata, formula, p_adj_method, prv_cut, lib_cut, reference_levels, neg_lb, tol, max_iter, conserve, alpha)
     35 def ancombc(table: pd.DataFrame, metadata: qiime2.Metadata, formula: str,
     36             p_adj_method: str = 'holm', prv_cut: float = 0.1, lib_cut: int = 0,
     37             reference_levels: str = None, neg_lb: bool = False,
     38             tol: float = 1e-05, max_iter: int = 100, conserve: bool = False,
     39             alpha: float = 0.05) -> DataLoafPackageDirFmt:
---> 41     return _ancombc(
     42         table=table,
     43         metadata=metadata,
     44         formula=formula,
     45         p_adj_method=p_adj_method,
     46         prv_cut=prv_cut,
     47         lib_cut=lib_cut,
     48         reference_levels=reference_levels,
     49         neg_lb=neg_lb,
     50         tol=tol,
     51         max_iter=max_iter,
     52         conserve=conserve,
     53         alpha=alpha,
     54     )

File ~/miniconda3/envs/qiime2-2023.2-no-mod/lib/python3.8/site-packages/q2_composition/_ancombc.py:182, in _ancombc(table, metadata, formula, p_adj_method, prv_cut, lib_cut, reference_levels, neg_lb, tol, max_iter, conserve, alpha)
    164 cmd = [#f'{conda_path}/bin/conda run -n {conda_env}',
    165        f'run_ancombc.R',
    166        '--inp_abundances_path', biom_fp,
   (...)
    178        '--output_loaf', str(output_loaf)
    179        ]
    181 try:
--> 182     run_commands([cmd])
    183 except subprocess.CalledProcessError as e:
    184     raise Exception('An error was encountered while running ANCOM-BC'
    185                     ' in R (return code %d), please inspect stdout and'
    186                     ' stderr to learn more.' % e.returncode)

File ~/miniconda3/envs/qiime2-2023.2-no-mod/lib/python3.8/site-packages/q2_composition/_ancombc.py:32, in run_commands(cmds, verbose)
     30     print('\nCommand:', end=' ')
     31     print(' '.join(cmd), end='\n\n')
---> 32 subprocess.run(cmd, check=True)

File ~/miniconda3/envs/qiime2-2023.2-no-mod/lib/python3.8/subprocess.py:493, in run(input, capture_output, timeout, check, *popenargs, **kwargs)
    490     kwargs['stdout'] = PIPE
    491     kwargs['stderr'] = PIPE
--> 493 with Popen(*popenargs, **kwargs) as process:
    494     try:
    495         stdout, stderr = process.communicate(input, timeout=timeout)

File ~/miniconda3/envs/qiime2-2023.2-no-mod/lib/python3.8/subprocess.py:858, in Popen.__init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors, text)
    854         if self.text_mode:
    855             self.stderr = io.TextIOWrapper(self.stderr,
    856                     encoding=encoding, errors=errors)
--> 858     self._execute_child(args, executable, preexec_fn, close_fds,
    859                         pass_fds, cwd, env,
    860                         startupinfo, creationflags, shell,
    861                         p2cread, p2cwrite,
    862                         c2pread, c2pwrite,
    863                         errread, errwrite,
    864                         restore_signals, start_new_session)
    865 except:
    866     # Cleanup if the child failed starting.
    867     for f in filter(None, (self.stdin, self.stdout, self.stderr)):

File ~/miniconda3/envs/qiime2-2023.2-no-mod/lib/python3.8/subprocess.py:1704, in Popen._execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, restore_signals, start_new_session)
   1702     if errno_num != 0:
   1703         err_msg = os.strerror(errno_num)
-> 1704     raise child_exception_type(errno_num, err_msg, err_filename)
   1705 raise child_exception_type(err_msg)

FileNotFoundError: [Errno 2] No such file or directory: 'run_ancombc.R'

Please Let me know if you need more information about this bug.

Hi @Kami-Katze,

Apologies for the delay in response, thanks for your patience!

One of my colleagues tested this locally with a fresh install of 2023.2 and was not able to reproduce this issue. Can you share why you're running these commands prior to running QIIME 2:

# Load example data
q_path='export PATH=/homes/mbeck/miniconda3/envs/qiime2-2023.2/bin:$PATH'
!$q_path; qiime composition ancombc --example-data example_data

Additionally, can you share all of the steps you took to install a fresh QIIME 2 environment? You shouldn't need to modify $PATH to run any QIIME 2 commands, or create a .condarc file (I don't use one for any of my QIIME 2 environments). This could be what's causing the issues that you're running into.

Cheers :lizard:

Hi,

I used the following command to download the example data from the ancombc function:

# Load example data
q_path='export PATH=/homes/mbeck/miniconda3/envs/qiime2-2023.2/bin:$PATH'
!$q_path; qiime composition ancombc --example-data example_data

Since I encountered problems with the Python API of QIIME2 when working with my own data in Jupyter Notebook, I decided to use the CLI interface of QIIME2 instead. This is the command I used within my Jupyter Notebook to download the example data.

Please note that I used the modified installation to download the example data, but not as the kernel of the Jupyter environment.

To create the new environment, I used the following commands:

wget https://data.qiime2.org/distro/core/qiime2-2023.2-py38-linux-conda.yml
conda env create -n qiime2-2023.2-no-mod --file qiime2-2023.2-py38-linux-conda.yml
conda activate qiime2-2023.2-no-mod
python -m ipykernel install --user --name qiime2-2023.2-no-mod --display-name "q2-23.2-no-mod"

Thanks again for your time and help. I really appreciate it!

Hi @Kami-Katze,

I'm specifically wondering about your use of the q_path variable, which is exporting PATH prior to running qiime composition ancombc. You shouldn't have to set or modify PATH in order to run any qiime commands - I suspect this has something do with the ancombc.R file not being found.

1 Like

Hi,

You are right that manipulating the PATH variable does not make sense in this case. However, I don't think this is what's causing the problems.

Even after stopping and starting my Jupyter server, restarting the kernel, and running only the following lines without changing the PATH variable, I still get the aforementioned error:

import qiime2
from qiime2.plugins.composition.methods import ancombc
table = qiime2.Artifact.load('example_data/ancombc-single-formula/table.qza')
metadata = qiime2.Metadata.load('example_data/ancombc-single-formula/metadata.tsv')
ancombc(table, metadata, 'bodysite')

Thank you for your help.

PS.

I don't know if this helps, but if I try to execute !qiime in my notebook without changing the PATH variable, I get the error /bin/bash: qiime: command not found. However, the qiime command works just fine in the terminal after activating the conda environment. This might be due to the configuration of the university's servers. Honestly, I don't know if it's supposed to be like this.

Hello @Kami-Katze,
I am not quite sure what exactly the issue is.

Can you try re-installing a new env of qiime2 and try running this set of commands?

$ conda activate qiime2-2023.2
$ qiime composition ancombc --example-data ./example_data
...
$ ipython

In [1]: from qiime2.plugins.composition.methods import ancombc

In [3]: import qiime2

In [4]: table = qiime2.Artifact.load('example_data/ancombc-single-formula/table.qza')

In [5]: metadata = qiime2.Metadata.load('example_data/ancombc-single-formula/metadata.tsv')

In [6]: ancombc(table, metadata, 'bodysite')

Let me know if you still run into that issue after re-installing and running these commands.

Hope that helps!
:turtle:

1 Like

Thank you for your help!

I was doing my best to reinstall Qiime2. However, I ran into some issues. I used mamba remove --name qiime2-2023.2 --all to remove the environment but noticed some warnings regarding files in the miniconda3/pkgs/ directory when running mamba env create -n fresh-qiime2-2023.2 --file qiime2-2023.2-py38-linux-conda.yml. The warning was about unexpected hash sums and file sizes. That installation encountered the same error as described above when using the Python API.

After that, I first used the same command as above to remove the qiime2-2023.2 environment and additionally ran rm -rf ~/miniconda3/pkgs/* before installing the environment again. Nevertheless, I still got the same error.

I also tried this using conda instead of mamba, but the results did not change.

If you have any ideas about what I could try instead, please let me know!

Hi @Kami-Katze,

Jumping back in on this (thanks @cherman2 for your help while I was on vacation!) - I still suspect that your modification of $PATH is (at least part of) the problem. Whenever you modify $PATH, that won't automatically be reset with each new conda environment you create. If you've added directories to $PATH that no longer exist or have been modified, executable files may not be found - which is what you're running into here.

Can you run echo $PATH in your terminal and copy/paste the entire output in your response? Thanks!

2 Likes

Hi,
I hope this is helful

(base) mbeck@hp-sl230-s3-r2:~$ echo $PATH
/homes/mbeck/miniconda3/bin:/homes/mbeck/miniconda3/condabin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/opt/puppetlabs/bin

Thank you again for your efforts

Hey @Kami-Katze,

Thanks for sharing this - your $PATH doesn't look unreasonable, but we should see run_ancombc.R in the list of executable files, since that's specifically what you did in your steps above. This file may not be recognized as an executable file on your machine, or it may be a permissions issue (which could be a possibility, given that it looks like you're using some sort of HP cluster).

Can you activate your QIIME 2 environment and then copy/paste the output of the following command:

ls -al $CONDA_PREFIX/bin/*R

Thanks! :lizard:

1 Like

Hi @lizgehret,

Thanks for your reply.

(qiime2-2023.2) mbeck@hp-sl230-s3-r2:~$ ls -al $CONDA_PREFIX/bin/*R
-rwxrwxr-x 1 mbeck bcf_users  9336 May  1 17:46 /homes/mbeck/miniconda3/envs/qiime2-2023.2/bin/R
-rwxrwxr-x 2 mbeck bcf_users   870 Feb 28 00:46 /homes/mbeck/miniconda3/envs/qiime2-2023.2/bin/run_adonis.R
-rwxrwxr-x 2 mbeck bcf_users  6002 Feb 27 22:41 /homes/mbeck/miniconda3/envs/qiime2-2023.2/bin/run_ancombc.R
-rwxrwxr-x 2 mbeck bcf_users 25134 Feb 27 22:41 /homes/mbeck/miniconda3/envs/qiime2-2023.2/bin/run_dada.R