Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error while running demix on VCFs produced by bcftools #268

Open
watronfire opened this issue Jan 8, 2025 · 0 comments · May be fixed by #269
Open

Error while running demix on VCFs produced by bcftools #268

watronfire opened this issue Jan 8, 2025 · 0 comments · May be fixed by #269

Comments

@watronfire
Copy link

watronfire commented Jan 8, 2025

Hi all,

I ran into the following issue while running freyja demix on a VCF generate by bcftools:

building mix/depth matrices
Traceback (most recent call last):
  File "/PHShome/nm104/mambaforge/envs/phonebook/bin/freyja", line 10, in <module>
    sys.exit(cli())
  File "/PHShome/nm104/mambaforge/envs/phonebook/lib/python3.9/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "/PHShome/nm104/mambaforge/envs/phonebook/lib/python3.9/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/PHShome/nm104/mambaforge/envs/phonebook/lib/python3.9/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/PHShome/nm104/mambaforge/envs/phonebook/lib/python3.9/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/PHShome/nm104/mambaforge/envs/phonebook/lib/python3.9/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/PHShome/nm104/mambaforge/envs/phonebook/lib/python3.9/site-packages/freyja/_cli.py", line 124, in demix
    mix, depths_, cov = build_mix_and_depth_arrays(variants, depths, muts,
  File "/PHShome/nm104/mambaforge/envs/phonebook/lib/python3.9/site-packages/freyja/sample_deconv.py", line 64, in build_mix_and_depth_arrays
    df = read_snv_frequencies_vcf(fn, depthFn, muts)
  File "/PHShome/nm104/mambaforge/envs/phonebook/lib/python3.9/site-packages/freyja/sample_deconv.py", line 104, in read_snv_frequencies_vcf
    df["ALT_FREQ"] = vcf_info[j].str.split('=')\
ValueError: could not convert string to float: '0,0,1,6'

The specific command I used was: freyja demix OUG-1858.variants-filled.vcf OUG-1858.depth.txt --output test.txt --barcodes freyja-barcodes/usher_barcodes.feather

All the files are attached. freyja_demix_files.zip

The traceback points to the following code:

vcf_info = df['INFO'].str.split(';', expand=True)
for j in range(vcf_info.shape[1]):
if vcf_info[j].str.split('=')[0] is not None:
if vcf_info[j].str.split('=')[0][0] == 'AF':
df["ALT_FREQ"] = vcf_info[j].str.split('=')\
.str[1]\
.values\
.astype(
float)

Based on my debugging, it seems the function assumes that all variants have the same number of fields in the INFO column, but I guess VCFs produced by bcftools don't (indels have extra fields in my files). As a result, I was able to workaround the problem by just extracting the value of the AF field using regex.

Environment:

  • python 3.9.19
  • pandas 2.2.3
  • usher 0.6.3
  • freyja 1.5.2
@watronfire watronfire linked a pull request Jan 8, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant