-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtools.py
39 lines (36 loc) · 1.43 KB
/
tools.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
"""Misc. useful things"""
class Tracker(object):
"""Tracks progress of task"""
def __init__(self, name, size, currPercentage=0, count=0):
self.name = name #name of task
self.size = size #total size of task (e.g. number of lines in file)
self.currPercentage = currPercentage #current percentage of task complete
self.count = count #absolute amount of task complete (e.g. number of lines of file read)
def increment(self):
if self.size !=0 and self.size is not None:
self.count += 1
newPercentage = self.currPercentage + 1
if float(self.count)/self.size >= float(newPercentage)/100: #if at least X% of the file has been read, print percentage
self.currPercentage = newPercentage
print("{} {}% complete".format(self.name, self.currPercentage))
def args_are_valid(args, names, intervals):
valid_args = True
for (arg, name, interval) in zip(args, names, intervals):
lower_bound = interval[0]
upper_bound = interval[1]
if lower_bound is not None:
if arg <= float(lower_bound):
print("Error. {} must be > {}.".format(name, lower_bound))
valid_args = False
if upper_bound is not None:
if arg >= float(upper_bound):
print("Error. {} must be < {}.".format(name, upper_bound))
valid_args = False
return valid_args
def get_res_string(res):
"""Converts resolution in bp to string (e.g. 10kb)"""
res_kb = int(res/1000)
if res_kb < 1000:
return str(res_kb) + "kb"
else:
return str(res_kb/1000) + "mb"