| 0 | 1 import requests | 
|  | 2 import argparse | 
|  | 3 import os | 
|  | 4 import sys | 
|  | 5 | 
|  | 6 __base_url__ = "http://supfam3.cs.bris.ac.uk/FATHMM/" | 
|  | 7 __submit_url__ = __base_url__ + "cgi-bin/submit.cgi" | 
|  | 8 __result_url__ = __base_url__ + "cgi-bin/" | 
|  | 9 __download_url__ = __base_url__ + "tmp/" | 
|  | 10 __type__="CANCER" ##Hidden field to show which type of variants we are processing | 
|  | 11 | 
|  | 12 | 
|  | 13 def stop_err(msg, err=1): | 
|  | 14     sys.stderr.write('%s\n' % msg) | 
|  | 15     sys.exit(err) | 
|  | 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     threshold = -0.75 | 
|  | 22     if (args.threshold): | 
|  | 23         threshold = float(args.threshold) | 
|  | 24     data = {"weighted": __type__, | 
|  | 25             "batch": contents, | 
|  | 26             "threshold": threshold | 
|  | 27             } | 
|  | 28     response = requests.post(__submit_url__, data=data) | 
|  | 29     if response.status_code!=200: | 
|  | 30         stop_err("Error processing request, got" + response.status_code) | 
|  | 31     text = response.text | 
|  | 32     split_text = text.split("window.location = ") | 
|  | 33     try: | 
|  | 34         url = split_text[1] | 
|  | 35         url = url.split(";")[0] | 
|  | 36         url = url.split("session=")[1] | 
|  | 37         url = url.replace("'", "").replace("./","") | 
|  | 38         url = __download_url__ + url + ".tab" | 
|  | 39     except IndexError: | 
|  | 40         stop_err("Unable to parse result id") | 
|  | 41     response = requests.get(url) | 
|  | 42     with open(args.output, 'wb') as fp: | 
|  | 43         fp.write(response.text) | 
|  | 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 location') | 
|  | 55     parser.add_argument('--threshold', | 
|  | 56                          type=float, | 
|  | 57                          required=False, | 
|  | 58                          help='Predictions with score less than threshold are possibly cancer causing') | 
|  | 59     args = parser.parse_args() | 
|  | 60     main_web(args) |