Mercurial > repos > iuc > trycycler_cluster
annotate trycycler.py @ 2:6f4c8ad6ea01 draft
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 692e4b196b413e87a4199d69532974f2a3021315"
author | iuc |
---|---|
date | Mon, 04 Oct 2021 16:23:20 +0000 |
parents | c767a45616d0 |
children |
rev | line source |
---|---|
0
c767a45616d0
"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 |
c767a45616d0
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff
changeset
|
2 |
c767a45616d0
"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 |
c767a45616d0
"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 |
c767a45616d0
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff
changeset
|
5 |
c767a45616d0
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff
changeset
|
6 |
c767a45616d0
"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): |
c767a45616d0
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff
changeset
|
8 counter = 1 |
c767a45616d0
"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): |
c767a45616d0
"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'): |
c767a45616d0
"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") |
c767a45616d0
"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: |
c767a45616d0
"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: |
c767a45616d0
"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) |
c767a45616d0
"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() |
c767a45616d0
"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) |
c767a45616d0
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff
changeset
|
17 counter += 1 |
c767a45616d0
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff
changeset
|
18 |
c767a45616d0
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff
changeset
|
19 |
c767a45616d0
"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): |
c767a45616d0
"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] |
c767a45616d0
"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/" |
c767a45616d0
"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: |
c767a45616d0
"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: |
c767a45616d0
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff
changeset
|
25 if ">" in line: |
c767a45616d0
"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() |
c767a45616d0
"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" |
c767a45616d0
"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: |
c767a45616d0
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff
changeset
|
29 handle.write(line) |
c767a45616d0
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff
changeset
|
30 |
c767a45616d0
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff
changeset
|
31 |
c767a45616d0
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff
changeset
|
32 def main(): |
c767a45616d0
"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": |
c767a45616d0
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff
changeset
|
34 cluster(argv[2]) |
c767a45616d0
"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": |
c767a45616d0
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff
changeset
|
36 reconcile(argv[2]) |
c767a45616d0
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff
changeset
|
37 |
c767a45616d0
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff
changeset
|
38 |
c767a45616d0
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff
changeset
|
39 if __name__ == "__main__": |
c767a45616d0
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/trycycler commit 9d7c4277b0f96aacd466f2d497e08edcca3fa238"
iuc
parents:
diff
changeset
|
40 main() |