Skip to content

Commit

Permalink
Updating code to work for #666
Browse files Browse the repository at this point in the history
  • Loading branch information
adkinsrs committed Aug 12, 2024
1 parent f00bf79 commit dbf77e3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
3 changes: 1 addition & 2 deletions services/projectr/install_bioc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ Rver="${Rmaj}.3.1"

current_dir=$(pwd)

# Install and build R (Using 'apt-get install' on Ubuntu Trusty installs version 3.0.2 of R)
curl http://lib.stat.cmu.edu/R/CRAN/src/base/${Rmaj}/${Rver}.tar.gz | tar -C /opt -zx
curl -s -L http://lib.stat.cmu.edu/R/CRAN/src/base/${Rmaj}/${Rver}.tar.gz | tar xzv -C /opt
cd /opt/${Rver}
/opt/${Rver}/configure --with-readline=no --enable-R-shlib --enable-BLAS-shlib --with-x=no || exit 1
make || exit 1
Expand Down
9 changes: 8 additions & 1 deletion services/projectr/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os, sys
import pandas as pd
from io import StringIO
from flask import Flask, abort, jsonify, request

cloud_logging = False
Expand Down Expand Up @@ -38,7 +39,9 @@ def do_binary_projection(target_df, loading_df):
"""Perform projection based on the number of genes that were expressed in the cell or observation."""
# Only applies with unweighted gene carts.
tp_target_series = target_df.astype(bool).sum(axis=0).transpose()
return pd.DataFrame(data=tp_target_series, columns=loading_df.columns, index=tp_target_series.index)
# Need to convert data to list of lists to create a DataFrame.
# https://stackoverflow.com/questions/70854450/pandas-dataframe-shape-of-passed-values-is-5-1-indices-imply-5-2
return pd.DataFrame(data=[tp_target_series], columns=loading_df.columns, index=tp_target_series.index)

def do_pca_projection(target_df, loading_df):
"""Perform projection of PCA loadings."""
Expand Down Expand Up @@ -66,6 +69,10 @@ def index():
write_entry("projectr", "INFO", "Genecart ID: {}".format(genecart_id))


# pd.read_json gives a FutureWarning, and suggest to wrap the json in StringIO.
target = StringIO(target)
loadings = StringIO(loadings)

target_df = pd.read_json(target, orient="split")
loading_df = pd.read_json(loadings, orient="split")

Expand Down
2 changes: 1 addition & 1 deletion services/projectr/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Flask==3.0.0
gunicorn==20.1.0
rpy2==3.5.1 # 3.5.2 and up gives errors with rpy2py and py2rpy
pandas==1.4.1
pandas==2.2.1
google-cloud-logging

0 comments on commit dbf77e3

Please sign in to comment.