Please help "An error was encountered while running MEGAHIT, (return code 247)"

I was running moshpit 2025.4 version and encountered the captioned problem. Below are the scripts I ran, please help.

(qiime2-moshpit-2025.4) chtang@TangLaptop:/mnt/c/Users/chtan/workshop_MCEF$ mosh assembly assemble-megahit --i-reads seq-demux.qza --p-presets "meta-sensitive" --p-num-cpu-threads 20 --o-contigs ./cache:contigs_may --verbose

/home/chtang/miniconda3/envs/qiime2-moshpit-2025.4/lib/python3.10/site-packages/numpy/core/fromnumeric.py:59: FutureWarning: 'DataFrame.swapaxes' is deprecated and will be removed in a future version. Please use 'DataFrame.transpose' instead.
return bound(*args, **kwds)
/home/chtang/miniconda3/envs/qiime2-moshpit-2025.4/lib/python3.10/site-packages/q2_assembly/megahit/megahit.py:105: UserWarning: The presets parameter overrides settings for the min_count and k_list parameters. The settings of min_count and k_list registered in provenance may not reflect the actual settings used by the presets parameter. Refer to the megahit documentation for more details, and refer to the presets values of these parameters when interpreting or reporting your results.
warnings.warn(warning, UserWarning)
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.

.

.

.

