-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatchs.py
59 lines (43 loc) · 1.2 KB
/
matchs.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
55
56
57
58
59
#!/user/bin/env python3
"""
Author: Gustavo Tamasco
Script to run:
The script takes:
Run the code by: ex_p5.py <reference_fasta_file> <related_fasta_file>
"""
# import statements
from sys import argv
import os.path
import subprocess
# functions and classes
def get_file(path):
"""This function creates the path for all your files
input: is a string with the path to your folder containing all files
Out: is a list of strings containing the path of all files
"""
files = []
for r, d, f in os.walk(path):
for file in f:
if '.txt' in file:
files.append(os.path.join(r,file))
return files
def get_match(file):
match = []
for line in file:
if 'NZ' not in line:
nm = line.split()[-1]
match.append(nm)
final_value = sum(map(int,match))
return(final_value)
def main():
"""Main code of the script"""
dirpath = '/Users/gustavotamasco/pantoea_aligner/teste'
files = get_file(dirpath)
for file in files:
with open(file) as i:
out_name = file.split('/')[-1][0:-4]
value = get_match(i)
print(out_name, value)
# main
if __name__ == '__main__':
main()