-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
54 lines (41 loc) · 1.41 KB
/
utils.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import os
import PIL
from distutils.spawn import find_executable
try:
meme_path = "/%s" % find_executable('meme').strip("meme")
except AttributeError:
# Temporary setting for my server
meme_path = "/home/caleb/anaconda2/envs/MARS/bin"
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
def mkdir_p(path):
import os
import errno
try:
os.makedirs(path)
except OSError as exc:
if exc.errno == errno.EEXIST and os.path.isdir(path):
pass
else:
raise
def tab2fasta(posneg, fasta, background):
i = 0
# print fasta
with open(posneg) as tab:
with open(fasta, 'w') as fa:
with open(background, 'w') as bg:
for line in tab:
details = line.split()
if len(details) == 2:
pos = 1
else:
pos = 2
if i < 500:
fa.write(">" + line.split()[0] + '\n' + line.split()[pos] + "\n")
else:
bg.write(">" + line.split()[0] + '\n' + line.split()[pos] + "\n")
i += 1
def rotate_image(figure_in, figure_out):
src_im = PIL.Image.open(figure_in)
im = src_im.rotate(270, expand=True)
im.save(figure_out)
revcompl = lambda x: ''.join([{'A': 'T', 'C': 'G', 'G': 'C', 'T': 'A'}[B] for B in x][::-1])