forked from Lammlab/Resic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpileup_sorting.py
executable file
·52 lines (33 loc) · 1.28 KB
/
pileup_sorting.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
"""pileup_sorting.
Usage:
pileup_sorting.py param
pileup_sorting.py example
pileup_sorting.py <pileup_in_file> <pileup_out_file>
pileup_sorting.py (-h | --help)
Options:
-h --help Show this screen.
"""
from docopt import docopt
# info : this file recives pileup file name and sort its lines according to their id and pos
from Utility.Pileup_class import Pileup_line
from Utility.generators_utilities import key_sorted_gen, class_generator
#key for sorting according to id and position of each line
#reciving pileup line
def get_key_tuple_from_pileup(line: Pileup_line):
return line.ref(),line.pos()[0]
def pileup_sort(in_pileup, out_pileup):
with open(in_pileup , "r") as file_pileup:
gen_pileup = class_generator(Pileup_line, file = file_pileup)
gen_sorted_pileup=key_sorted_gen(get_key_tuple_from_pileup,file=file_pileup,gen=gen_pileup)
open(out_pileup, "w").close()
for line in gen_sorted_pileup :
with open(out_pileup,"a+") as file1:
file1.write(line)
if __name__ == "__main__":
arguments = docopt(__doc__)
if arguments['param']:
parameters_description()
if arguments['example']:
example_description()
if (arguments['<pileup_in_file>'] and arguments['<pileup_out_file>']):
pileup_sort(arguments['<pileup_in_file>'],arguments['<pileup_out_file>'])