1
$\begingroup$

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

$\endgroup$

1 Answer 1

3
$\begingroup$

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.

$\endgroup$
1
  • 2
    $\begingroup$ I tested your first solution and worked very nicelly. Thank you by your time and patience. Paulo $\endgroup$ Commented Oct 30, 2021 at 13:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.