Mercurial > repos > richard-burhans > segalign
annotate diagonal_partition.py @ 3:6f46cebc9ed8 draft
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit ceae325563385443efc190130916b5ba3818fa46
author | richard-burhans |
---|---|
date | Thu, 18 Apr 2024 17:22:46 +0000 |
parents | 9e34b25a8670 |
children | 36cafb694dd2 |
rev | line source |
---|---|
2
9e34b25a8670
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 288c3e1887d4c13dcc922c612957460471977ff0
richard-burhans
parents:
0
diff
changeset
|
1 #!/usr/bin/env python |
0
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
2 |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
3 """ |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
4 Diagonal partitioning for segment files output by SegAlign. |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
5 |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
6 Usage: |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
7 diagonal_partition <max-segments> <lastz-command> |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
8 """ |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
9 |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
10 import os |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
11 import sys |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
12 |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
13 |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
14 def chunks(lst, n): |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
15 """Yield successive n-sized chunks from list.""" |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
16 for i in range(0, len(lst), n): |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
17 yield lst[i: i + n] |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
18 |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
19 |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
20 if __name__ == "__main__": |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
21 |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
22 DELETE_AFTER_CHUNKING = True |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
23 |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
24 # input_params = "10000 sad sadsa sad --segments=tmp10.block5.r1239937044.plus.segments dsa sa --strand=plus --output=out.maf sadads 2> logging.err" |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
25 # sys.argv = [sys.argv[0]] + input_params.split(' ') |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
26 chunk_size = int(sys.argv[1]) # first parameter contains chunk size |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
27 params = sys.argv[2:] |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
28 |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
29 # Parsing command output from SegAlign |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
30 segment_key = "--segments=" |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
31 segment_index = None |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
32 input_file = None |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
33 |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
34 for index, value in enumerate(params): |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
35 if value[: len(segment_key)] == segment_key: |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
36 segment_index = index |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
37 input_file = value[len(segment_key):] |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
38 break |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
39 if segment_index is None: |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
40 print(f"Error: could not segment key {segment_key} in parameters {params}") |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
41 exit(0) |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
42 |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
43 if not os.path.isfile(input_file): |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
44 print(f"Error: File {input_file} does not exist") |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
45 exit(0) |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
46 |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
47 if ( |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
48 chunk_size == 0 or sum(1 for _ in open(input_file)) <= chunk_size |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
49 ): # no need to sort if number of lines <= chunk_size |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
50 print(" ".join(params), flush=True) |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
51 exit(0) |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
52 |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
53 # Find rest of relevant parameters |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
54 output_key = "--output=" |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
55 output_index = None |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
56 output_alignment_file = None |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
57 output_alignment_file_base = None |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
58 output_format = None |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
59 |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
60 strand_key = "--strand=" |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
61 strand_index = None |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
62 for index, value in enumerate(params): |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
63 if value[: len(output_key)] == output_key: |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
64 output_index = index |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
65 output_alignment_file = value[len(output_key):] |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
66 output_alignment_file_base, output_format = output_alignment_file.rsplit( |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
67 ".", 1 |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
68 ) |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
69 if value[: len(strand_key)] == strand_key: |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
70 strand_index = index |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
71 if segment_index is None: |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
72 print(f"Error: could not output key {output_key} in parameters {params}") |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
73 exit(0) |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
74 if strand_index is None: |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
75 print(f"Error: could not output key {strand_key} in parameters {params}") |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
76 exit(0) |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
77 |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
78 err_index = -1 # error file is at very end |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
79 err_name_base = params[-1].split(".err", 1)[0] |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
80 |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
81 data = {} # dict of list of tuple (x, y, str) |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
82 |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
83 direction = None |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
84 if "plus" in params[strand_index]: |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
85 direction = "f" |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
86 elif "minus" in params[strand_index]: |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
87 direction = "r" |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
88 else: |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
89 print( |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
90 f"Error: could not figure out direction from strand value {params[strand_index]}" |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
91 ) |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
92 exit(0) |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
93 |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
94 for line in open(input_file, "r"): |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
95 if line == "": |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
96 continue |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
97 ( |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
98 seq1_name, |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
99 seq1_start, |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
100 seq1_end, |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
101 seq2_name, |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
102 seq2_start, |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
103 seq2_end, |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
104 _dir, |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
105 score, |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
106 ) = line.split() |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
107 # data.append((int(seq1_start), int(seq2_start), line)) |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
108 half_dist = int((int(seq1_end) - int(seq1_start)) // 2) |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
109 assert int(seq1_end) > int(seq1_start) |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
110 assert int(seq2_end) > int(seq2_start) |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
111 seq1_mid = int(seq1_start) + half_dist |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
112 seq2_mid = int(seq2_start) + half_dist |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
113 data.setdefault((seq1_name, seq2_name), []).append((seq1_mid, seq2_mid, line)) |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
114 |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
115 # If there are chromosome pairs with segment count <= chunk_size |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
116 # then no need to sort and split these pairs into separate files. |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
117 # It is better to keep these pairs in a single segment file. |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
118 skip_pairs = [] # pairs that have count <= chunk_size. |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
119 # these will not be sorted |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
120 if len(data.keys()) > 1: |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
121 for pair in data.keys(): |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
122 if len(data[pair]) <= chunk_size: |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
123 skip_pairs.append(pair) |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
124 |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
125 # sorting for forward segments |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
126 if direction == "r": |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
127 for pair in data.keys(): |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
128 if pair not in skip_pairs: |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
129 data[pair] = sorted( |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
130 data[pair], key=lambda coord: (coord[1] - coord[0], coord[0]) |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
131 ) |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
132 # sorting for reverse segments |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
133 elif direction == "f": |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
134 for pair in data.keys(): |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
135 if pair not in skip_pairs: |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
136 data[pair] = sorted( |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
137 data[pair], key=lambda coord: (coord[1] + coord[0], coord[0]) |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
138 ) |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
139 else: |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
140 print(f"INVALID DIRECTION VALUE: {direction}") |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
141 exit(0) |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
142 |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
143 # Writing file in chunks |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
144 ctr = 0 |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
145 for pair in data.keys() - skip_pairs: |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
146 for chunk in chunks(list(zip(*data[pair]))[2], chunk_size): |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
147 ctr += 1 |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
148 name_addition = f".split{ctr}" |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
149 fname = input_file.split(".segments", 1)[0] + name_addition + ".segments" |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
150 |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
151 with open(fname, "w") as f: |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
152 f.writelines(chunk) |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
153 # update segment file in command |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
154 params[segment_index] = segment_key + fname |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
155 # update output file in command |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
156 params[output_index] = ( |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
157 output_key |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
158 + output_alignment_file_base |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
159 + name_addition |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
160 + "." |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
161 + output_format |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
162 ) |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
163 # update error file in command |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
164 params[-1] = err_name_base + name_addition + ".err" |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
165 print(" ".join(params), flush=True) |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
166 |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
167 # writing unsorted skipped pairs |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
168 if len(skip_pairs) > 0: |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
169 skip_pairs_with_len = sorted( |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
170 [(len(data[p]), p) for p in skip_pairs] |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
171 ) # list of tuples of (pair length, pair) |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
172 aggregated_skip_pairs = [] # list of list of pair names |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
173 current_count = 0 |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
174 aggregated_skip_pairs.append([]) |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
175 for count, pair in skip_pairs_with_len: |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
176 if current_count + count <= chunk_size: |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
177 current_count += count |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
178 aggregated_skip_pairs[-1].append(pair) |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
179 else: |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
180 aggregated_skip_pairs.append([]) |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
181 current_count = count |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
182 aggregated_skip_pairs[-1].append(pair) |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
183 |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
184 for aggregate in aggregated_skip_pairs: |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
185 ctr += 1 |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
186 name_addition = f".split{ctr}" |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
187 fname = input_file.split(".segments", 1)[0] + name_addition + ".segments" |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
188 with open(fname, "w") as f: |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
189 for pair in sorted(aggregate, key=lambda p: (p[1], p[0])): |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
190 chunk = list(zip(*data[pair]))[2] |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
191 f.writelines(chunk) |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
192 # update segment file in command |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
193 params[segment_index] = segment_key + fname |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
194 # update output file in command |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
195 params[output_index] = ( |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
196 output_key |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
197 + output_alignment_file_base |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
198 + name_addition |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
199 + "." |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
200 + output_format |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
201 ) |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
202 # update error file in command |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
203 params[-1] = err_name_base + name_addition + ".err" |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
204 print(" ".join(params), flush=True) |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
205 |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
206 if DELETE_AFTER_CHUNKING: |
5c72425b7f1b
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
richard-burhans
parents:
diff
changeset
|
207 os.remove(input_file) |