annotate trycycler.py @ 0:4ac81df20c74 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:26:05 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
4ac81df20c74 "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
4ac81df20c74 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff changeset
2
4ac81df20c74 "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
4ac81df20c74 "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
4ac81df20c74 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff changeset
5
4ac81df20c74 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff changeset
6
4ac81df20c74 "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):
4ac81df20c74 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff changeset
8 counter = 1
4ac81df20c74 "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):
4ac81df20c74 "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'):
4ac81df20c74 "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")
4ac81df20c74 "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:
4ac81df20c74 "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:
4ac81df20c74 "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)
4ac81df20c74 "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()
4ac81df20c74 "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)
4ac81df20c74 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff changeset
17 counter += 1
4ac81df20c74 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff changeset
18
4ac81df20c74 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff changeset
19
4ac81df20c74 "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):
4ac81df20c74 "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]
4ac81df20c74 "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/"
4ac81df20c74 "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:
4ac81df20c74 "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:
4ac81df20c74 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff changeset
25 if ">" in line:
4ac81df20c74 "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()
4ac81df20c74 "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"
4ac81df20c74 "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:
4ac81df20c74 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff changeset
29 handle.write(line)
4ac81df20c74 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff changeset
30
4ac81df20c74 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff changeset
31
4ac81df20c74 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff changeset
32 def main():
4ac81df20c74 "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":
4ac81df20c74 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff changeset
34 cluster(argv[2])
4ac81df20c74 "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":
4ac81df20c74 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff changeset
36 reconcile(argv[2])
4ac81df20c74 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff changeset
37
4ac81df20c74 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff changeset
38
4ac81df20c74 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff changeset
39 if __name__ == "__main__":
4ac81df20c74 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff changeset
40 main()