'Dealing with vcf files and get parser error

I am trying this code to read vcf files from different folders and make plots:

#Importing necessary modules and packages
import pandas as pd
import vcf
import os
import matplotlib.pyplot as plt
            

# Folder Paths
#You can change the path according to your own pc specification
file_path1 = "C://Users//USER//Desktop//anas/VCFs_1/"
file_path2 = "C://Users//USER//Desktop//anas/VCFs_2/"

#Define paths
path1 = "C://Users//USER//Desktop//anas/VCFs_1/"
path2 = "C://Users//USER//Desktop//anas/VCFs_2/"


                 
# iterate through first vcf folder
for file1 in os.listdir(path1):
    # Check whether the file is in vcf format or not
    if file1.endswith(".vcf"):
        file_path1 = f"{path1}\{file1}"
        reader1 = vcf.Reader(open(file_path1))
        df1 = pd.DataFrame([vars(r) for r in reader1])
        #Convert INFO Col to List
        out1 = df1.merge(pd.DataFrame(df1.INFO.tolist()),
                                 left_index=True, right_index=True)
        #Show files present in first folder
        print(file_path1)
        #Show VCF Records
        print(out1)
        #Making scatter plot
        out1.plot.scatter(x = "CHROM", y = "POS", s = 10);
        #Save to CSV
        df1.to_csv("VCF1.csv")
        
                
#iterate through 2nd vcf folder          
for file2 in os.listdir(path2):
    if file2.endswith(".vcf"):
        file_path2 = f"{path2}\{file2}"
        reader2 = vcf.Reader(open(file_path2))
        df2 = pd.DataFrame([vars(r) for r in reader2])
        out2 = df2.merge(pd.DataFrame(df2.INFO.tolist()),
                         left_index=True, right_index=True)
        #Show files present in 2nd folder
        print(file_path2)
        #Show VCF Records
        print(out2)
        #Making scatter plot
        out2.plot.scatter(x = "CHROM", y = "POS", s = 10);
        #Save file to csv
        df2.to_csv("VCF2.csv")
       

but i am getting error: cannot import name 'Reader' from 'parser'(unknown location)

How can i remove it? I already installed pyvcf package in my pc



Solution 1:[1]

You can uninstall/remove packages with pip in the command line.

$pip uninstall pyvcf

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Fawaz.D