Skip to content

Commit

Permalink
Sgav2 api#7 (#47)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
dizak committed May 23, 2018
1 parent 5041579 commit 7ad31e7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
35 changes: 20 additions & 15 deletions prowler/apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 <None>
"""
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)
11 changes: 7 additions & 4 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 7ad31e7

Please sign in to comment.