Reputation: 1213
I'm trying to run a series of commands for two input files, but I want to avoid doing the same thing if it has already been done. To make it more clear, these are my commands:
from subprocess import call
import os.path
pathway = raw_input("Please give the pathway of your Genome Folder ( .fa files): ")
genome= raw_input("Please type your genome name (e.g. chick_build2.1):" )
#Building a genome (.stidx for stampy)
cmd = "python /space/tierzucht/mgholami/stampy-1.0.13/stampy.py -G %s %s/*.fa" %(genome, pathway)
#Building a genome (.fa for BWA)
cmd = "cat %s/*.fa > %s.fa" %(pathway, genome)
#Building an index (for BWA)
cmd = "bwa index %s.fa " %(genome)
call(cmd, shell=True)
and what I want to do is to add an if loop before each command that if the file already exists do not run this command. I tried this but it doesn't work:
if os.path.isfile("%s.stidx") %genome == False:
cmd = "python /space/tierzucht/mgholami/stampy-1.0.13/stampy.py -G %s %s/*.fa" %(genome, pathway)
what I'm trying to do is to check if the stidx format of the chosen file name already exists! And I want to do it with fa format and several others too.
Upvotes: 1
Views: 154
Reputation: 500893
Try:
if not os.path.isfile("%s.stidx"%genome):
cmd = "python /space/tierzucht/mgholami/stampy-1.0.13/stampy.py -G %s %s/*.fa" %(genome, pathway)
In your original code, the paretheses were misplaced (the %
was getting interpreted as the remainder operator, so the interpreter did not complain about a syntax error).
Upvotes: 1