0
|
1 # -*- coding: utf-8 -*-
|
|
2 import sys, getopt, os
|
|
3
|
|
4
|
|
5 class Args:
|
|
6
|
|
7 def __init__(self):
|
|
8 """
|
|
9 Instanciate Files object
|
|
10 """
|
|
11 self.input = None
|
|
12 self.output_dir = None
|
|
13 self.pattern = None
|
|
14 self.site_res_5 = None
|
|
15 self.site_res_3 = None
|
|
16 self.getargs()
|
|
17
|
|
18 def usage(self, info):
|
|
19 text = None
|
|
20 text = "Fibronectin script.\n\n"
|
|
21 if (info): text += info
|
|
22 temp = "Option\t\t\t\tfile\t\t\tDescription\n"
|
|
23 text += temp
|
|
24 text += '-' * (len(temp) + 60)
|
|
25 text += '\n'
|
|
26 text += "-i, --input\t\t\tfile.fasta\t\tFasta file that contains the DNA sequences\n"
|
|
27 text += "-o, --output_dir\t\t/path/for/output\tDirectory where output files will be written\n"
|
|
28 text += "-p, --pattern\t\t\tstring\t\t\tPattern of the sequence bank\n"
|
|
29 text += "-5, --restriction-site-5\tstring\t\t\tSequence of the restriction site in 5'\n"
|
|
30 text += "-3, --restriction-site-3\tstring\t\t\tSequence of the restriction site in 3'\n"
|
|
31 return text
|
|
32
|
|
33 def case(self):
|
|
34 # Test des fichiers et repertoires
|
|
35 if not self.input:
|
|
36 sys.exit(self.usage("input (-i,--input) : \"%s\" must be indicated\n" % (self.input)))
|
|
37 if not self.output_dir:
|
|
38 sys.exit(self.usage("output directory (-o,--output_dir) : \"%s\" must be indicated\n" % (self.output_dir)))
|
|
39 if not self.pattern:
|
|
40 sys.exit(
|
|
41 self.usage("Pattern of the sequence bank (-p,--pattern) : \"%s\" must be indicated\n" % (self.pattern)))
|
|
42 if not self.site_res_5:
|
|
43 sys.exit(self.usage(
|
|
44 "Sequence of the restriction site in 5' (-5,--restriction-site-5) : \"%s\" must be indicated\n" % (
|
|
45 self.site_res_5)))
|
|
46 if not self.site_res_3:
|
|
47 sys.exit(self.usage(
|
|
48 "Sequence of the restriction site in 3' (-3,--restriction-site-3) : \"%s\" must be indicated\n" % (
|
|
49 self.site_res_3)))
|
|
50
|
|
51 def data_format(self):
|
|
52 """
|
|
53 Check if information are correct
|
|
54 """
|
|
55 # Run without arguments
|
|
56 if len(sys.argv) == 1:
|
|
57 sys.exit(self.usage(None))
|
|
58 # Test input file argument
|
|
59 if self.input:
|
|
60 if not os.path.isfile(self.input):
|
|
61 print(self.input)
|
|
62 print(os.path.isfile(self.input))
|
|
63 #sys.exit(self.usage("Error with \"%s\" : -i required an input file\n" % self.multilist))
|
|
64
|
|
65 # Determine les fichiers fournis en arguments
|
|
66
|
|
67 def getargs(self):
|
|
68 """
|
|
69 Determine the files provided as arguments
|
|
70 @return: Choosen options
|
|
71 """
|
|
72 # Sans argument
|
|
73 if len(sys.argv) <= 1: sys.exit("Do './fibronectin.py -h' for a usage summary")
|
|
74 # test des option
|
|
75 try:
|
|
76 (opts, args) = getopt.getopt(sys.argv[1:], "i:o:p:5:3:h",
|
|
77 ["input=", "output_dir=", "pattern=", "site_res_5=", "site_res_3="])
|
|
78 except getopt.GetoptError as err:
|
|
79 # print help information and exit:
|
|
80 print(str(err)) # will print something like "option -a not recognized"
|
|
81 sys.exit(self.usage(None))
|
|
82 # Identification of options
|
|
83 for (o, a) in opts:
|
|
84 if o in ("-i", "--input"):
|
|
85 self.input = a
|
|
86 elif o in ("-o", "--output_dir"):
|
|
87 self.output_dir = a
|
|
88 elif o in ("-p", "--pattern"):
|
|
89 self.pattern = a
|
|
90 elif o in ("-5", "--restriction-site-5"):
|
|
91 self.site_res_5 = a
|
|
92 elif o in ("-3", "--restriction-site-3"):
|
|
93 self.site_res_3 = a
|
|
94 elif o in ("-h", "--help"):
|
|
95 sys.exit(self.usage(None))
|
|
96 else:
|
|
97 assert False, "unhandled option"
|
|
98 # Verification of cases
|
|
99 self.case()
|
|
100 self.data_format()
|