diff --git a/.gitignore b/.gitignore index 299f26c..e2963be 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,6 @@ *.pyc splicing_0.1.tar.gz pysplicing-0.1.tar.gz +env/* +build/* +misopy/test-output/* diff --git a/Makefile b/Makefile index 70c61a6..b7ce07d 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,9 @@ all: Pythonpackage +virtualenv: Pythonpackage + ./install.sh + ######################################################## RSRC=$(wildcard src/*.c) $(wildcard src/*.h) $(wildcard src/*.pmt) diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..1211ecf --- /dev/null +++ b/install.sh @@ -0,0 +1,25 @@ +#!/bin/bash +VIRTUALENV=`which virtualenv-2.7` +if [ "$VIRTUALENV" == "" ]; then + VIRTUALENV=`which virtualenv-2.6` +fi +if [ "$VIRTUALENV" == "" ]; then + VIRTUALENV=`which virtualenv` +fi +if [ "$VIRTUALENV" == "" ]; then + echo "Missing virtualenv!" + exit 1 +fi + +if [ ! -e env ]; then + echo "Initializing virtualenv folder (env)" + $VIRTUALENV env +fi +. env/bin/activate +python setup.py install --prefix env +pip install numpy +pip install -r requirements.txt + +# +# If you're on a Mac, and matplotlib won't install, try this: +# LDFLAGS="-L/usr/X11/lib" CFLAGS="-I/usr/X11/include -I/usr/X11/include/freetype2 -I/usr/X11/include/libpng15" pip install matplotlib diff --git a/miso b/miso new file mode 100755 index 0000000..d83eb63 --- /dev/null +++ b/miso @@ -0,0 +1,44 @@ +#!/bin/bash +function usage() { + echo "Usage: $(basename $0) command args..." + echo "" + echo "Valid commands: exon_utils" + echo " filter_events" + echo " index_gff" + echo " module_availability" + echo " pe_utils" + echo " plot" + echo " run_events_analysis" + echo " run" + echo " sam_to_bam" + echo "" + exit 1 +} +REAL=`python -c 'import os,sys;print os.path.realpath(sys.argv[1])' "$0"` +DIR=`dirname "$REAL"` +. $DIR/env/bin/activate + + +if [ ! "$1" ]; then + usage +fi + +cmd="$1" +shift + +export MISO_SHELL_EXEC="$0" + +if [ "$cmd" == "run" ]; then + python $DIR/env/bin/run_miso.py "$@" +elif [ -e "$DIR/env/bin/$cmd.py" ]; then + python "$DIR/env/bin/$cmd.py" "$@" +elif [ -e "$DIR/env/bin/$cmd" ]; then + python "$DIR/env/bin/$cmd" "$@" +elif [ -e "$cmd" ]; then + # this is for hard-coded commands, such as used in the cluster code + # or to run test-scripts + python "$cmd" "$@" +else + echo "Unknown command: $cmd" + usage +fi diff --git a/misopy/run_events_analysis.py b/misopy/run_events_analysis.py index 3f30310..38caab4 100644 --- a/misopy/run_events_analysis.py +++ b/misopy/run_events_analysis.py @@ -47,8 +47,8 @@ def compute_all_genes_psi(gff_dir, bam_filename, read_len, output_dir, all_miso_cmds = [] for gene_id, gff_index_filename in gene_ids_to_gff_index.iteritems(): - miso_cmd = "python %s --compute-gene-psi \"%s\" \"%s\" %s %s --read-len %d " \ - %(miso_run, gene_id, gff_index_filename, bam_filename, output_dir, + miso_cmd = "%s %s --compute-gene-psi \"%s\" \"%s\" %s %s --read-len %d " \ + %(Settings.get_miso_exec(), miso_run, gene_id, gff_index_filename, bam_filename, output_dir, read_len) if paired_end != None: # Run in paired-end mode @@ -183,8 +183,9 @@ def compute_psi(sample_filenames, output_dir, event_type, read_len, overhang_len events_filename = events.output_file(results_output_dir, sample_label) # Run MISO on them - miso_cmd = 'python %s --compute-two-iso-psi %s %s --event-type %s --read-len %d --overhang-len %d ' \ - %(os.path.join(miso_path, 'run_miso.py'), + miso_cmd = '%s %s --compute-two-iso-psi %s %s --event-type %s --read-len %d --overhang-len %d ' \ + %(Settings.get_miso_exec(), + os.path.join(miso_path, 'run_miso.py'), events_filename, results_output_dir, event_type, diff --git a/misopy/run_miso.py b/misopy/run_miso.py index 9401891..c8c8030 100644 --- a/misopy/run_miso.py +++ b/misopy/run_miso.py @@ -148,8 +148,9 @@ def run_two_iso_on_cluster(miso_path, events_filename, event_type, psi_outdir, num_jobs_per_batch = len(event_batch) print "Processing a batch of size %d events" %(num_jobs_per_batch) for event_name in event_batch: - miso_event_cmd = 'python %s --run-two-iso-event \"%s\" %s %s --event-type %s --read-len %d --overhang-len %d' \ - %(os.path.join(miso_path, 'run_miso.py'), + miso_event_cmd = '%s %s --run-two-iso-event \"%s\" %s %s --event-type %s --read-len %d --overhang-len %d' \ + %(Settings.get_miso_exec(), + os.path.join(miso_path, 'run_miso.py'), event_name, events_filename, psi_outdir, @@ -181,7 +182,7 @@ def get_curr_script_cmd(): Get the invocation of the current script (with its command line arguments) as a full command for use in a script. """ - return 'python ' + get_current_args() + return '%s %s' % (Settings.get_miso_exec(), get_current_args()) def strip_option(cmd, option): """ diff --git a/misopy/settings.py b/misopy/settings.py index 8a10b6c..e10cdfc 100644 --- a/misopy/settings.py +++ b/misopy/settings.py @@ -1,10 +1,12 @@ ## ## Settings with relevant directories ## + import misopy from misopy.parse_csv import * import ConfigParser import os +import sys miso_path = os.path.dirname(os.path.abspath(os.path.expanduser(__file__))) @@ -141,6 +143,12 @@ def get_filters(cls, event_type): @classmethod def get(cls): return cls.global_settings + + @classmethod + def get_miso_exec(cls): + if 'MISO_SHELL_EXEC' in os.environ: + return os.environ['MISO_SHELL_EXEC'] + return sys.executable def load_settings(settings_filename): diff --git a/misopy/test_cluster.py b/misopy/test_cluster.py index 1df31ae..01f95ff 100644 --- a/misopy/test_cluster.py +++ b/misopy/test_cluster.py @@ -4,6 +4,7 @@ ## import unittest import os +from misopy.settings import Settings class TestCluster(unittest.TestCase): """ @@ -13,8 +14,8 @@ def setUp(self): # Find out the current directory self.miso_path = os.path.dirname(os.path.abspath(os.path.expanduser(__file__))) self.tests_data_dir = os.path.join(self.miso_path, "test-data") - self.events_analysis_cmd = "python %s " %(os.path.join(self.miso_path, - "run_events_analysis.py")) + self.events_analysis_cmd = "%s %s " % (Settings.get_miso_exec(), + os.path.join(self.miso_path, "run_events_analysis.py")) self.tests_output_dir = os.path.join(self.miso_path, "test-output") self.test_sam_filename = os.path.join(self.tests_data_dir, "sam-data", @@ -69,7 +70,7 @@ def test_cluster_gene_psi(self): # First index the GFF of interest gff_filename = os.path.join(self.gff_events_dir, "mm9", "genes", "Atp2b1.mm9.gff") gff_index_dir = os.path.join(self.gff_events_dir, "mm9", "indexed") - index_cmd = "python %s --index %s %s" %(self.index_gff_script, + index_cmd = "%s %s --index %s %s" %(Settings.get_miso_exec(), self.index_gff_script, gff_filename, gff_index_dir) @@ -92,4 +93,5 @@ def test_cluster_gene_psi(self): if __name__ == '__main__': + Settings.load() unittest.main() diff --git a/misopy/test_miso.py b/misopy/test_miso.py index 77a8d2c..400a07a 100644 --- a/misopy/test_miso.py +++ b/misopy/test_miso.py @@ -1,6 +1,7 @@ #!/usr/bin/env python import unittest import os +from misopy.settings import Settings class TestMISO(unittest.TestCase): """ @@ -10,8 +11,9 @@ def setUp(self): # Find out the current directory self.miso_path = os.path.dirname(os.path.abspath(os.path.expanduser(__file__))) self.tests_data_dir = os.path.join(self.miso_path, "test-data") - self.events_analysis_cmd = "python %s " %(os.path.join(self.miso_path, - "run_events_analysis.py")) + self.events_analysis_cmd = "%s %s" % (Settings.get_miso_exec(), + os.path.join(self.miso_path, + "run_events_analysis.py")) self.tests_output_dir = os.path.join(self.miso_path, "test-output") self.test_sam_filename = os.path.join(self.tests_data_dir, "sam-data", @@ -29,9 +31,10 @@ def test_a_sam_to_bam(self): print "Testing conversion of SAM to BAM..." output_dir = os.path.join(self.tests_output_dir, "sam-output") - sam_to_bam_cmd = "python %s --convert %s %s" %(self.sam_to_bam_script, - self.test_sam_filename, - output_dir) + sam_to_bam_cmd = "%s %s --convert %s %s" % (Settings.get_miso_exec(), + self.sam_to_bam_script, + self.test_sam_filename, + output_dir) print "Executing: %s" %(sam_to_bam_cmd) os.system(sam_to_bam_cmd) @@ -58,9 +61,10 @@ def test_z_gene_psi(self): gff_filename = os.path.join(self.gff_events_dir, "mm9", "genes", "Atp2b1.mm9.gff") gff_index_dir = os.path.join(self.gff_events_dir, "mm9", "genes", "Atp2b1", "indexed") print "Testing GFF indexing of: %s" %(gff_filename) - index_cmd = "python %s --index %s %s" %(self.index_gff_script, - gff_filename, - gff_index_dir) + index_cmd = "%s %s --index %s %s" % (Settings.get_miso_exec(), + self.index_gff_script, + gff_filename, + gff_index_dir) print "Executing: %s" %(index_cmd) os.system(index_cmd) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..a22a9ec --- /dev/null +++ b/requirements.txt @@ -0,0 +1,5 @@ +numpy +scipy +simplejson +pysam +matplotlib