I have one input file (inputFile) that needs to undergo six filtering steps with six different 'BED' files. After every single filter, there results a new input file. I need to use these for input to the next iteration of my loop and so on until the initial file has undergone six iterations with all six of my BED files.
Here is my current code. The loop works for the first two calls but then stops and says that it cannot open the file that got created after the second iteration. Any advice is greatly appreciated.
samples = [0, 1, 2, 3, 4, 5]
fileName = ["first", "second", "third", "fourth", "fifth"]
inputFile = fileOne
for x in samples:
orderName = fileName[x] + sampleCapture + ".bed"
outputFile = open(orderName, "w")
bedFile = filterFiles[x]
subprocess.Popen(["bedtools", "intersect", "-a", inputFile, "-b", bedFile, "-v"],
stdout=outputFile)
outputFile.close()
inputFile = fileName[x] + sampleCapture + ".bed"
Popen
returns immediately. You should usecheck_call()
instead (as @cel mentioned):