annotate trycycler.py @ 6:af40e971a8cc draft default tip

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit e9abd8b86133e530d0395d85bca320a1af27a9b6
author iuc
date Tue, 02 Apr 2024 08:29:45 +0000
parents 8fcec9049d68
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
8fcec9049d68 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff changeset
1 #!/usr/bin/env python3
8fcec9049d68 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff changeset
2
8fcec9049d68 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff changeset
3 from os import path, walk
8fcec9049d68 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff changeset
4 from sys import argv
8fcec9049d68 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff changeset
5
8fcec9049d68 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff changeset
6
8fcec9049d68 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff changeset
7 def cluster(output_folder):
8fcec9049d68 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff changeset
8 counter = 1
8fcec9049d68 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff changeset
9 for root, dir, files in walk(output_folder):
8fcec9049d68 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff changeset
10 if root.endswith('1_contigs'):
8fcec9049d68 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff changeset
11 output_path = path.join(output_folder, f"cluster_0{counter}.fasta")
8fcec9049d68 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff changeset
12 with open(output_path, "a") as out_cluster:
8fcec9049d68 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff changeset
13 for fasta in files:
8fcec9049d68 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff changeset
14 fasta_path = path.join(root, fasta)
8fcec9049d68 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff changeset
15 fasta = open(fasta_path).read()
8fcec9049d68 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff changeset
16 out_cluster.write(fasta)
8fcec9049d68 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff changeset
17 counter += 1
8fcec9049d68 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff changeset
18
8fcec9049d68 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff changeset
19
8fcec9049d68 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff changeset
20 def reconcile(input_file):
8fcec9049d68 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff changeset
21 number_cluster = [x for x in input_file[-1:0:-1] if x.isdigit()][0]
8fcec9049d68 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff changeset
22 full_path = f"selected_cluster/cluster_0{number_cluster}/1_contigs/"
8fcec9049d68 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff changeset
23 with open(input_file) as tmp:
8fcec9049d68 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff changeset
24 for line in tmp:
8fcec9049d68 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff changeset
25 if ">" in line:
8fcec9049d68 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff changeset
26 filename = line[1:].strip()
8fcec9049d68 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff changeset
27 output_fasta = f"{full_path}{filename}.fasta"
8fcec9049d68 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff changeset
28 with open(output_fasta, "a") as handle:
8fcec9049d68 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff changeset
29 handle.write(line)
8fcec9049d68 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff changeset
30
8fcec9049d68 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff changeset
31
8fcec9049d68 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff changeset
32 def main():
8fcec9049d68 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff changeset
33 if argv[1] == "cluster":
8fcec9049d68 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff changeset
34 cluster(argv[2])
8fcec9049d68 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff changeset
35 if argv[1] == "reconcile":
8fcec9049d68 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff changeset
36 reconcile(argv[2])
8fcec9049d68 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff changeset
37
8fcec9049d68 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff changeset
38
8fcec9049d68 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff changeset
39 if __name__ == "__main__":
8fcec9049d68 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff changeset
40 main()