Mercurial > repos > iuc > trycycler_consensus
comparison trycycler.py @ 0:93c6a7423090 draft
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
author | iuc |
---|---|
date | Thu, 11 Feb 2021 19:24:35 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:93c6a7423090 |
---|---|
1 #!/usr/bin/env python3 | |
2 | |
3 from os import path, walk | |
4 from sys import argv | |
5 | |
6 | |
7 def cluster(output_folder): | |
8 counter = 1 | |
9 for root, dir, files in walk(output_folder): | |
10 if root.endswith('1_contigs'): | |
11 output_path = path.join(output_folder, f"cluster_0{counter}.fasta") | |
12 with open(output_path, "a") as out_cluster: | |
13 for fasta in files: | |
14 fasta_path = path.join(root, fasta) | |
15 fasta = open(fasta_path).read() | |
16 out_cluster.write(fasta) | |
17 counter += 1 | |
18 | |
19 | |
20 def reconcile(input_file): | |
21 number_cluster = [x for x in input_file[-1:0:-1] if x.isdigit()][0] | |
22 full_path = f"selected_cluster/cluster_0{number_cluster}/1_contigs/" | |
23 with open(input_file) as tmp: | |
24 for line in tmp: | |
25 if ">" in line: | |
26 filename = line[1:].strip() | |
27 output_fasta = f"{full_path}{filename}.fasta" | |
28 with open(output_fasta, "a") as handle: | |
29 handle.write(line) | |
30 | |
31 | |
32 def main(): | |
33 if argv[1] == "cluster": | |
34 cluster(argv[2]) | |
35 if argv[1] == "reconcile": | |
36 reconcile(argv[2]) | |
37 | |
38 | |
39 if __name__ == "__main__": | |
40 main() |