Unable to merge virus profile.txt files into table

I am using metaphlan4 with mpa_vJun23_CHOCOPhlAnSGB_202307

I obtained profiled.vsc files for virus using this command:
SampleName.r1.fastq --input_type fastq --bowtie2out SampleName.r1.bowtie2.bz2 --profile_vsc --vsc_out profiled_Sample Name.vsc.txt

I am running this command

merge_metaphlan_tables.py profiled_*.txt > -o merged_abundance_table.txt

I am getting this error:
Traceback (most recent call last):
File “MYPATH/.conda/envs/metaphlan4/lib/python3.10/site-packages/pandas/core/indexes/base.py”, line 3805, in get_loc
return self._engine.get_loc(casted_key)
File “index.pyx”, line 167, in pandas._libs.index.IndexEngine.get_loc
File “index.pyx”, line 196, in pandas._libs.index.IndexEngine.get_loc
File “pandas/_libs/hashtable_class_helper.pxi”, line 7081, in pandas._libs.hashtable.PyObjectHashTable.get_item
File “pandas/_libs/hashtable_class_helper.pxi”, line 7089, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: ‘relative_abundance’

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File “MYPATH/.conda/envs/metaphlan4/bin/merge_metaphlan_tables.py”, line 10, in
sys.exit(main())
File “MYPATH/.conda/envs/metaphlan4/lib/python3.10/site-packages/metaphlan/utils/merge_metaphlan_tables.py”, line 73, in main
merge(args.aistms, open(args.o, ‘w’) if args.o else sys.stdout, args.gtdb_profiles)
File “MYPATH/.conda/envs/metaphlan4/lib/python3.10/site-packages/metaphlan/utils/merge_metaphlan_tables.py”, line 36, in merge
profiles_list.append(pd.Series(data=iIn[‘relative_abundance’], index=iIn.index,
File “MYAPTH/.conda/envs/metaphlan4/lib/python3.10/site-packages/pandas/core/frame.py”, line 4090, in getitem
indexer = self.columns.get_loc(key)
File “MYPATH/.conda/envs/metaphlan4/lib/python3.10/site-packages/pandas/core/indexes/base.py”, line 3812, in get_loc
raise KeyError(key) from err
KeyError: ‘relative_abundance’

Any thoughts of how I can troubleshoot this?

Thanks!

I found this tutorial: MetaPhlAn 4.1 · biobakery/biobakery Wiki · GitHub

However, the code provided: ```

Merge multiple tables

merge_vsc_tables.py -o OUT.vsc.txt *_vsc.txt


Did not work.

I tried modeling the code after how the merge command is written for relative abundance. This is what worked for me: 

merge_vsc_tables.py profiled_*.txt > OUT.vsc.txt

Hello,

I am also facing an error when trying to merge the VSC tables:

merge_vsc_tables.py X204SC250*/S_*/**_vsc_metagenome.txt -o merged_vsc_tables.txt

Traceback (most recent call last):
File “/work/FAC/FBM/DBC/slehtine/stool_sampling/tools/mpa4.2.2/bin/merge_vsc_tables.py”, line 10, in
sys.exit(main())
^^^^^^
File “/work/FAC/FBM/DBC/slehtine/stool_sampling/tools/mpa4.2.2/lib/python3.12/site-packages/metaphlan/utils/merge_vsc_tables.py”, line 99, in main
merge(args.aistms, fout, options)
File “/work/FAC/FBM/DBC/slehtine/stool_sampling/tools/mpa4.2.2/lib/python3.12/site-packages/metaphlan/utils/merge_vsc_tables.py”, line 69, in merge
out_table = pd.pivot_table(
merged_tables,
index=indexes_for_pivot,
columns=‘sampleID’,
values=groupby_field
)
File “/work/FAC/FBM/DBC/slehtine/stool_sampling/tools/mpa4.2.2/lib/python3.12/site-packages/pandas/core/reshape/pivot.py”, line 102, in pivot_table
table = __internal_pivot_table(
File “/work/FAC/FBM/DBC/slehtine/stool_sampling/tools/mpa4.2.2/lib/python3.12/site-packages/pandas/core/reshape/pivot.py”, line 172, in __internal_pivot_table
grouped = data.groupby(keys, observed=observed_bool, sort=sort, dropna=dropna)
File “/work/FAC/FBM/DBC/slehtine/stool_sampling/tools/mpa4.2.2/lib/python3.12/site-packages/pandas/core/frame.py”, line 9190, in groupby
return DataFrameGroupBy(
File “/work/FAC/FBM/DBC/slehtine/stool_sampling/tools/mpa4.2.2/lib/python3.12/site-packages/pandas/core/groupby/groupby.py”, line 1329, in init
grouper, exclusions, obj = get_grouper(
File “/work/FAC/FBM/DBC/slehtine/stool_sampling/tools/mpa4.2.2/lib/python3.12/site-packages/pandas/core/groupby/grouper.py”, line 1043, in get_grouper
raise KeyError(gpr)
KeyError: ‘Annotation’

(/work/FAC/FBM/DBC/slehtine/stool_sampling/tools/mpa4.2.2) metaphlan --version
MetaPhlAn version 4.2.2 (4 Jun 2025)

Any help would be appreciated !

Hi @fconstancias ,

I think there was a bug in the merge_vsc_tables script in MetaPhlAn version 4.2.2, which has been fixed in the newer versions.

You can either update the whole MetaPhlAn package or find the fixed script for merging vsc tables here: https://github.com/biobakery/MetaPhlAn/blob/master/metaphlan/utils/merge_vsc_tables.py

Hope this was helpful!

Linda

1 Like