text: user7137: 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? 
  
  user964: 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
  
original_text: 7137: <p>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. </p>
  
  <p>At the moment I am trying to use subprocess.run() or subprocess.Popen() to do so. </p>
  
  <pre class="lang-py prettyprint-override"><code>
  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)
  </code></pre>
  
  <p>my issue is I do not know a way to have "genomes" passed as the components of the list within the command. </p>
  
  <p>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? </p>
   964: <p>I think what you want to do is:</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>each pass through the for loop will take a one of the genome files and pass it into the cmsearch command. </p>
  
  <p>Note: </p>
  
  <p>1) glob.glob returns a list so no need to cast it again - <a href="https://docs.python.org/2/library/glob.html" rel="nofollow noreferrer">https://docs.python.org/2/library/glob.html</a></p>
  