View Single Post
Old 02-04-2014, 02:26 PM   #21
bw.
Member
 
Location: San Francisco, CA

Join Date: Mar 2012
Posts: 21
Default

I'm also seeing the slashes with VarScan v2.3.6
I wrote this script to convert the slashes to commas:

Code:
import sys

if len(sys.argv) < 2:  sys.exit("Usage: " + sys.argv[0] + "  vcf_filename")

in_fname = sys.argv[1]
out_fname = (in_fname[:-4] if in_fname.endswith(".vcf") else in_frame) + ".fixed.vcf"
print("Writing to: " + out_fname)
out = open(out_fname, "w")
for line in open(in_fname):
        if not line or line[0] is "#":
                out.write(line)
        else:
                fields = line.split("\t")
                fields[3] = fields[3].replace("/", ",").replace("\\", ",")   # remove any slashes from REF field
                fields[4] = fields[4].replace("/", ",").replace("\\", ",")   # remove any slashes from ALT field
                out.write("\t".join(fields))
To use, just copy-paste into a file (lets say script.py) and run:

python script.py file.vcf


Also, this version of the script just removes the vcf records with slashes:

Code:
import sys

if len(sys.argv) < 2:  sys.exit("Usage: " + sys.argv[0] + "  vcf_filename")

in_fname = sys.argv[1]
out_fname = (in_fname[:-4] if in_fname.endswith(".vcf") else in_frame) + ".fixed.vcf"
print("Writing to: " + out_fname)
out = open(out_fname, "w")
for line in open(in_fname):
        if not line or line[0] is "#":
                out.write(line)
        else:
                fields = line.split("\t")
                if "\\" not in (fields[3]+fields[4]) and "/" not in (fields[3]+fields[4]):
                        out.write("\t".join(fields))

Last edited by bw.; 02-05-2014 at 01:16 PM. Reason: Turns out slashes also sometimes appear in the REF field, so added checks for that.
bw. is offline   Reply With Quote