comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:814eed3d4f3e
1 #!/usr/bin/env python
2
3 import sys
4 import os
5 # from pathlib import Path
6
7
8 def make_list(tmp_file, lst_file):
9 dividers = ["_1", "_F", "_R1", "_2", "_R", "_R2"]
10 with open(tmp_file, "r") as fh:
11 lines = fh.readlines()
12 _lines = []
13 processed_list = []
14 for i in range(0,len(lines)):
15 if (os.path.splitext(lines[i].strip())[-1] == ".fasta") or (os.path.splitext(lines[i].strip())[-1] == ".fa"):
16 _lines.append(lines[i].strip())
17 else:
18 file_name = os.path.basename(lines[i])
19 if file_name not in processed_list:
20 detected_devider = [div for div in dividers if div in file_name]
21 if len(detected_devider) > 0:
22 detected_devider = detected_devider[0]
23 new_file_name = file_name.split(detected_devider)[0]
24 for j in range(i+1, len(lines)):
25 if new_file_name in lines[j]:
26 paired = "{},{}".format(lines[i].strip(), lines[j].strip())
27 _lines.append(paired)
28 processed_list.append(file_name)
29 # else:
30 # _lines.append(lines[i].strip())
31
32 with open(lst_file,"w") as fh:
33 for _line in _lines:
34 fh.writelines("{}\n".format(_line))
35
36 if __name__ == "__main__":
37 tmp_file = sys.argv[1]
38 lst_file = sys.argv[2]
39 make_list(tmp_file, lst_file)