diff --git a/.gitignore b/.gitignore index 5b2b8b1..5478243 100644 --- a/.gitignore +++ b/.gitignore @@ -90,3 +90,14 @@ ENV/ # Visual Studio Code configuration .vscode + +# Cplex installer and installation (generated by install.sh) +cplex_studio2211.linux_x86_64.bin +cplex_studio2211/ + +# Compass cache, test, and output files (generated by test.sh) +_tmp/ +expression.tsv +model.json.gz +reactions.tsv +compass/Resources/COMPASS/RECON2_mat/default-media/preprocess.json diff --git a/compass/compass/algorithm.py b/compass/compass/algorithm.py index 7b7f063..0f77774 100644 --- a/compass/compass/algorithm.py +++ b/compass/compass/algorithm.py @@ -356,7 +356,7 @@ def compass_exchange(model, problem, reaction_penalties, only_exchange=False, pe if(problem.objective.get_name() != 'reaction_penalties'): utils.reset_objective(problem) problem.objective.set_linear( - list(reaction_penalties.iteritems()) + list(reaction_penalties.items()) ) problem.objective.set_name('reaction_penalties') problem.objective.set_sense(problem.objective.sense.minimize) @@ -414,7 +414,7 @@ def compass_exchange(model, problem, reaction_penalties, only_exchange=False, pe if(problem.objective.get_name() != 'reaction_penalties'): utils.reset_objective(problem) problem.objective.set_linear( - list(reaction_penalties.iteritems()) + list(reaction_penalties.items()) ) problem.objective.set_name('reaction_penalties') problem.objective.set_sense(problem.objective.sense.minimize) @@ -522,7 +522,7 @@ def compass_reactions(model, problem, reaction_penalties, perf_log=None, args = if(problem.objective.get_name() != 'reaction_penalties'): utils.reset_objective(problem) problem.objective.set_linear( - list(reaction_penalties.iteritems()) + list(reaction_penalties.items()) ) problem.objective.set_name('reaction_penalties') problem.objective.set_sense(problem.objective.sense.minimize) diff --git a/compass/compass/algorithm_t.py b/compass/compass/algorithm_t.py index d79f565..e4fd31a 100644 --- a/compass/compass/algorithm_t.py +++ b/compass/compass/algorithm_t.py @@ -304,7 +304,7 @@ def compass_transposed(ranges, data, model, media, args): # Minimize Penalty utils.reset_objective(problem) problem.objective.set_linear( - list(reaction_penalties[sample_name].iteritems()) + list(reaction_penalties[sample_name].items()) ) problem.objective.set_sense(problem.objective.sense.minimize) diff --git a/compass/compass/microclustering.py b/compass/compass/microclustering.py index b49a9bf..7e50403 100644 --- a/compass/compass/microclustering.py +++ b/compass/compass/microclustering.py @@ -98,8 +98,8 @@ def filterGenesThreshold(data, threshold): def filterGenesFano(data, num_mad=2): #Could sample columns at random to improve runtime - mu = data.mean(axis=1).ravel() - fano = data.var(axis=1).ravel() / mu + mu = data.mean(axis=1).to_numpy() + fano = data.var(axis=1).to_numpy() / mu mu_argsort = np.argsort(mu) mu_sort = mu[mu_argsort] @@ -178,7 +178,7 @@ def pool_matrix_cols(data, pools): for i in pools[g]: groups[data.columns[i]] = g groups = pd.DataFrame.from_dict(groups, orient='index', columns=['compass_microcluster']).T - return data.append(groups).T.groupby("compass_microcluster").mean().T.rename(mapper=lambda x: 'cluster_'+str(int(x)), axis=1) + return pd.concat([data, groups]).T.groupby("compass_microcluster").mean().T.rename(mapper=lambda x: 'cluster_'+str(int(x)), axis=1) def unpool_columns(pooled_data, pools, data): unpooled_cols = [] diff --git a/compass/compass/penalties.py b/compass/compass/penalties.py index 3a21910..f10f75b 100644 --- a/compass/compass/penalties.py +++ b/compass/compass/penalties.py @@ -155,7 +155,7 @@ def eval_reaction_penalties_shared(model, expression, # Compute reaction expression for each sample reaction_expression = [] - for name, expression_data in expression.iteritems(): + for name, expression_data in expression.items(): reaction_expression.append( eval_reaction_expression_single( model, expression_data, and_function diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..0733184 --- /dev/null +++ b/install.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +set -e # Exit immediately if a command exits with a non-zero status. +set -u # Treat unset variables as an error. + +# Set the Cplex installer name and the install path for Cplex. +CPLEX_INSTALLER="cplex_studio2211.linux_x86_64.bin" +CPLEX_INSTALL_DIR="cplex_studio2211" +CPLEX_INSTALL_PATH=$(realpath "${CPLEX_INSTALL_DIR}") + +# Set up virtual environment. +python3 -m venv .env +# shellcheck disable=SC1091 +source .env/bin/activate + +# Install Cplex and its Python API. +chmod u+x "${CPLEX_INSTALLER}" +"./${CPLEX_INSTALLER}" -i silent -DINSTALLER_UI=silent -DLICENSE_ACCEPTED=TRUE -DUSER_INSTALL_DIR="${CPLEX_INSTALL_PATH}" +python3 "${CPLEX_INSTALL_PATH}/python/setup.py" install + +# Install Compass. +pip3 install --editable . diff --git a/test.sh b/test.sh new file mode 100644 index 0000000..ce4866e --- /dev/null +++ b/test.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +set -e # Exit immediately if a command exits with a non-zero status. + +# Activate the environment generated by install.sh. +# shellcheck disable=SC1091 +source .env/bin/activate + +# Download the test data. +gdown https://raw.githubusercontent.com/YosefLab/Compass/refs/heads/master/compass/Resources/Test-Data/tsv_format/expression.tsv + +# Run Compass. +compass --num-thread 32 --data expression.tsv --species homo_sapiens + +# Clean up. +rm expression.tsv +rm model.json.gz +rm reactions.tsv