-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathextract_dn_ds.py
More file actions
executable file
·29 lines (21 loc) · 876 Bytes
/
Copy pathextract_dn_ds.py
File metadata and controls
executable file
·29 lines (21 loc) · 876 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env python
from __future__ import print_function
import argparse
import os
import subprocess
# arguments
parser = argparse.ArgumentParser()
parser.add_argument('-dir', help='directory containing codeml output files with suffix "codeml.out"', required=True)
args = parser.parse_args()
# grab out files
codeml_outs = [x for x in os.listdir(args.dir) if x.endswith('codeml.out')]
os.chdir(args.dir)
print('gene\tlength\tdN\tdS')
for run in codeml_outs:
gene = run.split('.')[0]
length = run.split('.')[1]
grep_cmd = 'grep "tree length for" {}'.format(run.replace('(', '\(').replace(')', '\)').replace("'", "\\'"))
dndsdata = subprocess.Popen(grep_cmd, shell=True, stdout=subprocess.PIPE).communicate()[0].split('\n')[:-1]
dn = float(dndsdata[0].split()[-1])
ds = float(dndsdata[1].split()[-1])
print(gene, length, dn, ds, sep='\t')