You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to use vcfpy yo convert a CSV file into VCF the script : import pandas as pd
import vcfpy
import sys
def csv_to_vcf(csv_file, vcf_file):
# read CSV file using pandas
df = pd.read_csv(csv_file)
# read vcf file
reader = vcfpy.Reader.from_path(vcf_file)
# create a new VCF file
vcf_writer = vcfpy.Writer.from_path(vcf_file,reader.header)
# add the header information to the VCF file
# loop through rows in the CSV file
for i, row in df.iterrows():
# create a new record for the VCF file
record = vcfpy.Record(
CHROM=row['#CHROM'],
POS=row['POS'],
ID=".",
REF=row['REF'],
ALT=".",
QUAL=".",
FILTER=".",
INFO=".",
FORMAT=[])
chr = row['#CHROM']
pos = int(row['POS'])
ref = row['REF']
alt = row['ALT']
chr='chr'+str(chr)
if chr == 'chrMT':
chr = 'chrM'
try:
fetched = reader.fetch(record.CHROM,pos-5,pos+5)
except:
fetched = '.|.'
for fet in fetched:
# add the record to the VCF file
vcf_writer.write_record(fet)
# close the VCF file
vcf_writer.close()
if name == "main":
csv_file = sys.argv[1]
vcf_file = sys.argv[2]
csv_to_vcf(csv_file,vcf_file)
where the Cmpd is the CSV file and the VCF file already has a header.
If there was a crash, please include the traceback here.
Error :
/vcfpy/writer.py", line 135, in _serialize_record
row = [record.CHROM, record.POS]
AttributeError: 'str' object has no attribute 'CHROM'
The text was updated successfully, but these errors were encountered:
Description
I'm trying to use vcfpy yo convert a CSV file into VCF the script : import pandas as pd
import vcfpy
import sys
def csv_to_vcf(csv_file, vcf_file):
if name == "main":
csv_file = sys.argv[1]
vcf_file = sys.argv[2]
csv_to_vcf(csv_file,vcf_file)
What I Did
python csv_to_vcf.py Cmpd_Hetro_Bathc1_morethan10test.csv results_table.DVD.vcf
where the Cmpd is the CSV file and the VCF file already has a header.
The text was updated successfully, but these errors were encountered: