comparison args.py @ 0:0254731f047b draft default tip

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/SynDivA commit 90c5ec603e2c6b8c49d2dc7ec1b1e97f9d8fb92c
author iuc
date Thu, 23 Jun 2022 22:32:13 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:0254731f047b
1 # -*- coding: utf-8 -*-
2 import getopt
3 import os
4 import sys
5
6
7 def usage(info) -> str:
8 text = "SynDivA script.\n\n"
9 if info:
10 text += info
11 temp = "Option\t\t\t\tfile\t\t\tDescription\n"
12 text += temp
13 text += '-' * (len(temp) + 60)
14 text += '\n'
15 text += "-i, --input\t\t\tfile.fasta\t\tFasta file that contains the DNA sequences\n"
16 text += "-o, --output_dir\t\t/path/for/output\tDirectory where output files will be written\n"
17 text += "-p, --pattern\t\t\tstring\t\t\tPattern of the sequence bank\n"
18 text += "-5, --restriction-site-5\tstring\t\t\tSequence of the restriction site in 5'\n"
19 text += "-3, --restriction-site-3\tstring\t\t\tSequence of the restriction site in 3'\n"
20 return text
21
22
23 def get_os_path_join(directory, filename):
24 return os.path.join(directory, filename)
25
26
27 def get_os_path_name(input):
28 return os.path.basename(input)
29
30
31 def check_pattern(pattern):
32 authorized_pattern_letter = ['A', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'K', 'L', 'M',
33 'N', 'P', 'Q', 'R', 'S', 'T', 'V', 'W', 'Y', ':', '0',
34 '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '*']
35 return len([letter in authorized_pattern_letter for letter in pattern]) == len(pattern)
36
37
38 class Args:
39
40 def __init__(self):
41 """
42 Instanciate Files object
43 """
44 self.input = None
45 self.output_dir = None
46 self.pattern = None
47 self.site_res_5 = None
48 self.site_res_3 = None
49 self.getargs()
50
51 def case(self):
52 # Test des fichiers et repertoires
53 if not self.input:
54 sys.exit(usage("input (-i,--input) : \"%s\" must be indicated\n" % (self.input)))
55 if not self.output_dir:
56 sys.exit(usage("output directory (-o,--output_dir) : \"%s\" must be indicated\n" % (self.output_dir)))
57 if not self.pattern:
58 sys.exit(
59 usage("Pattern of the sequence bank (-p,--pattern) : \"%s\" must be indicated\n" % (self.pattern)))
60 if not self.site_res_5:
61 sys.exit(usage(
62 "Sequence of the restriction site in 5' (-5,--restriction-site-5) : \"%s\" must be indicated\n" % (
63 self.site_res_5)))
64 if not self.site_res_3:
65 sys.exit(usage(
66 "Sequence of the restriction site in 3' (-3,--restriction-site-3) : \"%s\" must be indicated\n" % (
67 self.site_res_3)))
68
69 def data_format(self):
70 """
71 Check if information are correct
72 """
73 # Run without arguments
74 if len(sys.argv) == 1:
75 sys.exit(usage(None))
76 # Test input file argument
77 if self.input and not os.path.isfile(self.input):
78 print(self.input)
79 print(os.path.isfile(self.input))
80
81 def getargs(self):
82 """
83 Determine the files provided as arguments
84 @return: Choosen options
85 """
86 # Sans argument
87 if len(sys.argv) <= 1:
88 sys.exit("Do './fibronectin.py -h' for a usage summary")
89 # options test
90 try:
91 (opts, args) = getopt.getopt(sys.argv[1:], "i:o:p:5:3:h",
92 ["input=", "output_dir=", "pattern=", "site_res_5=", "site_res_3="])
93 except getopt.GetoptError as err:
94 # print help information and exit:
95 print(str(err)) # will print something like "option -a not recognized"
96 sys.exit(usage(None))
97 # Identification of options
98 for (o, a) in opts:
99 if o in ("-i", "--input"):
100 self.input = a
101 elif o in ("-o", "--output_dir"):
102 self.output_dir = a
103 elif o in ("-p", "--pattern"):
104 self.pattern = a
105 elif o in ("-5", "--restriction-site-5"):
106 self.site_res_5 = a
107 elif o in ("-3", "--restriction-site-3"):
108 self.site_res_3 = a
109 elif o in ("-h", "--help"):
110 sys.exit(usage(None))
111 else:
112 assert False, "unhandled option"
113 # Verification of cases
114 self.case()
115 self.data_format()