-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_logos.py
28 lines (24 loc) · 1.22 KB
/
make_logos.py
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
import os
import sys
import numpy as np
import pandas as pd
import subprocess
import StringIO
from optparse import OptionParser
parser=OptionParser()
parser.add_option('-i','--inf',dest='motif_definitions',help="""file with motif_definitions for logo generation""")
parser.add_option('-o','--outdir',dest='outdir',help="""output directory""")
options,args=parser.parse_args()
if not os.path.isdir(options.outdir):
print >> sys.stderr, 'creating output directory '+options.outdir
os.mkdir(options.outdir)
print >> sys.stderr, 'creating sequence logos using motif definitions from '+options.motif_definitions
for line in open(options.motif_definitions):
motif=line.split()[0]
kmers=line.split()[1].split(',')
print >> sys.stderr, motif
seqs='\n'.join('>seq_{0}\n{1}'.format(n,s) for n,s in enumerate(kmers))
mout,merr=subprocess.Popen(['muscle'],stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE).communicate(seqs)
outfile=os.path.join(options.outdir,'{0}.png'.format(motif))
wout,werr=subprocess.Popen(['weblogo','-F','png_print','-A','dna','-X','no','-Y','no','-P','','-c','classic','--errorbars','no','-o',outfile],\
stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE).communicate(mout)