Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathtools.py
More file actions
Latest commit
39 lines (36 loc) · 1.43 KB
/
Copy pathtools.py
File metadata and controls
39 lines (36 loc) · 1.43 KB
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"""
classTracker(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)
defincrement(self):
ifself.size!=0andself.sizeisnotNone:
self.count+=1
newPercentage=self.currPercentage+1
iffloat(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))
defargs_are_valid(args, names, intervals):
valid_args=True
for (arg, name, interval) inzip(args, names, intervals):
lower_bound=interval[0]
upper_bound=interval[1]
iflower_boundisnotNone:
ifarg<=float(lower_bound):
print("Error. {} must be > {}.".format(name, lower_bound))
valid_args=False
ifupper_boundisnotNone:
ifarg>=float(upper_bound):
print("Error. {} must be < {}.".format(name, upper_bound))
valid_args=False
returnvalid_args
defget_res_string(res):
"""Converts resolution in bp to string (e.g. 10kb)"""
res_kb=int(res/1000)
ifres_kb<1000:
returnstr(res_kb) +"kb"
else:
returnstr(res_kb/1000) +"mb"