Mercurial > repos > thanhlv > plasmidtron
annotate tidy.py @ 0:814eed3d4f3e draft default tip
planemo upload for repository https://github.com/quadram-institute-bioscience/galaxy-tools/tree/master/tools/plasmidtron commit d2ae53b6ee23d56d26e9add8fe5ade2e20e75b87-dirty
author | thanhlv |
---|---|
date | Thu, 11 Apr 2019 04:51:28 -0400 |
parents | |
children |
rev | line source |
---|---|
0
814eed3d4f3e
planemo upload for repository https://github.com/quadram-institute-bioscience/galaxy-tools/tree/master/tools/plasmidtron commit d2ae53b6ee23d56d26e9add8fe5ade2e20e75b87-dirty
thanhlv
parents:
diff
changeset
|
1 #!/usr/bin/env python |
814eed3d4f3e
planemo upload for repository https://github.com/quadram-institute-bioscience/galaxy-tools/tree/master/tools/plasmidtron commit d2ae53b6ee23d56d26e9add8fe5ade2e20e75b87-dirty
thanhlv
parents:
diff
changeset
|
2 |
814eed3d4f3e
planemo upload for repository https://github.com/quadram-institute-bioscience/galaxy-tools/tree/master/tools/plasmidtron commit d2ae53b6ee23d56d26e9add8fe5ade2e20e75b87-dirty
thanhlv
parents:
diff
changeset
|
3 import sys |
814eed3d4f3e
planemo upload for repository https://github.com/quadram-institute-bioscience/galaxy-tools/tree/master/tools/plasmidtron commit d2ae53b6ee23d56d26e9add8fe5ade2e20e75b87-dirty
thanhlv
parents:
diff
changeset
|
4 import os |
814eed3d4f3e
planemo upload for repository https://github.com/quadram-institute-bioscience/galaxy-tools/tree/master/tools/plasmidtron commit d2ae53b6ee23d56d26e9add8fe5ade2e20e75b87-dirty
thanhlv
parents:
diff
changeset
|
5 # from pathlib import Path |
814eed3d4f3e
planemo upload for repository https://github.com/quadram-institute-bioscience/galaxy-tools/tree/master/tools/plasmidtron commit d2ae53b6ee23d56d26e9add8fe5ade2e20e75b87-dirty
thanhlv
parents:
diff
changeset
|
6 |
814eed3d4f3e
planemo upload for repository https://github.com/quadram-institute-bioscience/galaxy-tools/tree/master/tools/plasmidtron commit d2ae53b6ee23d56d26e9add8fe5ade2e20e75b87-dirty
thanhlv
parents:
diff
changeset
|
7 |
814eed3d4f3e
planemo upload for repository https://github.com/quadram-institute-bioscience/galaxy-tools/tree/master/tools/plasmidtron commit d2ae53b6ee23d56d26e9add8fe5ade2e20e75b87-dirty
thanhlv
parents:
diff
changeset
|
8 def make_list(tmp_file, lst_file): |
814eed3d4f3e
planemo upload for repository https://github.com/quadram-institute-bioscience/galaxy-tools/tree/master/tools/plasmidtron commit d2ae53b6ee23d56d26e9add8fe5ade2e20e75b87-dirty
thanhlv
parents:
diff
changeset
|
9 dividers = ["_1", "_F", "_R1", "_2", "_R", "_R2"] |
814eed3d4f3e
planemo upload for repository https://github.com/quadram-institute-bioscience/galaxy-tools/tree/master/tools/plasmidtron commit d2ae53b6ee23d56d26e9add8fe5ade2e20e75b87-dirty
thanhlv
parents:
diff
changeset
|
10 with open(tmp_file, "r") as fh: |
814eed3d4f3e
planemo upload for repository https://github.com/quadram-institute-bioscience/galaxy-tools/tree/master/tools/plasmidtron commit d2ae53b6ee23d56d26e9add8fe5ade2e20e75b87-dirty
thanhlv
parents:
diff
changeset
|
11 lines = fh.readlines() |
814eed3d4f3e
planemo upload for repository https://github.com/quadram-institute-bioscience/galaxy-tools/tree/master/tools/plasmidtron commit d2ae53b6ee23d56d26e9add8fe5ade2e20e75b87-dirty
thanhlv
parents:
diff
changeset
|
12 _lines = [] |
814eed3d4f3e
planemo upload for repository https://github.com/quadram-institute-bioscience/galaxy-tools/tree/master/tools/plasmidtron commit d2ae53b6ee23d56d26e9add8fe5ade2e20e75b87-dirty
thanhlv
parents:
diff
changeset
|
13 processed_list = [] |
814eed3d4f3e
planemo upload for repository https://github.com/quadram-institute-bioscience/galaxy-tools/tree/master/tools/plasmidtron commit d2ae53b6ee23d56d26e9add8fe5ade2e20e75b87-dirty
thanhlv
parents:
diff
changeset
|
14 for i in range(0,len(lines)): |
814eed3d4f3e
planemo upload for repository https://github.com/quadram-institute-bioscience/galaxy-tools/tree/master/tools/plasmidtron commit d2ae53b6ee23d56d26e9add8fe5ade2e20e75b87-dirty
thanhlv
parents:
diff
changeset
|
15 if (os.path.splitext(lines[i].strip())[-1] == ".fasta") or (os.path.splitext(lines[i].strip())[-1] == ".fa"): |
814eed3d4f3e
planemo upload for repository https://github.com/quadram-institute-bioscience/galaxy-tools/tree/master/tools/plasmidtron commit d2ae53b6ee23d56d26e9add8fe5ade2e20e75b87-dirty
thanhlv
parents:
diff
changeset
|
16 _lines.append(lines[i].strip()) |
814eed3d4f3e
planemo upload for repository https://github.com/quadram-institute-bioscience/galaxy-tools/tree/master/tools/plasmidtron commit d2ae53b6ee23d56d26e9add8fe5ade2e20e75b87-dirty
thanhlv
parents:
diff
changeset
|
17 else: |
814eed3d4f3e
planemo upload for repository https://github.com/quadram-institute-bioscience/galaxy-tools/tree/master/tools/plasmidtron commit d2ae53b6ee23d56d26e9add8fe5ade2e20e75b87-dirty
thanhlv
parents:
diff
changeset
|
18 file_name = os.path.basename(lines[i]) |
814eed3d4f3e
planemo upload for repository https://github.com/quadram-institute-bioscience/galaxy-tools/tree/master/tools/plasmidtron commit d2ae53b6ee23d56d26e9add8fe5ade2e20e75b87-dirty
thanhlv
parents:
diff
changeset
|
19 if file_name not in processed_list: |
814eed3d4f3e
planemo upload for repository https://github.com/quadram-institute-bioscience/galaxy-tools/tree/master/tools/plasmidtron commit d2ae53b6ee23d56d26e9add8fe5ade2e20e75b87-dirty
thanhlv
parents:
diff
changeset
|
20 detected_devider = [div for div in dividers if div in file_name] |
814eed3d4f3e
planemo upload for repository https://github.com/quadram-institute-bioscience/galaxy-tools/tree/master/tools/plasmidtron commit d2ae53b6ee23d56d26e9add8fe5ade2e20e75b87-dirty
thanhlv
parents:
diff
changeset
|
21 if len(detected_devider) > 0: |
814eed3d4f3e
planemo upload for repository https://github.com/quadram-institute-bioscience/galaxy-tools/tree/master/tools/plasmidtron commit d2ae53b6ee23d56d26e9add8fe5ade2e20e75b87-dirty
thanhlv
parents:
diff
changeset
|
22 detected_devider = detected_devider[0] |
814eed3d4f3e
planemo upload for repository https://github.com/quadram-institute-bioscience/galaxy-tools/tree/master/tools/plasmidtron commit d2ae53b6ee23d56d26e9add8fe5ade2e20e75b87-dirty
thanhlv
parents:
diff
changeset
|
23 new_file_name = file_name.split(detected_devider)[0] |
814eed3d4f3e
planemo upload for repository https://github.com/quadram-institute-bioscience/galaxy-tools/tree/master/tools/plasmidtron commit d2ae53b6ee23d56d26e9add8fe5ade2e20e75b87-dirty
thanhlv
parents:
diff
changeset
|
24 for j in range(i+1, len(lines)): |
814eed3d4f3e
planemo upload for repository https://github.com/quadram-institute-bioscience/galaxy-tools/tree/master/tools/plasmidtron commit d2ae53b6ee23d56d26e9add8fe5ade2e20e75b87-dirty
thanhlv
parents:
diff
changeset
|
25 if new_file_name in lines[j]: |
814eed3d4f3e
planemo upload for repository https://github.com/quadram-institute-bioscience/galaxy-tools/tree/master/tools/plasmidtron commit d2ae53b6ee23d56d26e9add8fe5ade2e20e75b87-dirty
thanhlv
parents:
diff
changeset
|
26 paired = "{},{}".format(lines[i].strip(), lines[j].strip()) |
814eed3d4f3e
planemo upload for repository https://github.com/quadram-institute-bioscience/galaxy-tools/tree/master/tools/plasmidtron commit d2ae53b6ee23d56d26e9add8fe5ade2e20e75b87-dirty
thanhlv
parents:
diff
changeset
|
27 _lines.append(paired) |
814eed3d4f3e
planemo upload for repository https://github.com/quadram-institute-bioscience/galaxy-tools/tree/master/tools/plasmidtron commit d2ae53b6ee23d56d26e9add8fe5ade2e20e75b87-dirty
thanhlv
parents:
diff
changeset
|
28 processed_list.append(file_name) |
814eed3d4f3e
planemo upload for repository https://github.com/quadram-institute-bioscience/galaxy-tools/tree/master/tools/plasmidtron commit d2ae53b6ee23d56d26e9add8fe5ade2e20e75b87-dirty
thanhlv
parents:
diff
changeset
|
29 # else: |
814eed3d4f3e
planemo upload for repository https://github.com/quadram-institute-bioscience/galaxy-tools/tree/master/tools/plasmidtron commit d2ae53b6ee23d56d26e9add8fe5ade2e20e75b87-dirty
thanhlv
parents:
diff
changeset
|
30 # _lines.append(lines[i].strip()) |
814eed3d4f3e
planemo upload for repository https://github.com/quadram-institute-bioscience/galaxy-tools/tree/master/tools/plasmidtron commit d2ae53b6ee23d56d26e9add8fe5ade2e20e75b87-dirty
thanhlv
parents:
diff
changeset
|
31 |
814eed3d4f3e
planemo upload for repository https://github.com/quadram-institute-bioscience/galaxy-tools/tree/master/tools/plasmidtron commit d2ae53b6ee23d56d26e9add8fe5ade2e20e75b87-dirty
thanhlv
parents:
diff
changeset
|
32 with open(lst_file,"w") as fh: |
814eed3d4f3e
planemo upload for repository https://github.com/quadram-institute-bioscience/galaxy-tools/tree/master/tools/plasmidtron commit d2ae53b6ee23d56d26e9add8fe5ade2e20e75b87-dirty
thanhlv
parents:
diff
changeset
|
33 for _line in _lines: |
814eed3d4f3e
planemo upload for repository https://github.com/quadram-institute-bioscience/galaxy-tools/tree/master/tools/plasmidtron commit d2ae53b6ee23d56d26e9add8fe5ade2e20e75b87-dirty
thanhlv
parents:
diff
changeset
|
34 fh.writelines("{}\n".format(_line)) |
814eed3d4f3e
planemo upload for repository https://github.com/quadram-institute-bioscience/galaxy-tools/tree/master/tools/plasmidtron commit d2ae53b6ee23d56d26e9add8fe5ade2e20e75b87-dirty
thanhlv
parents:
diff
changeset
|
35 |
814eed3d4f3e
planemo upload for repository https://github.com/quadram-institute-bioscience/galaxy-tools/tree/master/tools/plasmidtron commit d2ae53b6ee23d56d26e9add8fe5ade2e20e75b87-dirty
thanhlv
parents:
diff
changeset
|
36 if __name__ == "__main__": |
814eed3d4f3e
planemo upload for repository https://github.com/quadram-institute-bioscience/galaxy-tools/tree/master/tools/plasmidtron commit d2ae53b6ee23d56d26e9add8fe5ade2e20e75b87-dirty
thanhlv
parents:
diff
changeset
|
37 tmp_file = sys.argv[1] |
814eed3d4f3e
planemo upload for repository https://github.com/quadram-institute-bioscience/galaxy-tools/tree/master/tools/plasmidtron commit d2ae53b6ee23d56d26e9add8fe5ade2e20e75b87-dirty
thanhlv
parents:
diff
changeset
|
38 lst_file = sys.argv[2] |
814eed3d4f3e
planemo upload for repository https://github.com/quadram-institute-bioscience/galaxy-tools/tree/master/tools/plasmidtron commit d2ae53b6ee23d56d26e9add8fe5ade2e20e75b87-dirty
thanhlv
parents:
diff
changeset
|
39 make_list(tmp_file, lst_file) |