3
|
1 #!/usr/bin/env python
|
|
2 import sys
|
|
3 import requests
|
|
4 import os
|
|
5 import argparse
|
|
6 import re
|
|
7
|
|
8 __url__ = 'http://mutationassessor.org/'
|
|
9
|
|
10
|
|
11 def stop_err(msg, err=1):
|
|
12 sys.stderr.write('%s\n' % msg)
|
|
13 sys.exit(err)
|
|
14
|
|
15
|
|
16 def main_web(args):
|
|
17 assert os.path.exists(args.input)
|
|
18 with open(args.input) as f:
|
|
19 contents = f.read().strip()
|
|
20 if args.hg19 is True and args.protein is True:
|
|
21 stop_err('--hg19 option conflicts with --protein')
|
|
22 if args.protein is False:
|
|
23 ## Replace tabs/space with commas
|
|
24 re.sub('[\t\s]+', ',', contents)
|
|
25 if args.hg19:
|
|
26 ## Append hg19 to each line
|
|
27 lines = contents.split('\n')
|
|
28 contents = ('\n').join(
|
|
29 map((lambda x: 'hg19,' + x),
|
|
30 lines))
|
|
31
|
|
32 payload = {'vars': contents, 'tableQ': 1}
|
|
33 request = requests.post(__url__, data=payload)
|
|
34 response = request.text
|
|
35 if request.status_code != requests.codes.ok:
|
|
36 stop_err("""Error retrieving response from server.
|
|
37 Server returned %s .
|
|
38 Output: %s
|
|
39 """ % (request.status_code, response))
|
|
40 with open(args.output, 'wb') as fp:
|
|
41 fp.write(response)
|
|
42
|
|
43 if __name__ == '__main__':
|
|
44 parser = argparse.ArgumentParser(description="Process input output paths")
|
|
45 parser.add_argument('--input',
|
|
46 type=str,
|
|
47 required=True,
|
|
48 help='Input file location')
|
|
49 parser.add_argument('--output',
|
|
50 type=str,
|
|
51 required=True,
|
|
52 help='Output file locatio')
|
|
53 parser.add_argument('--log',
|
|
54 type=str,
|
|
55 required=False)
|
|
56 parser.add_argument('--hg19',
|
|
57 action='store_true',
|
|
58 help="""Use hg19 build.
|
|
59 Appends 'hg19' to each input line""")
|
|
60 parser.add_argument('--protein',
|
|
61 action='store_true',
|
|
62 help='Inputs are in protein space')
|
|
63 args = parser.parse_args()
|
|
64 main_web(args)
|