diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c18dd8d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__pycache__/ diff --git a/.travis.yml b/.travis.yml index 4850e84..d2f5b56 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,9 @@ language: python # python versioning python: - 2.7 + - 3.4 + - 3.5 + - 3.6 # requirements install: diff --git a/cmapPy/__init__.py b/cmapPy/__init__.py index 16b4a08..f4a9a60 100644 --- a/cmapPy/__init__.py +++ b/cmapPy/__init__.py @@ -1,3 +1,3 @@ -from clue_api_client import * -from pandasGEXpress import * -from set_io import * \ No newline at end of file +from .clue_api_client import * +from .pandasGEXpress import * +from .set_io import * diff --git a/cmapPy/clue_api_client/cell_queries.py b/cmapPy/clue_api_client/cell_queries.py index 47b7c12..e119202 100644 --- a/cmapPy/clue_api_client/cell_queries.py +++ b/cmapPy/clue_api_client/cell_queries.py @@ -1,5 +1,5 @@ import logging -import setup_logger +from . import setup_logger __authors__ = "David L. Lahr" __email__ = "dlahr@broadinstitute.org" diff --git a/cmapPy/clue_api_client/clue_api_client.py b/cmapPy/clue_api_client/clue_api_client.py index ce8a03b..3250683 100644 --- a/cmapPy/clue_api_client/clue_api_client.py +++ b/cmapPy/clue_api_client/clue_api_client.py @@ -1,6 +1,6 @@ import requests import logging -import setup_logger +from . import setup_logger import json import copy diff --git a/cmapPy/clue_api_client/gene_queries.py b/cmapPy/clue_api_client/gene_queries.py index 06f2148..d4b4e7b 100644 --- a/cmapPy/clue_api_client/gene_queries.py +++ b/cmapPy/clue_api_client/gene_queries.py @@ -1,5 +1,5 @@ import logging -import setup_logger +from . import setup_logger __authors__ = "David L. Lahr" __email__ = "dlahr@broadinstitute.org" diff --git a/cmapPy/clue_api_client/macchiato_queries.py b/cmapPy/clue_api_client/macchiato_queries.py index 7312fd5..f246dce 100644 --- a/cmapPy/clue_api_client/macchiato_queries.py +++ b/cmapPy/clue_api_client/macchiato_queries.py @@ -1,5 +1,5 @@ import logging -import setup_logger +from . import setup_logger __authors__ = "David L. Lahr" __email__ = "dlahr@broadinstitute.org" diff --git a/cmapPy/clue_api_client/mock_clue_api_client.py b/cmapPy/clue_api_client/mock_clue_api_client.py index 88f2097..90d22fd 100644 --- a/cmapPy/clue_api_client/mock_clue_api_client.py +++ b/cmapPy/clue_api_client/mock_clue_api_client.py @@ -1,6 +1,6 @@ import logging -import setup_logger -import clue_api_client +from . import setup_logger +from . import clue_api_client __authors__ = "David L. Lahr" __email__ = "dlahr@broadinstitute.org" diff --git a/cmapPy/clue_api_client/pert_queries.py b/cmapPy/clue_api_client/pert_queries.py index 58f8669..093b3ed 100644 --- a/cmapPy/clue_api_client/pert_queries.py +++ b/cmapPy/clue_api_client/pert_queries.py @@ -1,5 +1,5 @@ import logging -import setup_logger +from . import setup_logger __authors__ = "David L. Lahr" __email__ = "dlahr@broadinstitute.org" diff --git a/cmapPy/clue_api_client/tests/test_clue_api_client.py b/cmapPy/clue_api_client/tests/test_clue_api_client.py index 46f73ee..5a9f50e 100644 --- a/cmapPy/clue_api_client/tests/test_clue_api_client.py +++ b/cmapPy/clue_api_client/tests/test_clue_api_client.py @@ -3,9 +3,10 @@ import logging from cmapPy.clue_api_client import clue_api_client as clue_api_client import os.path -import ConfigParser import collections +from six.moves import configparser + __authors__ = "David L. Lahr" __email__ = "dlahr@broadinstitute.org" @@ -120,7 +121,7 @@ def test_run_put(self): def build_clue_api_client_from_default_test_config(): - cfg = ConfigParser.RawConfigParser() + cfg = configparser.RawConfigParser() cfg.read(config_filepath) cao = clue_api_client.ClueApiClient(base_url=cfg.get(config_section, "clue_api_url"), user_key=cfg.get(config_section, "clue_api_user_key")) diff --git a/cmapPy/clue_api_client/tests/test_pert_queries.py b/cmapPy/clue_api_client/tests/test_pert_queries.py index 6346b3e..7fa1882 100644 --- a/cmapPy/clue_api_client/tests/test_pert_queries.py +++ b/cmapPy/clue_api_client/tests/test_pert_queries.py @@ -18,9 +18,9 @@ def test__build_map_from_clue_api_result(self): r = pq._build_map_from_clue_api_result([{"a": "b", "c": "d"}], "a", "c") self.assertIsNotNone(r) logger.debug("r: {}".format(r)) - self.assertEquals(1, len(r)) + self.assertEqual(1, len(r)) self.assertIn("b", r) - self.assertEquals("d", r["b"]) + self.assertEqual("d", r["b"]) def test_retrieve_pert_id_pert_iname_map(self): r = pq.retrieve_pert_id_pert_iname_map(["BRD-K21680192", "BRD-K88378636", "not a valid BRD"], cao) diff --git a/cmapPy/pandasGEXpress/GCToo.py b/cmapPy/pandasGEXpress/GCToo.py index 861727a..6c035c4 100755 --- a/cmapPy/pandasGEXpress/GCToo.py +++ b/cmapPy/pandasGEXpress/GCToo.py @@ -42,7 +42,7 @@ import numpy as np import pandas as pd import logging -import setup_GCToo_logger as setup_logger +from . import setup_GCToo_logger as setup_logger __authors__ = 'Oana Enache, Lev Litichevskiy, Dave Lahr' diff --git a/cmapPy/pandasGEXpress/concat_gctoo.py b/cmapPy/pandasGEXpress/concat_gctoo.py index 7fe49f7..bee1ab1 100755 --- a/cmapPy/pandasGEXpress/concat_gctoo.py +++ b/cmapPy/pandasGEXpress/concat_gctoo.py @@ -36,14 +36,16 @@ import sys import glob import logging -import setup_GCToo_logger as setup_logger -import pandas as pd + import numpy +import pandas as pd +from six.moves import range -import GCToo -import parse -import write_gct -import write_gctx +from . import GCToo +from . import parse +from . import setup_GCToo_logger as setup_logger +from . import write_gct +from . import write_gctx __author__ = "Lev Litichevskiy" __email__ = "lev@broadinstitute.org" @@ -371,7 +373,7 @@ def build_mismatched_common_meta_report(common_meta_df_shapes, sources, all_meta expanded_sources = [] for (i, shape) in enumerate(common_meta_df_shapes): src = sources[i] - expanded_sources.extend([src for i in xrange(shape[0])]) + expanded_sources.extend([src for i in range(shape[0])]) expanded_sources = numpy.array(expanded_sources) logger.debug("len(expanded_sources): {}".format(len(expanded_sources))) @@ -386,8 +388,8 @@ def build_mismatched_common_meta_report(common_meta_df_shapes, sources, all_meta for unique_dup_id in unique_duplicate_ids: rows = duplicate_ids_meta_df.loc[unique_dup_id] - matching_row_locs = numpy.array([False for i in xrange(all_meta_df_with_dups.shape[0])]) - for i in xrange(rows.shape[0]): + matching_row_locs = numpy.array([False for i in range(all_meta_df_with_dups.shape[0])]) + for i in range(rows.shape[0]): r = rows.iloc[i] row_comparison = r == all_meta_df_with_dups matching_row_locs = matching_row_locs | row_comparison.all(axis=1).values @@ -399,7 +401,7 @@ def build_mismatched_common_meta_report(common_meta_df_shapes, sources, all_meta all_report_df = pd.concat(report_df_list, axis=0) all_report_df["orig_rid"] = all_report_df.index - all_report_df.index = pd.Index(xrange(all_report_df.shape[0]), name="index") + all_report_df.index = pd.Index(range(all_report_df.shape[0]), name="index") logger.debug("all_report_df.shape: {}".format(all_report_df.shape)) logger.debug("all_report_df.index: {}".format(all_report_df.index)) logger.debug("all_report_df.columns: {}".format(all_report_df.columns)) diff --git a/cmapPy/pandasGEXpress/gct2gctx.py b/cmapPy/pandasGEXpress/gct2gctx.py index 0afc003..5148ea7 100644 --- a/cmapPy/pandasGEXpress/gct2gctx.py +++ b/cmapPy/pandasGEXpress/gct2gctx.py @@ -9,11 +9,11 @@ """ import logging -import setup_GCToo_logger as setup_logger +from . import setup_GCToo_logger as setup_logger import argparse import sys -import parse_gct -import write_gctx +from . import parse_gct +from . import write_gctx __author__ = "Oana Enache" __email__ = "oana@broadinstitute.org" diff --git a/cmapPy/pandasGEXpress/gctx2gct.py b/cmapPy/pandasGEXpress/gctx2gct.py index e0fa655..9de9bca 100644 --- a/cmapPy/pandasGEXpress/gctx2gct.py +++ b/cmapPy/pandasGEXpress/gctx2gct.py @@ -9,11 +9,11 @@ """ import logging -import setup_GCToo_logger as setup_logger +from . import setup_GCToo_logger as setup_logger import argparse import sys -import parse_gctx -import write_gct +from . import parse_gctx +from . import write_gct import os.path __author__ = "Oana Enache" diff --git a/cmapPy/pandasGEXpress/mini_gctoo_for_testing.py b/cmapPy/pandasGEXpress/mini_gctoo_for_testing.py index 80a7821..89c2993 100644 --- a/cmapPy/pandasGEXpress/mini_gctoo_for_testing.py +++ b/cmapPy/pandasGEXpress/mini_gctoo_for_testing.py @@ -7,10 +7,10 @@ """ import logging -import setup_GCToo_logger as setup_logger +from . import setup_GCToo_logger as setup_logger import pandas import numpy -import GCToo +from . import GCToo __author__ = 'Oana Enache' __email__ = 'oana@broadinstitute.org' diff --git a/cmapPy/pandasGEXpress/parse.py b/cmapPy/pandasGEXpress/parse.py index 3020504..abf472b 100644 --- a/cmapPy/pandasGEXpress/parse.py +++ b/cmapPy/pandasGEXpress/parse.py @@ -8,9 +8,9 @@ """ import logging -import setup_GCToo_logger as setup_logger -import parse_gct -import parse_gctx +from . import setup_GCToo_logger as setup_logger +from . import parse_gct +from . import parse_gctx __author__ = "Oana Enache" __email__ = "oana@broadinstitute.org" diff --git a/cmapPy/pandasGEXpress/parse_gct.py b/cmapPy/pandasGEXpress/parse_gct.py index 52390ed..ad0a78b 100644 --- a/cmapPy/pandasGEXpress/parse_gct.py +++ b/cmapPy/pandasGEXpress/parse_gct.py @@ -60,11 +60,11 @@ """ import logging -import setup_GCToo_logger as setup_logger +from . import setup_GCToo_logger as setup_logger import pandas as pd -import numpy as np +import numpy as np import os.path -import GCToo +from . import GCToo __author__ = "Lev Litichevskiy, Oana Enache" __email__ = "lev@broadinstitute.org" @@ -115,7 +115,7 @@ def parse(file_path, convert_neg_666=True, row_meta_only=False, col_meta_only=Fa if not os.path.exists(file_path): err_msg = "The given path to the gct file cannot be found. gct_path: {}" logger.error(err_msg.format(file_path)) - raise(Exception(err_msg.format(file_path))) + raise Exception(err_msg.format(file_path)) logger.info("Reading GCT: {}".format(file_path)) # Read version and dimensions @@ -150,7 +150,7 @@ def read_version_and_dims(file_path): err_msg = ("Only GCT1.2 and 1.3 are supported. The first row of the GCT " + "file must simply be (without quotes) '#1.3' or '#1.2'") logger.error(err_msg.format(version)) - raise(Exception(err_msg.format(version))) + raise Exception(err_msg.format(version)) # Convert version to a string version_as_string = "GCT" + str(version) @@ -165,11 +165,11 @@ def read_version_and_dims(file_path): if version == "1.2" and len(dims) != 2: error_msg = "GCT1.2 should have 2 dimension-related entries in row 2. dims: {}" logger.error(error_msg.format(dims)) - raise(Exception(error_msg.format(dims))) - elif version == "1.3" and len(dims) != 4: + raise Exception(error_msg.format(dims)) + elif version == "1.3" and len(dims) != 4: error_msg = "GCT1.3 should have 4 dimension-related entries in row 2. dims: {}" logger.error(error_msg.format(dims)) - raise(Exception(error_msg.format(dims))) + raise Exception(error_msg.format(dims)) # Explicitly define each dimension num_data_rows = int(dims[0]) @@ -286,7 +286,7 @@ def assemble_data(full_df, num_col_metadata, num_data_rows, num_row_metadata, nu "data.loc['{}', '{}'] = '{}'\nAdd to nan_values if you wish " + "for this value to be considered NaN.").format(bad_row_label, col, val) logger.error(err_msg) - raise(Exception(err_msg)) + raise Exception(err_msg) # Rename the index name and columns name data.index.name = row_index_name diff --git a/cmapPy/pandasGEXpress/parse_gctx.py b/cmapPy/pandasGEXpress/parse_gctx.py index 44eda88..28979d3 100644 --- a/cmapPy/pandasGEXpress/parse_gctx.py +++ b/cmapPy/pandasGEXpress/parse_gctx.py @@ -1,10 +1,10 @@ import logging -import setup_GCToo_logger as setup_logger +from . import setup_GCToo_logger as setup_logger import os import numpy as np import pandas as pd import h5py -import GCToo +from . import GCToo __author__ = "Oana Enache" __email__ = "oana@broadinstitute.org" @@ -58,7 +58,7 @@ def parse(gctx_file_path, convert_neg_666=True, rid=None, cid=None, if not os.path.exists(full_path): err_msg = "The given path to the gctx file cannot be found. full_path: {}" logger.error(err_msg.format(full_path)) - raise (Exception(err_msg.format(full_path))) + raise Exception(err_msg.format(full_path)) logger.info("Reading GCTX: {}".format(full_path)) # open file diff --git a/cmapPy/pandasGEXpress/random_slice.py b/cmapPy/pandasGEXpress/random_slice.py index 1b405ea..78db4b3 100644 --- a/cmapPy/pandasGEXpress/random_slice.py +++ b/cmapPy/pandasGEXpress/random_slice.py @@ -2,9 +2,9 @@ Slices a random subset of a GCToo instance of a user-specified size. """ import logging -import setup_GCToo_logger as setup_logger +from . import setup_GCToo_logger as setup_logger import numpy -import GCToo +from . import GCToo __author__ = "Oana Enache" __email__ = "oana@broadinstitute.org" diff --git a/cmapPy/pandasGEXpress/slice_gct.py b/cmapPy/pandasGEXpress/slice_gct.py index 732921d..e77dc4b 100644 --- a/cmapPy/pandasGEXpress/slice_gct.py +++ b/cmapPy/pandasGEXpress/slice_gct.py @@ -14,10 +14,10 @@ import pandas as pd import re -import setup_GCToo_logger as setup_logger -import GCToo -import parse_gct as pg -import write_gct as wg +from . import setup_GCToo_logger as setup_logger +from . import GCToo +from . import parse_gct as pg +from . import write_gct as wg __author__ = "Lev Litichevskiy" __email__ = "lev@broadinstitute.org" @@ -190,4 +190,4 @@ def slice_gctoo(gctoo, row_bool=None, col_bool=None, rid=None, cid=None, exclude if __name__ == "__main__": - main() \ No newline at end of file + main() diff --git a/cmapPy/pandasGEXpress/tests/test_concat_gctoo.py b/cmapPy/pandasGEXpress/tests/test_concat_gctoo.py index 1053c6a..b55c4c7 100644 --- a/cmapPy/pandasGEXpress/tests/test_concat_gctoo.py +++ b/cmapPy/pandasGEXpress/tests/test_concat_gctoo.py @@ -1,3 +1,5 @@ +from __future__ import print_function + import os import unittest import logging @@ -369,9 +371,9 @@ def parse_args(self, unused): os.remove(expected_output_file) - print - print - print + print() + print() + print() #happy path args.remove_all_metadata_fields = True diff --git a/cmapPy/pandasGEXpress/tests/test_parse_gctx.py b/cmapPy/pandasGEXpress/tests/test_parse_gctx.py index 9241aee..c560df3 100644 --- a/cmapPy/pandasGEXpress/tests/test_parse_gctx.py +++ b/cmapPy/pandasGEXpress/tests/test_parse_gctx.py @@ -11,6 +11,7 @@ import cmapPy.pandasGEXpress.slice_gct as slice_gct import cmapPy.pandasGEXpress.write_gctx as write_gctx import pandas.util.testing as pandas_testing +from six.moves import range __author__ = "Oana Enache" @@ -35,7 +36,7 @@ def __init__(self, data_list, dtype): self.dtype = dtype def read_direct(self, dest): - for i in xrange(len(dest)): + for i in range(len(dest)): dest[i] = self.data_list[i] @@ -62,8 +63,8 @@ def test_parse(self): # first, make & write out temp version of mini_gctoo with int rids/cids new_mg = mini_gctoo_for_testing.make(convert_neg_666=False) int_indexed_data_df = new_mg.data_df.copy() - int_indexed_data_df.index = [str(i) for i in xrange(0, 6)] - int_indexed_data_df.columns = [str(i) for i in xrange(10, 16)] + int_indexed_data_df.index = [str(i) for i in range(0, 6)] + int_indexed_data_df.columns = [str(i) for i in range(10, 16)] int_indexed_row_meta = new_mg.row_metadata_df.copy() int_indexed_row_meta.index = int_indexed_data_df.index @@ -270,20 +271,20 @@ def test_get_ordered_idx(self): # case 1: id_type == None case1 = parse_gctx.get_ordered_idx(None, [], mg.row_metadata_df) - self.assertEqual(case1, range(0, 6), - "Expected oredered idx to be {} but got {}".format(range(0, 6), case1)) + self.assertEqual(case1, list(range(0, 6)), + "Expected ordered idx to be {} but got {}".format(list(range(0, 6)), case1)) # case 2: id_type == "id" case2 = parse_gctx.get_ordered_idx("id", ['LJP007_MCF7_24H:CTL_VEHICLE:DMSO:-666'], mg.col_metadata_df) self.assertEqual(case2, [4], - "Expected oredered idx to be {} but got {}".format([4], case2)) + "Expected ordered idx to be {} but got {}".format([4], case2)) # case 3: id_type == ridx case3 = parse_gctx.get_ordered_idx("idx", [5, 1, 3], mg.col_metadata_df) self.assertEqual(case3, [1, 3, 5], - "Expected oredered idx to be {} but got {}".format([1, 3, 5], case3)) + "Expected ordered idx to be {} but got {}".format([1, 3, 5], case3)) def test_parse_data_df(self): mini_data_df = pd.DataFrame([[-0.283359, 0.011270], [0.304119, 1.921061], [0.398655, -0.144652]], @@ -333,7 +334,7 @@ def test_convert_ids_to_meta_type(self): logger.debug("conversion from regular int to numpy int64 - type(r[0]): {}".format(type(r[0]))) self.assertEqual(np.int64, type(r[0])) - id_list = [str(i) for i in xrange(3)] + id_list = [str(i) for i in range(3)] r = parse_gctx.convert_ids_to_meta_type(id_list, df) logger.debug("conversion from str to numpy int64 - type(r[0]): {}".format(type(r[0]))) self.assertEqual(np.int64, type(r[0])) diff --git a/cmapPy/pandasGEXpress/write_gct.py b/cmapPy/pandasGEXpress/write_gct.py index 80f33ee..c8a2c98 100755 --- a/cmapPy/pandasGEXpress/write_gct.py +++ b/cmapPy/pandasGEXpress/write_gct.py @@ -1,5 +1,5 @@ import logging -import setup_GCToo_logger as setup_logger +from . import setup_GCToo_logger as setup_logger import pandas as pd import numpy as np import os diff --git a/cmapPy/pandasGEXpress/write_gctx.py b/cmapPy/pandasGEXpress/write_gctx.py index 545bcd5..75c43b2 100644 --- a/cmapPy/pandasGEXpress/write_gctx.py +++ b/cmapPy/pandasGEXpress/write_gctx.py @@ -1,5 +1,5 @@ import logging -import setup_GCToo_logger as setup_logger +from . import setup_GCToo_logger as setup_logger import h5py import numpy diff --git a/requirements.txt b/requirements.txt index aa3289a..e3851ba 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,4 @@ numpy==1.11.2 pandas==0.20 h5py==2.6.0 requests==2.13.0 +six diff --git a/setup.py b/setup.py index 391db62..244d31a 100644 --- a/setup.py +++ b/setup.py @@ -6,11 +6,6 @@ here = path.abspath(path.dirname(__file__)) -# Make sure isn't using Python 3, since we currently don't support that -import sys -if not sys.version_info[0] == 2: - sys.exit("Apologies! Python 3 isn't supported yet.") - setup( name='cmapPy', @@ -51,6 +46,10 @@ # that you indicate whether you support Python 2, Python 3 or both. 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.4', + 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.6', ], # What does your project relate to?