52 lines
2 KiB
Python
Executable file
52 lines
2 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""
|
|
Created on Wed Aug 19 14:33:51 2020
|
|
|
|
@author: tanu
|
|
"""
|
|
#%% load packages
|
|
import os,sys
|
|
import subprocess
|
|
import argparse
|
|
import requests
|
|
import re
|
|
import time
|
|
from bs4 import BeautifulSoup
|
|
import pandas as pd
|
|
from pandas.api.types import is_string_dtype
|
|
from pandas.api.types import is_numeric_dtype
|
|
#%%#####################################################################
|
|
|
|
def get_results(url_file, host_url, output_dir, outfile_suffix):
|
|
# initilialise empty df
|
|
#mcsm_na_results_out_df = pd.DataFrame()
|
|
with open(url_file, 'r') as f:
|
|
for count, line in enumerate(f):
|
|
line = line.strip()
|
|
print('URL no.', count+1, '\n', line)
|
|
|
|
#============================
|
|
# Writing results file: csv
|
|
#============================
|
|
mcsm_na_results_dir = output_dir + '/mcsm_na_results'
|
|
if not os.path.exists(mcsm_na_results_dir):
|
|
print('\nCreating dir: mcsm_na_results within:', output_dir )
|
|
os.makedirs(mcsm_na_results_dir)
|
|
|
|
# Download the .txt
|
|
prediction_number = re.search(r'([0-9]+\.[0-9]+$)', line).group(0)
|
|
print('CHECK prediction no:', prediction_number)
|
|
txt_url = f"{host_url}/mcsm_na/static/results/" + prediction_number + '.txt'
|
|
print('CHECK txt url:', txt_url)
|
|
|
|
out_filename = mcsm_na_results_dir + '/' + outfile_suffix + '_output_' + prediction_number + '.txt.gz'
|
|
response_txt = requests.get(txt_url, stream = True)
|
|
if response_txt.status_code == 200:
|
|
print('\nDownloading .txt:', txt_url
|
|
, '\n\nSaving file as:', out_filename)
|
|
with open(out_filename, 'wb') as f:
|
|
f.write(response_txt.raw.read())
|
|
|
|
#%%#####################################################################
|
|
|