-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprotein2category.py
executable file
·123 lines (107 loc) · 4.37 KB
/
protein2category.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/python
# import global modules
import os
import sys
import argparse
import logging
import re
# import workflow builder
import wf
# Module metadata variables
__author__ = "Jose Rodriguez"
__credits__ = ["Marco Trevisan", "Jesus Vazquez"]
__license__ = "Creative Commons Attribution-NonCommercial-NoDerivs 4.0 Unported License https://creativecommons.org/licenses/by-nc-nd/4.0/"
__version__ = "1.0.1"
__maintainer__ = "Jose Rodriguez"
__email__ = "[email protected]"
__status__ = "Development"
def _print_exception(code, msg):
'''
Print the code message
'''
logging.exception(msg)
sys.exit(code)
def main(args):
'''
Main function
'''
# check parameters
# extract params for the methods
params = {}
methods = ["sanxot1", "sanxotsieve1", "sanxot2"]
for method in methods:
if not method in args.params:
_print_exception( 2, "checking the parameters for the {} method".format(method) )
match = re.search(r'{\s*' + method + r'\s*:\s*([^\}]*)}', args.params, re.IGNORECASE)
if match.group():
params[method] = match.group(1)
else:
_print_exception( 2, "checking the parameters for the {} method".format(method) )
# get directory from input files
outdir = os.path.dirname(os.path.realpath(args.catfile))
# create builder ---
logging.info("create workflow builder")
w = wf.builder(outdir, logging)
logging.info("execute sanxot")
w.sanxot({
"-a": "q2c_outs",
"-d": args.profile,
"-r": args.relfile
}, params["sanxot1"])
logging.info("execute sanxotsieve")
w.sanxotsieve({
"-d": args.profile,
"-r": args.relfile,
"-f": args.fdr,
"-V": "q2c_outs_infoFile.txt"
}, params["sanxotsieve1"])
logging.info("execute sanxot")
tagfile = os.path.splitext( os.path.basename(args.profile) )[0] + "_tagged.xls"
w.sanxot({
"-a": "q2c_nouts",
"-d": args.profile,
"-r": tagfile,
"-o": args.catfile,
"-V": "q2c_outs_infoFile.txt",
}, params["sanxot2"])
if __name__ == "__main__":
# parse arguments
parser = argparse.ArgumentParser(
description='Create the relationship table for protein2category method',
epilog='''
Example:
protein2category.py -i
-r
-s
Parameter example:
"{aljamia1: -i [Raw_FirstScan]-[Charge] -j [Xs_127_N_126] -k [Vs_127_N_126] -f !([FASTAProteinDescription]~~TRYP_PIG||[FASTAProteinDescription]~~Krt||[FASTAProteinDescription]~~KRT) }
{aljamia2: -i [Sequence] -j [Raw_FirstScan]-[Charge] }
{klibrate1: -g -f }"
''')
parser.add_argument('-q', '--profile', required=True, help='Input file with the peptides')
parser.add_argument('-r', '--relfile', required=True, help='Input file with the relationship table')
parser.add_argument('-f', '--fdr', required=True, help='FDR value')
parser.add_argument('-c', '--catfile', required=True, help='Output file with the categories')
parser.add_argument('-a', '--params', required=True, help='Input parameters for the sub-methods')
parser.add_argument('-l', '--logfile', help='Output file with the log tracks')
parser.add_argument('-v', dest='verbose', action='store_true', help="Increase output verbosity")
args = parser.parse_args()
# set-up logging
scriptname = os.path.splitext( os.path.basename(__file__) )[0]
# add filehandler
logfile = os.path.basename(args.catfile) + "/"+ scriptname +".log"
if args.logfile:
logfile = args.logfile
# logging debug level. By default, info level
if args.verbose:
logging.basicConfig(filename=logfile, level=logging.DEBUG,
format='%(asctime)s - %(levelname)s - '+scriptname+' - %(message)s',
datefmt='%m/%d/%Y %I:%M:%S %p')
else:
logging.basicConfig(filename=logfile, level=logging.INFO,
format='%(asctime)s - %(levelname)s - '+scriptname+' - %(message)s',
datefmt='%m/%d/%Y %I:%M:%S %p')
# start main function
logging.info('start script: '+"{0}".format(" ".join([x for x in sys.argv])))
main(args)
logging.info('end script')