From 7ad31e70db84c1293ccdf8659a1749a78db4ac11 Mon Sep 17 00:00:00 2001 From: Dariusz Izak Date: Wed, 23 May 2018 12:01:25 +0200 Subject: [PATCH] Sgav2 api#7 (#47) * UPD:Renaming so that there is place for v2 * FIX@get_data:urls of the v2 contain subdir which must be removed from the locally downloaded file * FIX:build fails on travis due to unexpected indent --- prowler/apis.py | 35 ++++++++++++++++++++--------------- tests/tests.py | 11 +++++++---- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/prowler/apis.py b/prowler/apis.py index 8b4a5dc..4589c47 100644 --- a/prowler/apis.py +++ b/prowler/apis.py @@ -202,20 +202,25 @@ class CostanzoAPI: """ def __init__(self): - self.home = "http://drygin.ccbr.utoronto.ca/~costanzo2009" - self.data = {"raw": "sgadata_costanzo2009_rawdata_101120.txt.gz", - "raw_matrix": "sgadata_costanzo2009_rawdata_matrix_101120.txt.gz", - "lenient_cutoff": "sgadata_costanzo2009_lenientCutoff_101120.txt.gz", - "intermediate_cutoff": "sgadata_costanzo2009_intermediateCutoff_101120.txt.gz", - "stringent_cutoff": "sgadata_costanzo2009_stringentCutoff_101120.txt.gz", - "bioprocesses": "bioprocess_annotations_costanzo2009.xls", - "chemical_genomics": "chemgenomic_data_costanzo2009.xls", - "query_list": "sgadata_costanzo2009_query_list_101120.txt", - "array_list": "sgadata_costanzo2009_array_list.txt"} + self.home = {"v1": "http://drygin.ccbr.utoronto.ca/~costanzo2009", + "v2": "http://thecellmap.org/costanzo2016/"} + self.data = {"v1": {"raw": "sgadata_costanzo2009_rawdata_101120.txt.gz", + "raw_matrix": "sgadata_costanzo2009_rawdata_matrix_101120.txt.gz", + "lenient_cutoff": "sgadata_costanzo2009_lenientCutoff_101120.txt.gz", + "intermediate_cutoff": "sgadata_costanzo2009_intermediateCutoff_101120.txt.gz", + "stringent_cutoff": "sgadata_costanzo2009_stringentCutoff_101120.txt.gz", + "bioprocesses": "bioprocess_annotations_costanzo2009.xls", + "chemical_genomics": "chemgenomic_data_costanzo2009.xls", + "query_list": "sgadata_costanzo2009_query_list_101120.txt", + "array_list": "sgadata_costanzo2009_array_list.txt"}, + "v2": {"pairwise": "data_files/Raw%20genetic%20interaction%20datasets:%20Pair-wise%20interaction%20format.zip", + "matrix": "data_files/Raw%20genetic%20interaction%20datasets:%20Matrix%20format.zip", + "interaction_profile_similarity_matrices": "data_files/Genetic%20interaction%20profile%20similarity%20matrices.zip"}} def get_data(self, data, - output_directory="."): + output_directory=".", + sga_version="v2"): """Get files from Costanzo's SOM website. Args: @@ -232,11 +237,11 @@ def get_data(self, out_file_name (str): name for file to be downloaded. Automatically same as appropriate Costanzo_API attrib when set to """ - if data not in list(self.data.keys()): + if data not in list(self.data[sga_version].keys()): raise ValueError("unknown option for data arg") - url = "{0}/{1}".format(self.home, - self.data[data]) - out_file_name = self.data[data] + url = "{0}/{1}".format(self.home[sga_version], + self.data[sga_version][data]) + out_file_name = self.data[sga_version][data].replace("data_files/", "").replace("%20", "_").replace(":", "-") res = rq.get(url) with open("{}/{}".format(output_directory, out_file_name), "wb") as fout: fout.write(res.content) diff --git a/tests/tests.py b/tests/tests.py index 7b6d8d1..7b9c21f 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -134,20 +134,23 @@ def setUp(self): Sets up class level attributes for the tests. """ self.costanzo_api = apis.CostanzoAPI() + self.sga_versions = ["v1", "v2"] def tearDown(self): """ Distroys files downloaded or created during the tests. """ - for i in list(self.costanzo_api.data.values()): - os.remove("test_data/{}".format(i)) + for sga_version in self.sga_versions: + for i in list(self.costanzo_api.data[sga_version].values()): + os.remove("test_data/{}".format(i).replace("data_files/", "").replace("%20", "_").replace(":", "-")) def test_get_data(self): """ Tests if apis.CostanzoAPI,get_data downloads data files successfully. """ - for i in list(self.costanzo_api.data.keys()): - self.costanzo_api.get_data(i, "test_data") + for sga_version in self.sga_versions: + for i in list(self.costanzo_api.data[sga_version].keys()): + self.costanzo_api.get_data(i, "test_data", sga_version) class DatabasesTests(unittest.TestCase):