Writing a python module to run Infernal on a list of fasta files I am very new to using python3 and am hoping to use it to reduce the time I need to spend running Infernal to look for a variety of RNAs in a large collection of bacterial genomes. I am hoping to write a short module in python that will let me sequentially run infernal using a single covariance model on a list of genome files. 

At the moment I am trying to use subprocess.run() or subprocess.Popen() to do so. 


import subprocess
import os 
import glob

genomes = list(glob.glob(os.path.join("/path/to/genomes/", "*.fa")))

for x in files:
    subprocess.Popen(args=["cmsearch", "/path/to/covariancemodel/", "genomes"], shell=False)


my issue is I do not know a way to have "genomes" passed as the components of the list within the command. 

Is this a way off approach to trying to automate this? If so is there a better way to do it or is there a way to simply pass each file in the list to the cmsearch command?
I think what you want to do is:

import subprocess
import os 
import glob

genomes = glob.glob(os.path.join("/path/to/genomes/", "*.fa"))

for gfile in genomes:
    subprocess.Popen(args=["cmsearch", "/path/to/covariancemodel/", gfile], shell=False)


each pass through the for loop will take a one of the genome files and pass it into the cmsearch command. 

Note: 

1) glob.glob returns a list so no need to cast it again - https://docs.python.org/2/library/glob.html