I am running a Java tool called snpSift and would like to run it on multiple files. As such I am using a pythong script and using subprocess. The actual command I am trying to create a string of is:
java -jar SnpSift.jar filter "ANN[0].EFFECT has 'variant'" input.vcf > ~/output.vcf
This command is correct as I have used it directly on the command line myself. I have created a list called variantType which contains strings of different variants that I intend to use as a variable when running snpSift.
I am trying to create another list (command) that will contain the entire command line input as a string for each file and each variantType. My script is below:
command = []
for file in os.listdir("filepath"):
absfile = os.path.abspath(file)
if(file.endswith(".vcf")):
for i in variantType:
w = 'java -jar SnpSift.jar filter "'
x = "ANN[0].EFFECT has "
y = "'" + i + "'"
z = '" ' + absfile + " > output." + i + "." + str(file)
command.append(w+x+y+z)
My issue is that the input for the filter has to have quotation marks in this manner: "ANN[0].EFFECT has 'variant'"
My attempts to do this using double quotation marks have failed, and result in the following output:
'java -jar SnpSift.jar filter "ANN[0].EFFECT has \'transcript_ablation\'" input.vcf > ~output.vcf'
How can I remove those '\' characters? If I print y (the variable containing that part of the entire string) these characters are not printed, but when I print the entire command, they are there, and therefore I cannot run the command properly.
EDIT
When I use:
print(command[0])
This prints the desired command (without the '\').
It is only when I use:
command[0]
That the issue occurs.