defined method for formatting mcsm_results

This commit is contained in:
Tanushree Tunstall 2020-04-14 11:30:36 +01:00
parent 8b7ccccc49
commit 23c2ddf45f
2 changed files with 245 additions and 206 deletions

View file

@ -58,13 +58,10 @@ print('Output filename:', out_filename
, '\nOutput path:', outdir
, '\n=============================================================')
#%% global variables
#HOST = "http://biosig.unimelb.edu.au"
#PREDICTION_URL = f"{HOST}/mcsm_lig/prediction"
#=======================================================================
def fetch_results(urltextfile):
"""
Extract results data from the results page
Extract results data using the prediction url
@params result_page of request_results()
@type response object
@ -90,36 +87,37 @@ def fetch_results(urltextfile):
def build_result_dict(web_result_raw):
"""
Format web results which is inconveniently preformatted!
Build dict of mcsm output for a single mutation
Format web results which is preformatted to enable building result dict
# preformatted string object: Problematic!
# roughly bring these to the same format as the other
# make format consistent
@params web_result_raw directly from html parser extraction
@params web_result_raw: directly from html parser extraction
@type string
@returns result dict
@type {}
"""
# remove blank lines from output
# remove blank lines from output
mytext = os.linesep.join([s for s in web_result_raw.splitlines() if s])
# Predicted affintiy change and DUET stability change cols
# are are split over multiple lines and Mutation information is empty!
# affinity change and DUET stability change cols are are split over
# multiple lines and Mutation information is empty!
mytext = mytext.replace('ange:\n', 'ange: ')
#print(mytext)
# print(mytext)
# initiliase result_dict
# initiliase result_dict
result_dict = {}
for line in mytext.split('\n'):
fields = line.split(':')
#print(fields)
# print(fields)
if len(fields) > 1: # since Mutaton information is empty
dict_entry = dict([(x, y) for x, y in zip(fields[::2], fields[1::2])])
result_dict.update(dict_entry)
return result_dict
return result_dict
#=======================================================================
#%% call function
#request_results(infile_url)