<p>You have to use command line options, not interactive prompts, like so:</p>
<pre><code>subprocess.call(['wordcount', '-sequence', filename, '-wordsize', sys.argv[1]], '-outfile', filename + '.wordcount.txt')
</code></pre>
<p>Or, using the <a href="https://docs.python.org/reference/lexical_analysis.html#f-strings" rel="nofollow noreferrer">f-strings or formatted string literals</a>:</p>
<pre><code>subprocess.call(f'wordcount -sequence {filename} -wordsize {sys.argv[1]} -outfile {filename}.wordcount.txt')
</code></pre>
<p>Note that I had to add <code>-outfile</code> option to your system call, otherwise <code>wordcount</code> prompts for the output file. See <a href="https://www.bioinformatics.nl/cgi-bin/emboss/help/wordcount" rel="nofollow noreferrer"><code>wordcount</code> manual</a>.</p>

CC BY-SA 4.0
2021-10-30T13:07:15.703Z
I tested your first solution and worked very nicelly. Thank you by your time and patience. Paulo
Paulo Sergio Schlogl
CC BY-SA 4.0
2021-10-30T00:59:19.513Z
2021-10-30T01:17:43.837Z
2021-10-30T01:17:43.837Z
Timur Shtatland
<p>Hi guys I would like to run wordcount from Emboss in a bunch of fasta files. I tried this:</p>
<pre><code>#!/usr/bin/env python
import sys
import subprocess



filenames = ['Downloads/Data/GCF_000016725.1_chr.fna']
for filename in filenames:
    name = filename.split('/')[2]
    print(filename)
    subprocess.call (['wordcount', 'Input sequence(s): ' + filename, 'Word size [4]: ' + sys.argv[1]])
</code></pre>
<p>But I got error messages:</p>
<pre><code>Count and extract unique words in molecular sequence(s)
Error: Failed to open filename 'Input sequence(s): Downloads/Data/GCF_000016725.1_chr.fna'
Error: Unable to read sequence 'Input sequence(s): Downloads/Data/GCF_000016725.1_chr.fna'
Died: wordcount terminated: Bad value for '-sequence' and no prompt
</code></pre>
<p>But if a use shell with Downloads/Data/GCF_000016725.1_chr.fna  it works fine!</p>
<p>Any tip would be helpful!
I am using python, but I would have a method to compare my results!</p>
<p>Thank you by your time!</p>
<p>Paulo</p>

<python><emboss>
Using python to call Emboss wordcount
# Using python to call Emboss wordcount

(Asked by: username_0 on 2021-10-29)

Hi guys I would like to run wordcount from Emboss in a bunch of fasta files. I tried this:
#!/usr/bin/env python
import sys
import subprocess



filenames = ['Downloads/Data/GCF_000016725.1_chr.fna']
for filename in filenames:
    name = filename.split('/')[2]
    print(filename)
    subprocess.call (['wordcount', 'Input sequence(s): ' + filename, 'Word size [4]: ' + sys.argv[1]])

But I got error messages:
Count and extract unique words in molecular sequence(s)
Error: Failed to open filename 'Input sequence(s): Downloads/Data/GCF_000016725.1_chr.fna'
Error: Unable to read sequence 'Input sequence(s): Downloads/Data/GCF_000016725.1_chr.fna'
Died: wordcount terminated: Bad value for '-sequence' and no prompt

But if a use shell with Downloads/Data/GCF_000016725.1_chr.fna  it works fine!
Any tip would be helpful!
I am using python, but I would have a method to compare my results!
Thank you by your time!
Paulo

**Tags:** python, emboss

---

## 1 answers

### Answer by username_1 on 2021-10-30. Score: 3 | Accepted answer

You have to use command line options, not interactive prompts, like so:
subprocess.call(['wordcount', '-sequence', filename, '-wordsize', sys.argv[1]], '-outfile', filename + '.wordcount.txt')

Or, using the f-strings or formatted string literals:
subprocess.call(f'wordcount -sequence {filename} -wordsize {sys.argv[1]} -outfile {filename}.wordcount.txt')

Note that I had to add -outfile option to your system call, otherwise wordcount prompts for the output file. See wordcount manual.

> **Comments:**
> **username_0**: I tested your first solution and worked very nicelly. Thank you by your time and patience. Paulo  

---

