-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsplitGenome.py
38 lines (33 loc) · 1.02 KB
/
splitGenome.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
#!/usr/bin/env python
import os
import sys
def openfile(path: str):
lines = []
with open(path, 'r', encoding='utf-8') as f_open:
file_lines = f_open.read().split('\n')
for line in file_lines:
if len(line) == 0 or '#' == line[0]:
continue
lines.append(line)
return lines
def block_cacher_v2(lines: list, separator_first: str):
file_blocks = []
block = []
for line in lines:
if len(line) == 0:
continue
if line.startswith(separator_first):
if len(block) > 0:
file_blocks.append(block)
block = [line]
continue
block.append(line)
if len(block) > 0:
file_blocks.append(block)
return file_blocks
d = './'+'.'.join(sys.argv[1].split('.')[:-1])
os.makedirs(d)
for block in block_cacher_v2(openfile(sys.argv[1]), '>'):
b = '\n'.join(block)
with open(d+'/'+'_'.join(block[0][1:].strip().split())+'.fasta', 'w')as f:
f.write(b)