Skip to content

Commit

Permalink
Merge pull request #17 from mruffalo/python3
Browse files Browse the repository at this point in the history
Support Python 2.7, 3.4, 3.5, 3.6
  • Loading branch information
oena committed Nov 5, 2017
2 parents 0f14a08 + 1aa1b1f commit cf02643
Show file tree
Hide file tree
Showing 27 changed files with 83 additions and 73 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pycache__/
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ language: python
# python versioning
python:
- 2.7
- 3.4
- 3.5
- 3.6

# requirements
install:
Expand Down
6 changes: 3 additions & 3 deletions cmapPy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from clue_api_client import *
from pandasGEXpress import *
from set_io import *
from .clue_api_client import *
from .pandasGEXpress import *
from .set_io import *
2 changes: 1 addition & 1 deletion cmapPy/clue_api_client/cell_queries.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
import setup_logger
from . import setup_logger

__authors__ = "David L. Lahr"
__email__ = "dlahr@broadinstitute.org"
Expand Down
2 changes: 1 addition & 1 deletion cmapPy/clue_api_client/clue_api_client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import requests
import logging
import setup_logger
from . import setup_logger
import json
import copy

Expand Down
2 changes: 1 addition & 1 deletion cmapPy/clue_api_client/gene_queries.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
import setup_logger
from . import setup_logger

__authors__ = "David L. Lahr"
__email__ = "dlahr@broadinstitute.org"
Expand Down
2 changes: 1 addition & 1 deletion cmapPy/clue_api_client/macchiato_queries.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
import setup_logger
from . import setup_logger

__authors__ = "David L. Lahr"
__email__ = "dlahr@broadinstitute.org"
Expand Down
4 changes: 2 additions & 2 deletions cmapPy/clue_api_client/mock_clue_api_client.py
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion cmapPy/clue_api_client/pert_queries.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
import setup_logger
from . import setup_logger

__authors__ = "David L. Lahr"
__email__ = "dlahr@broadinstitute.org"
Expand Down
5 changes: 3 additions & 2 deletions cmapPy/clue_api_client/tests/test_clue_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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"))
Expand Down
4 changes: 2 additions & 2 deletions cmapPy/clue_api_client/tests/test_pert_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cmapPy/pandasGEXpress/GCToo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
22 changes: 12 additions & 10 deletions cmapPy/pandasGEXpress/concat_gctoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)))

Expand All @@ -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
Expand All @@ -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))
Expand Down
6 changes: 3 additions & 3 deletions cmapPy/pandasGEXpress/gct2gctx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions cmapPy/pandasGEXpress/gctx2gct.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions cmapPy/pandasGEXpress/mini_gctoo_for_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
6 changes: 3 additions & 3 deletions cmapPy/pandasGEXpress/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
18 changes: 9 additions & 9 deletions cmapPy/pandasGEXpress/parse_gct.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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])
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions cmapPy/pandasGEXpress/parse_gctx.py
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions cmapPy/pandasGEXpress/random_slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 5 additions & 5 deletions cmapPy/pandasGEXpress/slice_gct.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -190,4 +190,4 @@ def slice_gctoo(gctoo, row_bool=None, col_bool=None, rid=None, cid=None, exclude


if __name__ == "__main__":
main()
main()
8 changes: 5 additions & 3 deletions cmapPy/pandasGEXpress/tests/test_concat_gctoo.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import print_function

import os
import unittest
import logging
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit cf02643

Please sign in to comment.