-
Notifications
You must be signed in to change notification settings - Fork 0
/
buscofinder.py
executable file
·50 lines (49 loc) · 1.87 KB
/
buscofinder.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
#!/usr/bin/env python3
import argparse
import os
#retreive user arguments
parser = argparse.ArgumentParser()
parser.add_argument("-b", "--score", help = "type of busco score", default = "M")
parser.add_argument("-m", "--max_score", help = "max acceptible score", default = 10, type = float)
args = parser.parse_args()
#make empty string that will hold final names and scores
fin_string = ""
#iterate through each file in directory
for file in os.scandir("/mnt/lustre/macmaneslab/nah1004/transcriptomes/reports"):
if file.name.startswith("qual"):
if file.name.endswith("v2"):
#iterate through file to find desired scores
try:
with open( file, "r") as in_handle:
line = in_handle.readline()
line = line.strip()
bad_list = line.split()
wanted_item = bad_list[-1].replace("[", ",")
wanted_item = wanted_item.replace("]","")
scores_list = wanted_item.split(",")
scores_dict = {}
#obtain only items from list that will be necessary for pertaining score and its name
for scores in scores_list:
element = scores.split(":")
ID = element[0]
score = float(element[1].strip("%"))
scores_dict[ID]=score
arguments = scores_dict[args.score]
new_name = file.name.replace("qualreport.", "").replace("_v2", "")
#only look for scores that are either above or below a particular threshold, given by user
print("T1: {}".format(scores_dict[args.score]))
if args.score in "CDS":
if scores_dict[args.score] > args.max_score:
fin_string += "{}\t{}\n".format(new_name, arguments)
else:
if scores_dict[args.score] < args.max_score:
fin_string += "{}\t{}\n".format(new_name, arguments)
except IOError as err:
print(err)
print(fin_string)
#write parsed through information to new file
try:
with open ("names_scores.txt", "w") as in_handle:
in_handle.write(fin_string)
except IOError as err:
print ( err )