forked from emmacampagnolo/alignmentfree
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloading.py
More file actions
34 lines (24 loc) · 747 Bytes
/
loading.py
File metadata and controls
34 lines (24 loc) · 747 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
30
31
32
33
34
from os import listdir, path
def load_fna(filename):
texts = []
txt = []
with open(filename) as fp:
for line in fp:
if line[0] == '>':
if len(txt) > 0:
texts.append("".join(txt))
txt = []
else:
txt.append(line.strip())
if len(txt) > 0:
texts.append("".join(txt))
return texts
def load_directory(directory):
files = {}
for filename in listdir(directory):
if filename[filename.rfind('.')+1:] in ["fa", "fasta", "fna"]:
files[filename] = load_fna(path.join(directory, filename))
return files
if __name__ == "__main__":
files = load_directory("data")
print(len(files))