Skip to content

Commit

Permalink
Merge pull request #45 from AlexandrovLab/u_ndarray
Browse files Browse the repository at this point in the history
Upgrade v1.3.20: Add np.ndarray to process_input
  • Loading branch information
mdbarnesUCSD authored Feb 16, 2024
2 parents 99a1418 + a57d54d commit 1feb78a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def readme():
return f.read()


VERSION = "1.3.19"
VERSION = "1.3.20"


def write_version_py(filename="sigProfilerPlotting/version.py"):
Expand All @@ -23,7 +23,7 @@ def write_version_py(filename="sigProfilerPlotting/version.py"):
# THIS FILE IS GENERATED FROM SIGPROFILERPLOTTING SETUP.PY
short_version = '%(version)s'
version = '%(version)s'
update = 'Upgrade v1.3.19: Fix plotSV input handling and refactor tests.'
update = 'Upgrade v1.3.20: Add np.ndarray to process_input'
"""
fh = open(filename, "w")
Expand Down
21 changes: 16 additions & 5 deletions sigProfilerPlotting/sigProfilerPlotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,12 @@ def get_context_reference(plot_type):


def process_input(matrix_path, plot_type):
# input data is a DataFrame
if isinstance(matrix_path, pd.DataFrame):
data = matrix_path.copy() # copy a dataframe with deepcopy.
if (
MUTTYPE != data.index.name
): # This condition is if the dataframe already has MUTTYPE as its index_column
# copy dataframe with deepcopy
data = matrix_path.copy()
# Index is not MutationType
if MUTTYPE != data.index.name:
if MUTTYPE in data.columns:
data = data.set_index(MUTTYPE, drop=True)
else:
Expand All @@ -178,8 +179,17 @@ def process_input(matrix_path, plot_type):
elif isinstance(matrix_path, str):
data = pd.read_csv(matrix_path, sep="\t", index_col=0)
data = data.dropna(axis=1, how="all")
# input data is a numpy array
elif isinstance(matrix_path, np.ndarray):
# Note: ndarray does not have index or column names and is not recommended
data = pd.DataFrame(matrix_path)
# add index of mutation type to the dataframe
if plot_type.lower() in type_dict:
data.index = get_context_reference(plot_type)
else:
raise ValueError("ERROR: matrix_path requires path to file or DataFrame.")
raise ValueError(
"ERROR: matrix_path requires pd.DataFrame, path to file, or np.ndarray, not " + f"{type(matrix_path)}."
)

if data.isnull().values.any():
raise ValueError("ERROR: matrix_path contains Nans.")
Expand All @@ -196,6 +206,7 @@ def order_input_context(plot_type, input_data):
ref_format = get_context_reference(plot_type)
reindexed_data = input_data.reindex(ref_format)
else:
# If a non-standard context is used, no sort is applied
reindexed_data = input_data
return reindexed_data

Expand Down
6 changes: 3 additions & 3 deletions sigProfilerPlotting/version.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

# THIS FILE IS GENERATED FROM SIGPROFILERPLOTTING SETUP.PY
short_version = '1.3.19'
version = '1.3.19'
update = 'Upgrade v1.3.19: Fix plotSV input handling and refactor tests.'
short_version = '1.3.20'
version = '1.3.20'
update = 'Upgrade v1.3.20: Add np.ndarray to process_input'


0 comments on commit 1feb78a

Please sign in to comment.