Skip to content

Commit

Permalink
MacOS bundle (#2)
Browse files Browse the repository at this point in the history
* Try that

* Get python path

* Get python path

* Get python path

* That's not going to work

* Compile scanfold with nuitka

* Missing sed flag

* Bundle rnastructure and viennarna

* tar file

* less verbose

* i think thats everything

* fix path

* More fixes

* Change multiprocessing method to work with nuitka

* python2/python3

* Switch fork

* Try using threads

* Build macos for releases

* Make run_me double clickable

* Final tweaks

* Switch submodule back
  • Loading branch information
Nick Booher authored Feb 16, 2021
1 parent 612dff5 commit 059f451
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 16 deletions.
16 changes: 15 additions & 1 deletion .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
name: MacOS package

on:
release:
types: [published]
workflow_dispatch:

jobs:
Expand All @@ -29,4 +31,16 @@ jobs:
if: ${{ success() && github.event_name == 'workflow_dispatch' }}
with:
name: scanfoldigv-macos
path: ./scanfoldigv-macos.zip
path: ./scanfoldigv-macos.zip

- name: Upload Release Asset (automatically on release)
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: ./scanfoldigv-macos.zip
asset_name: scanfoldigv-macos-${{github.event.release.tag_name}}.zip
asset_content_type: application/zip
if: ${{ github.event_name == 'release' }}
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ Patched version of IGV that integrates ScanFold functionality.

## Run

### Windows
A pre-built version for Windows is available on [releases](https://github.com/ResearchIT/scanfoldigv/releases).
### Windows and Mac
A pre-built version is available on [releases](https://github.com/ResearchIT/scanfoldigv/releases).

### Mac and Linux
### Linux

Follow instructions to compile. Then

Expand Down
2 changes: 1 addition & 1 deletion ScanFold
Submodule ScanFold updated 1 files
+13 −2 ScanFoldSharedIGV.py
62 changes: 60 additions & 2 deletions macos/bundle_macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,69 @@ popd
pushd igv
./gradlew clean
./gradlew createMacAppWithJavaDistZip -PjdkBundleMac=${TOPLEVEL}/lib/jdk-11.0.10+9-jre/Contents/Home
#unzip -d ${BUNDLE_PREFIX} distributions/IGV_MacApp_user_WithJava.zip
mv build ${BUNDLE_PREFIX}/IGV
unzip build/distributions/IGV_MacApp_user_WithJava.zip
mv IGV_User.app ${BUNDLE_PREFIX}/IGV.app
popd


# compile scanfold
pushd ScanFold
sed -i -e 's/#!\/usr\/local\/bin\/python.*//' ScanFold-Scan_IGV.py ScanFold-Fold_IGV.py
python3 -mvenv env
. env/bin/activate
pip install Nuitka biopython numpy
python -m nuitka --standalone --plugin-enable=numpy ScanFold-Scan_IGV.py
python -m nuitka --standalone --plugin-enable=numpy ScanFold-Fold_IGV.py
deactivate
popd

# bundle scanfold
mkdir -p ${BUNDLE_PREFIX}/scanfold/

pushd ${BUNDLE_PREFIX}/scanfold
cp -R ${TOPLEVEL}/ScanFold/{ScanFold-Scan_IGV.dist,ScanFold-Fold_IGV.dist} .
cp ${TOPLEVEL}/scripts/run_scanfold.py .
popd

# viennarna
pushd lib
curl -L -O https://github.com/ViennaRNA/ViennaRNA/releases/download/v2.4.16/ViennaRNA-2.4.16.tar.gz
tar -xzf ViennaRNA-2.4.16.tar.gz
pushd ViennaRNA-2.4.16
mkdir target
#export ac_cv_func_realloc_0_nonnull=yes
#export ac_cv_func_malloc_0_nonnull=yes
CONFIGURE_OPTIONS=" --without-swig \
--without-doc \
--without-forester \
--with-cluster \
--with-kinwalker \
--disable-mpfr \
--disable-pthreads \
--disable-tty-colors \
--disable-lto"
./configure --prefix=${PWD}/target ${CONFIGURE_OPTIONS}
make
make install
mkdir -p ${BUNDLE_PREFIX}/ViennaRNA
mv target/bin/RNAfold ${BUNDLE_PREFIX}/ViennaRNA/
cp license.txt ${BUNDLE_PREFIX}/ViennaRNA/
popd
popd

# rnastructure
pushd lib
curl -L -O http://rna.urmc.rochester.edu/Releases/current/RNAstructureTextInterfacesMac.tgz
tar -xzf RNAstructureTextInterfacesMac.tgz
mv RNAstructureTextInterfacesMac.tgz
mkdir ${BUNDLE_PREFIX}/RNAstructure
mv RNAstructure/exe/ct2dot ${BUNDLE_PREFIX}/RNAstructure/
mv RNAstructure/gpl.txt ${BUNDLE_PREFIX}/RNAstructure/
mv RNAstructure/data_tables ${BUNDLE_PREFIX}/RNAstructure/
popd

# main
pushd ${BUNDLE_PREFIX}
cp ${TOPLEVEL}/macos/run_me.command .
zip -r ${TOPLEVEL}/scanfoldigv-macos.zip *
popd
10 changes: 10 additions & 0 deletions macos/run_me.command
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export SCANFOLDRUNDIR=$(cd `dirname $(readlink $0 || echo $0)` && pwd)
export SCANFOLDPYTHONINTERPRETER=$(which python)
export SCANFOLDRUNSCRIPT=${SCANFOLDRUNDIR}/scanfold/run_scanfold.py
export SCANFOLDISBUNDLED=TRUE
#switch to this if fork doesn't work
#export SCANFOLDMPUSETHREADS=TRUE
export SCANFOLDMPMETHOD=fork
cd "${SCANFOLDRUNDIR}"
xattr -r -d com.apple.quarantine . >/dev/null 2>&1
open IGV.app
39 changes: 30 additions & 9 deletions scripts/run_scanfold.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
import tempfile
import sys
import os
import platform

def run_me(script, workdir, args):

proc_env = os.environ.copy()
cwd = os.getcwd()

if os.name == 'nt':
script = os.path.join(cwd, 'scanfold', script)
if platform.system() == 'Windows':
script = os.path.join(cwd, 'scanfold', script + ".py")
proc_env['DATAPATH'] = os.path.join(cwd, 'RNAstructure', 'data_tables')
new_path = [
os.path.join(cwd, 'ViennaRNA'),
Expand All @@ -19,8 +20,22 @@ def run_me(script, workdir, args):
]
proc_env['PATH'] = ';'.join(new_path)
python_interpreter = os.environ['SCANFOLDPYTHONINTERPRETER']
command = [python_interpreter, '-u', script]
elif platform.system() == 'Darwin' and 'SCANFOLDISBUNDLED' in os.environ:
proc_env['DATAPATH'] = os.path.join(cwd, 'RNAstructure', 'data_tables')
new_path = [
os.path.join(cwd, 'ViennaRNA'),
os.path.join(cwd, 'RNAstructure'),
proc_env['PATH']
]
proc_env['PATH'] = ':'.join(new_path)
python_interpreter = os.environ['SCANFOLDPYTHONINTERPRETER']
if script == "ScanFold-Scan_IGV":
command = [os.path.join(cwd, 'scanfold', 'ScanFold-Scan_IGV.dist', 'ScanFold-Scan_IGV')]
else:
command = [os.path.join(cwd, 'scanfold', 'ScanFold-Fold_IGV.dist', 'ScanFold-Fold_IGV')]
else:
script = os.path.join(cwd, 'ScanFold', script)
script = os.path.join(cwd, 'ScanFold', script + ".py")
proc_env['DATAPATH'] = os.path.join(cwd, 'env', 'data_tables')
proc_env['VIRTUAL_ENV'] = os.path.join(cwd, 'env')
new_path = [
Expand All @@ -29,14 +44,20 @@ def run_me(script, workdir, args):
]
proc_env['PATH'] = ':'.join(new_path)
python_interpreter = 'python'

command = [python_interpreter, '-u', script]
command = [python_interpreter, '-u', script]

command.extend(args)

process = subprocess.Popen(command, stdout=subprocess.PIPE, env=proc_env, cwd=workdir, bufsize=0)
for c in iter(lambda: process.stdout.read(1), b''):
sys.stdout.buffer.write(c)
sys.stdout.buffer.flush()
if hasattr(sys.stdout, 'buffer'):
# python 3
sys.stdout.buffer.write(c)
sys.stdout.buffer.flush()
else:
# python 2 (macos)
sys.stdout.write(c)
sys.stdout.flush()

def mktemp(directory, extension, name="output"):
file_handle, file_path = tempfile.mkstemp(prefix=name, suffix=extension, dir=directory)
Expand Down Expand Up @@ -72,7 +93,7 @@ def main(args):
'--fasta_index', FASTAINDEX
]

run_me('ScanFold-Scan_IGV.py', args.WORKDIR, scan_params)
run_me('ScanFold-Scan_IGV', args.WORKDIR, scan_params)

OUT1 = mktemp(args.WORKDIR, '.nofilter.ct')
OUT2 = mktemp(args.WORKDIR, '.-1filter.ct')
Expand Down Expand Up @@ -116,7 +137,7 @@ def main(args):
if args.GLOBALREFOLD:
fold_params.append('--global_refold')

run_me('ScanFold-Fold_IGV.py', args.WORKDIR, fold_params)
run_me('ScanFold-Fold_IGV', args.WORKDIR, fold_params)

files_to_load = [
BPTRACK,
Expand Down

0 comments on commit 059f451

Please sign in to comment.