-
Notifications
You must be signed in to change notification settings - Fork 0
/
custtools.py
executable file
·42 lines (34 loc) · 939 Bytes
/
custtools.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
# functions for repeated tasks
def read_dataset(fname):
""" read dataset and merge all lines into a string """
seq = ''
f = open(fname,'r')
seq = ''.join([line.replace('\n','') for line in f.readlines() if line[:1] != '>'])
return seq
def read_dataset_multiple(fname):
""" read dataset and append distinct strings """
result = {}
f = open(fname,'r')
for line in f.readlines():
line = line.replace('\n','')
if line[:1] == '>':
if not result.has_key(line):
k = line
result[k] = ''
else:
result[k] += line
return result
def read_dataset_multiple_anon(fname):
""" read dataset and append distinct strings """
result = []
tmp = ''
f = open(fname,'r')
for line in f.readlines():
line = line.replace('\n','')
if line[:1] == '>':
if tmp != '': result.append(tmp)
tmp = ''
else:
tmp += line
if tmp != '': result.append(tmp)
return result