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