2025-08-24 15:13:17 - MEGAHIT v1.2.9
2025-08-24 15:13:17 - Using megahit_core with POPCNT and BMI2 support
2025-08-24 15:13:17 - Convert reads to binary library
2025-08-24 15:15:38 - b'INFO sequence/io/sequence_lib.cpp : 75 - Lib 0 (/tmp/qiime2/chtang/data/8c65e7c5-555d-4de3-8769-9ad328fabe9e/data/MJ14_3_L001_R1_001.fastq.gz,/tmp/qiime2/chtang/data/8c65e7c5-555d-4de3-8769-9ad328fabe9e/data/MJ14_24_L001_R2_001.fastq.gz): pe, 206290940 reads, 150 max length'
2025-08-24 15:15:38 - b'INFO utils/utils.h : 152 - Real: 140.7282\tuser: 73.0379\tsys: 15.5282\tmaxrss: 246384'
2025-08-24 15:15:38 - k-max reset to: 141
2025-08-24 15:15:38 - Start assembly. Number of CPU threads 20
2025-08-24 15:15:38 - k list: 21,29,39,49,59,69,79,89,99,109,119,129,141
2025-08-24 15:15:38 - Memory used: 45306338918
2025-08-24 15:15:38 - Extracting solid (k+1)-mers and building sdbg for k = 21
2025-08-24 15:37:08 - Assemble contigs from SdBG for k = 21
2025-08-24 20:05:34 - Local assembly for k = 21
2025-08-24 20:12:07 - Extract iterative edges from k = 21 to 29
2025-08-24 20:21:24 - Error occurs, please refer to /tmp/tmppkrvuilk/results/log for detail
2025-08-24 20:21:24 - Command: /home/chtang/miniconda3/envs/qiime2-moshpit-2025.4/bin/megahit_core iterate -c /tmp/tmppkrvuilk/results/intermediate_contigs/k21.contigs.fa -b /tmp/tmppkrvuilk/results/intermediate_contigs/k21.bubble_seq.fa -t 20 -k 21 -s 8 -o /tmp/tmppkrvuilk/results/tmp/k29/29 -r /tmp/tmppkrvuilk/results/tmp/reads.lib.bin; Exit code -9
Traceback (most recent call last):
File "/home/chtang/miniconda3/envs/qiime2-moshpit-2025.4/lib/python3.10/site-packages/q2_assembly/megahit/megahit.py", line 83, in _process_sample
run_command(cmd, verbose=True)
File "/home/chtang/miniconda3/envs/qiime2-moshpit-2025.4/lib/python3.10/site-packages/q2_assembly/_utils.py", line 38, in run_command
subprocess.run(cmd, check=True)
File "/home/chtang/miniconda3/envs/qiime2-moshpit-2025.4/lib/python3.10/subprocess.py", line 526, in run
raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['megahit', '-1', '/tmp/qiime2/chtang/data/8c65e7c5-555d-4de3-8769-9ad328fabe9e/data/MJ14_3_L001_R1_001.fastq.gz', '-2', '/tmp/qiime2/chtang/data/8c65e7c5-555d-4de3-8769-9ad328fabe9e/data/MJ14_24_L001_R2_001.fastq.gz', '-o', '/tmp/tmppkrvuilk/results', '--presets', 'meta-sensitive', '--min-count', '2', '--k-list', '21,29,39,59,79,99,119,141', '--bubble-level', '2', '--prune-level', '2', '--prune-depth', '2', '--disconnect-ratio', '0.1', '--low-local-ratio', '0.2', '--cleaning-rounds', '5', '--memory', '0.9', '--mem-flag', '1', '--num-cpu-threads', '20', '--min-contig-len', '200']' returned non-zero exit status 247.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/chtang/miniconda3/envs/qiime2-moshpit-2025.4/lib/python3.10/site-packages/q2cli/commands.py", line 529, in call
results = self._execute_action(
File "/home/chtang/miniconda3/envs/qiime2-moshpit-2025.4/lib/python3.10/site-packages/q2cli/commands.py", line 607, in _execute_action
results = action(**arguments)
File "", line 2, in assemble_megahit
File "/home/chtang/miniconda3/envs/qiime2-moshpit-2025.4/lib/python3.10/site-packages/qiime2/sdk/action.py", line 221, in bound_callable
outputs = self.callable_executor(
File "/home/chtang/miniconda3/envs/qiime2-moshpit-2025.4/lib/python3.10/site-packages/qiime2/sdk/action.py", line 440, in callable_executor
outputs = self._callable(ctx, **view_args)
File "/home/chtang/miniconda3/envs/qiime2-moshpit-2025.4/lib/python3.10/site-packages/q2_assembly/megahit/megahit.py", line 163, in assemble_megahit
(contig,) = _assemble_megahit(seq, **kwargs)
File "", line 2, in _assemble_megahit
File "/home/chtang/miniconda3/envs/qiime2-moshpit-2025.4/lib/python3.10/site-packages/qiime2/sdk/context/base.py", line 90, in callable_action
return self.dispatch(args, kwargs)
File "/home/chtang/miniconda3/envs/qiime2-moshpit-2025.4/lib/python3.10/site-packages/qiime2/sdk/context/base.py", line 45, in dispatch
results = exe(*args, **kwargs)
File "", line 2, in _assemble_megahit
File "/home/chtang/miniconda3/envs/qiime2-moshpit-2025.4/lib/python3.10/site-packages/qiime2/sdk/action.py", line 221, in bound_callable
outputs = self.callable_executor(
File "/home/chtang/miniconda3/envs/qiime2-moshpit-2025.4/lib/python3.10/site-packages/qiime2/sdk/action.py", line 359, in callable_executor
output_views = self._callable(**view_args)
File "/home/chtang/miniconda3/envs/qiime2-moshpit-2025.4/lib/python3.10/site-packages/q2_assembly/megahit/megahit.py", line 219, in _assemble_megahit
return assemble_megahit_helper(
File "/home/chtang/miniconda3/envs/qiime2-moshpit-2025.4/lib/python3.10/site-packages/q2_assembly/megahit/megahit.py", line 263, in assemble_megahit_helper
_process_sample(samp, fwd, rev, common_args, result)
File "/home/chtang/miniconda3/envs/qiime2-moshpit-2025.4/lib/python3.10/site-packages/q2_assembly/megahit/megahit.py", line 85, in _process_sample
raise Exception(
Exception: An error was encountered while running MEGAHIT, (return code 247), please inspect stdout and stderr to learn more.

Plugin error from assembly:

An error was encountered while running MEGAHIT, (return code 247), please inspect stdout and stderr to learn more.

See above for debug info.

Welcome to the forums, Charles! :qiime2:

That's 43 GB, I think!

How much memory does your laptop have?
MEGAHIT uses a lot of memory and while exit code 247 not a standard exit code, it's often memory, apparently.

1 Like

Thanks for the reply, Colin. My laptop has 96 GB, but it seems that only a half (~48 GB) has been allocated to run Qiime.

Should I increase RAM allocation? How could this be done?

1 Like

Hi @CharlesTang,

Are you running QIIME 2 on a Windows laptop? That is, via the Windows Subsystem for Linux (WSL)? If so, this is why. WSL defaults to allocating 50% of the system memory. See here.

So, you'll need to check the links in that post to adjust.

2 Likes

I allocated 80GB of RAM and ran again, still, the same error message occurred (please see below). I wonder if there are any other solutions. Thank you very much.

#################################

/home/chtang/miniconda3/envs/qiime2-moshpit-2025.4/lib/python3.10/site-packages/q2_assembly/megahit/megahit.py:105: UserWarning: The presets parameter overrides settings for the min_count and k_list parameters. The settings of min_count and k_list registered in provenance may not reflect the actual settings used by the presets parameter. Refer to the megahit documentation for more details, and refer to the presets values of these parameters when interpreting or reporting your results.
warnings.warn(warning, UserWarning)
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: megahit -1 /tmp/qiime2/chtang/data/0cf8d554-6b4c-48b7-a1a3-ed73e634d7a5/data/MJ14_3_L001_R1_001.fastq.gz -2 /tmp/qiime2/chtang/data/0cf8d554-6b4c-48b7-a1a3-ed73e634d7a5/data/MJ14_24_L001_R2_001.fastq.gz -o /tmp/tmpi9e9fso4/results --presets meta-sensitive --min-count 2 --k-list 21,29,39,59,79,99,119,141 --bubble-level 2 --prune-level 2 --prune-depth 2 --disconnect-ratio 0.1 --low-local-ratio 0.2 --cleaning-rounds 5 --memory 0.9 --mem-flag 1 --num-cpu-threads 20 --min-contig-len 200

2025-09-04 16:36:27 - MEGAHIT v1.2.9
2025-09-04 16:36:27 - Using megahit_core with POPCNT and BMI2 support
2025-09-04 16:36:27 - Convert reads to binary library
2025-09-04 16:38:54 - b'INFO sequence/io/sequence_lib.cpp : 75 - Lib 0 (/tmp/qiime2/chtang/data/0cf8d554-6b4c-48b7-a1a3-ed73e634d7a5/data/MJ14_3_L001_R1_001.fastq.gz,/tmp/qiime2/chtang/data/0cf8d554-6b4c-48b7-a1a3-ed73e634d7a5/data/MJ14_24_L001_R2_001.fastq.gz): pe, 206290940 reads, 150 max length'
2025-09-04 16:38:54 - b'INFO utils/utils.h : 152 - Real: 147.4651\tuser: 73.1232\tsys: 18.8857\tmaxrss: 246276'
2025-09-04 16:38:54 - k-max reset to: 141
2025-09-04 16:38:54 - Start assembly. Number of CPU threads 20
2025-09-04 16:38:54 - k list: 21,29,39,49,59,69,79,89,99,109,119,129,141
2025-09-04 16:38:54 - Memory used: 75905449574
2025-09-04 16:38:54 - Extracting solid (k+1)-mers and building sdbg for k = 21
2025-09-04 17:01:12 - Assemble contigs from SdBG for k = 21
2025-09-04 21:44:50 - Local assembly for k = 21
2025-09-04 21:51:42 - Extract iterative edges from k = 21 to 29
2025-09-04 22:16:41 - Error occurs, please refer to /tmp/tmpi9e9fso4/results/log for detail
2025-09-04 22:16:41 - Command: /home/chtang/miniconda3/envs/qiime2-moshpit-2025.4/bin/megahit_core iterate -c /tmp/tmpi9e9fso4/results/intermediate_contigs/k21.contigs.fa -b /tmp/tmpi9e9fso4/results/intermediate_contigs/k21.bubble_seq.fa -t 20 -k 21 -s 8 -o /tmp/tmpi9e9fso4/results/tmp/k29/29 -r /tmp/tmpi9e9fso4/results/tmp/reads.lib.bin; Exit code -9
Traceback (most recent call last):
File "/home/chtang/miniconda3/envs/qiime2-moshpit-2025.4/lib/python3.10/site-packages/q2_assembly/megahit/megahit.py", line 83, in _process_sample
run_command(cmd, verbose=True)
File "/home/chtang/miniconda3/envs/qiime2-moshpit-2025.4/lib/python3.10/site-packages/q2_assembly/_utils.py", line 38, in run_command
subprocess.run(cmd, check=True)
File "/home/chtang/miniconda3/envs/qiime2-moshpit-2025.4/lib/python3.10/subprocess.py", line 526, in run
raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['megahit', '-1', '/tmp/qiime2/chtang/data/0cf8d554-6b4c-48b7-a1a3-ed73e634d7a5/data/MJ14_3_L001_R1_001.fastq.gz', '-2', '/tmp/qiime2/chtang/data/0cf8d554-6b4c-48b7-a1a3-ed73e634d7a5/data/MJ14_24_L001_R2_001.fastq.gz', '-o', '/tmp/tmpi9e9fso4/results', '--presets', 'meta-sensitive', '--min-count', '2', '--k-list', '21,29,39,59,79,99,119,141', '--bubble-level', '2', '--prune-level', '2', '--prune-depth', '2', '--disconnect-ratio', '0.1', '--low-local-ratio', '0.2', '--cleaning-rounds', '5', '--memory', '0.9', '--mem-flag', '1', '--num-cpu-threads', '20', '--min-contig-len', '200']' returned non-zero exit status 247.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/chtang/miniconda3/envs/qiime2-moshpit-2025.4/lib/python3.10/site-packages/q2cli/commands.py", line 529, in call
results = self._execute_action(
File "/home/chtang/miniconda3/envs/qiime2-moshpit-2025.4/lib/python3.10/site-packages/q2cli/commands.py", line 607, in _execute_action
results = action(**arguments)
File "", line 2, in assemble_megahit
File "/home/chtang/miniconda3/envs/qiime2-moshpit-2025.4/lib/python3.10/site-packages/qiime2/sdk/action.py", line 221, in bound_callable
outputs = self.callable_executor(
File "/home/chtang/miniconda3/envs/qiime2-moshpit-2025.4/lib/python3.10/site-packages/qiime2/sdk/action.py", line 440, in callable_executor
outputs = self._callable(ctx, **view_args)
File "/home/chtang/miniconda3/envs/qiime2-moshpit-2025.4/lib/python3.10/site-packages/q2_assembly/megahit/megahit.py", line 163, in assemble_megahit
(contig,) = _assemble_megahit(seq, **kwargs)
File "", line 2, in _assemble_megahit
File "/home/chtang/miniconda3/envs/qiime2-moshpit-2025.4/lib/python3.10/site-packages/qiime2/sdk/context/base.py", line 90, in callable_action
return self.dispatch(args, kwargs)
File "/home/chtang/miniconda3/envs/qiime2-moshpit-2025.4/lib/python3.10/site-packages/qiime2/sdk/context/base.py", line 45, in dispatch
results = exe(*args, **kwargs)
File "", line 2, in _assemble_megahit
File "/home/chtang/miniconda3/envs/qiime2-moshpit-2025.4/lib/python3.10/site-packages/qiime2/sdk/action.py", line 221, in bound_callable
outputs = self.callable_executor(
File "/home/chtang/miniconda3/envs/qiime2-moshpit-2025.4/lib/python3.10/site-packages/qiime2/sdk/action.py", line 359, in callable_executor
output_views = self._callable(**view_args)
File "/home/chtang/miniconda3/envs/qiime2-moshpit-2025.4/lib/python3.10/site-packages/q2_assembly/megahit/megahit.py", line 219, in _assemble_megahit
return assemble_megahit_helper(
File "/home/chtang/miniconda3/envs/qiime2-moshpit-2025.4/lib/python3.10/site-packages/q2_assembly/megahit/megahit.py", line 263, in assemble_megahit_helper
_process_sample(samp, fwd, rev, common_args, result)
File "/home/chtang/miniconda3/envs/qiime2-moshpit-2025.4/lib/python3.10/site-packages/q2_assembly/megahit/megahit.py", line 85, in _process_sample
raise Exception(
Exception: An error was encountered while running MEGAHIT, (return code 247), please inspect stdout and stderr to learn more.

Plugin error from assembly:

An error was encountered while running MEGAHIT, (return code 247), please inspect stdout and stderr to learn more.

See above for debug info.

#################################

Thank you for posting the full error!

Here's what I noticed:

Exit code -9 means a job was canceled / killed. This can happen when a job overruns its memory.

Still, 80 GB is a lot of memory! How big is your input data set? I wonder how much memory megahit_core needs?

1 Like

Hi Colin,

Thanks for the reply. The input file is about 250 GB. I wonder if RAM has to be more than the input file size.

Appreciated.

1 Like

Megahit includes lots of memory settings:

I'm not sure which of these settings are available in the Qiime2 plugin as it's not mentioned in the docs I could find:

Some of these settings are in the source code, so maybe the devs can advise while the docs are still in unpublished:

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.