How to redirect HyPhy output to text file
2
0
Entering edit mode
18 months ago
Alon • 0

I want to run FUBAR from a python script and redirect the output to a text file so that I can perform some additional analysis on it. I have this working line of code:

os.system("echo `(echo '1'; echo '4'; echo '/myfile.fasta'; echo '/myfile.nwk') | hyphy `")

How do I modify it to redirect the output to a text file in the same directory?

FUBAR BASH HyPhy Python • 656 views
ADD COMMENT
1
Entering edit mode
18 months ago
Alon • 0

I figured it out.

os.system("echo `(echo '1'; echo '4'; echo '/myfile.fasta'; echo '/mytree.nwk') | hyphy ` > /results.txt")
ADD COMMENT
1
Entering edit mode
18 months ago
zorbax ▴ 610

I think you need to use subprocess for better control of your file descriptors.

import subprocess

cmd = "hyphy --alignment myfile.fasta --tree myfile.nwk"
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()
ADD COMMENT
0
Entering edit mode

Thank you for your comment. I'm aware that subprocess is preferred these days but it is more complicated and I think os.system is good enough for this purpose.

ADD REPLY

Login before adding your answer.

Traffic: 2576 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6