Failed to read and parse vcf file
0
0
Entering edit mode
3 months ago

I am trying this code:

import vcf
print (record)


But its giving me import error although i already installed PyVCF package:

Kindly help me to fix it?

Python Bioinformatics • 498 views
0
Entering edit mode
0
Entering edit mode

I suspect you installed pyVCF package via pip although you don't provide that information. It's always good to provide such details. Just now I tried myself and although I found pip says it is successful after many failed attempt with various versions, I saw the same thing as you are seeing at present when I try to import. Specifically import fails. Which generally means something about the installation was not correct, despite what pip reported.

I looked around and found this post which is a little more recent than the software itself. According to the date in the upper right corner here, pyVCF hasn't been updated in a long time. Abandoned / not actively-maintained software is usually a sign that you are more likely to encounter issues.

However....
I was successful at both installation and subsequent import by following the recommendation in this comment here dated two years ago by steve:

also it sounds like your installation of pyvcf is messed up. I would consider trying the version in conda; https://anaconda.org/bioconda/pyvcf

It looks like you are using this in Jupyter based on this image here? (You don't provide this information in either post. The more information you provide, the better your answers will be.) Assuming you do have recent Jupyter notebook or JupyterLab, try running this in a cell in your notebook to follow that advice:

%conda install pyvcf


That uses a magic command that has recently been added to IPython kernel that is commonly used in modern Jupyter to run Python. The magic %conda install and related %pip install commands insure that they install the software to the environment that the current notebook is using, see more about them here. Restart the kernel, and then in another cell try import vcf. If that import attempt works without error, you can use the rest of the code you posted.

The post at Biostars I pointed to also suggests some alternatives instead of this software that has not been developed in nearly six years.

0
Entering edit mode

So it simply means we should install older versions of any package by using conda instead of pypi

0
Entering edit mode

No, it doesn't 100% mean if it is old than try conda in all cases. However, it can be helpful when you run into a problem to try another route. And conda is a great route. And in this case others had suggested it is more reliable for this software. Ideally, it is best to avoid software that isn't being actively developed/maintained because you are going to be having a more difficult go of it. And your experience usually gets tougher with more time since it was last updated. I will say if you are working in a notebook and want things to work, pretty much 100% of the time try the magics route with %pip install and %conda install to see if you can bypass issues you may encounter with your environment. Don't use ! anymore in the notebook with pip and conda. (There's a lot of outdated information out there suggesting that.) I think by default if you leave off the !, now pip install and conda install use the magics route by default. Meaning the % gets added by automagics.