annotate trycycler.py @ 4:05bd7504fdb2 draft

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