This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Emboss & Python : Suppress Printing Messages To Standard Output

I have a Python script running EMBOSS "needle" alignments using the os.system() command, and I find it unnecessary for it to print out:

(a) all error messages e.g.

Error: Sequence is not nucleic

(b) the standard "needle" message e.g.

Needleman-Wunsch global alignment of two sequences

Does anybody have a clean solution suppress these? Thanks in advance for your help.

python biopython output

3 answers

Have you read the documentation? There are some standard switches for all EMBOSS programs including:

General qualifiers:
-auto               boolean    Turn off prompts
-stdout             boolean    Write first file to standard output
-filter             boolean    Read first file from standard input, write
                              first file to standard output
-options            boolean    Prompt for standard and additional values
-debug              boolean    Write debug output to program.dbg
-verbose            boolean    Report some/full command line options
-help               boolean    Report command line options and exit. More
                              information on associated and general
                              qualifiers can be found with -help -verbose
-warning            boolean    Report warnings
-error              boolean    Report errors
-fatal              boolean    Report fatal errors
-die                boolean    Report dying program messages
-version            boolean    Report version number and exit

So in your case, -auto and -options will address issue (b) and some/all of -warning, -error, -fatal and -die will address issue (a).

Hi newilfws,

Thank you for your suggesstions. I think the error problems were solved, but I am not having luck suppressing the standard output messages described in (b), as they are not exactly prompts. If you have any additional insight into this I would greatly appreciate it.

Hi newilfws, Thank you for your suggestions. I think the error problems were solved, but I am not having luck suppressing the standard output messages described in (b), as they are not exactly prompts. If you have any additional insight into this I would greatly appreciate it

Have you tried the -auto switch? I just ran needle from the command line using it and the "needle message" is not printed.

My bad, this totally works, I was confusing the invocation syntax with the NeedleCommandline biopython wrapper. Thanks!

Maybe writing your system command like needle -params stuff > /dev/null? Dont't know if that python os.command handles it, but it works in shell.

Hi Michael, thanks for the suggestion. I did try this initially, along with a couple other permutations ("&> /dev/null", "> nul", etc.) without any success. It seems that the "-auto" switch is successful in suppressing the standard output, though.

You could use the NeedleCommandline object in Biopython for building the command line and executing it (It's in the Bio.Emboss.Applications module - see the tutorial http://biopython.org/DIST/docs/tutorial/Tutorial.html for an example).

Log in to answer this question.