SEQanswers

Go Back   SEQanswers > Bioinformatics > Bioinformatics



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bowtie2-build error writing to reference index file cz0013 Bioinformatics 8 08-17-2015 09:31 AM
PyVCF question dktldkrh13 Bioinformatics 0 11-20-2014 10:35 AM
multiple vcf files to one multisampled vcf file Jetse Bioinformatics 2 06-27-2013 05:34 AM
vcflib, a C++ library for reading and writing VCF files ekg Bioinformatics 0 09-29-2010 01:12 PM

Reply
 
Thread Tools
Old 06-24-2017, 11:51 PM   #1
ravaan
Junior Member
 
Location: India

Join Date: Jun 2017
Posts: 2
Default Writing VCF File using PyVCF [HELP]

I am using PyVCF to read a VCF file, modify the data, and write this modified data either to the old file or to a new file. As given in their documentation I am using the vcf.Writer function to create a wrtieStream and write the file, code here:

Code:
vcf_reader = vcf.Reader(open('/home/ubuntu/GSoC-Strain_Diffrential/test.vcf.gz'))

# code to modify the data

vcf_writer = vcf.Writer(open('/dev/null', 'w'), vcf_reader)

count = 1
record = next(vcf_reader)
REF_list = [record.CHROM]
for record in vcf_reader:
    print record.REF, record.POS
    record.REF = 'C'
    print record.REF
    REF_list.extend([record.POS])
    vcf_writer.write_record(record)
    vcf_writer.flush()
    count = count + 1
    if count > 100:
        break

The code is running without any errors, but no changes are written to the file (The original file remains unchanged and no new file is created).

Any help is highly appreciated.

The complete code is provided here
ravaan is offline   Reply With Quote
Old 06-25-2017, 03:07 PM   #2
GenoMax
Senior Member
 
Location: East Coast USA

Join Date: Feb 2008
Posts: 6,961
Default

Looks like the output is specified as (/dev/null = nothing). Change that to a real path/file name e.g. /home/ubuntu/GSoC-Strain_Diffrential/test_modified.vcf.gz
GenoMax is offline   Reply With Quote
Old 06-25-2017, 11:44 PM   #3
ravaan
Junior Member
 
Location: India

Join Date: Jun 2017
Posts: 2
Smile

I tried that earlier but got some error, tried again worked like charm! Thanks for the help!
ravaan is offline   Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off




All times are GMT -8. The time now is 11:13 AM.


Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Single Sign On provided by vBSSO