yarden / MISO

MISO: Mixture of Isoforms model for RNA-Seq isoform quantitation
http://genes.mit.edu/burgelab/miso/index.html
132 stars 74 forks source link

Add python shebang to the top #59

Open roryk opened 11 years ago

roryk commented 11 years ago

Hey Yarden,

Since this gets installed as a script I put the business up top to let it get executed.

yarden commented 10 years ago

Hi Rory,

Are you sure you installed the package rather than running the source code? When you install packages the Python package manager is supposed to use the path of the Python version you installed, and prepend it to each of the scripts (that typically go in a bin directory, like ~/.local/bin). Adding a shebang manually is not a good solution since many people have systems with multiple Python versions, and then the script could invoke the wrong one (and not the one used to install MISO.) --Yarden

roryk commented 10 years ago

Hi Yarden,

I think adding the /usr/bin/env -E to the top does inject the python-that-installed MISO there. Without it, the path doesn't seem to be added. On a fresh vagrant box I cloned the repo and installed with python setup.py install:

(bcbio)vagrant@vagrant-ubuntu-precise-64:~/tmp/MISO$ more `which index_gff`
(bcbio)vagrant@vagrant-ubuntu-precise-64:~/tmp/MISO$ more `which index_gff`
# -*- mode: python; -*-
##
## Script to build an indexed representation of a GFF file for efficient
## retrieval of genes
##
import os
import sys
import time

Using the /usr/bin/env -E python patch:

(bcbio)vagrant@vagrant-ubuntu-precise-64:/v-data/MISO$ more `which index_gff`

#!/home/vagrant/anaconda/envs/bcbio/bin/python -E
# -*- mode: python; -*-
##
## Script to build an indexed representation of a GFF file for efficient
## retrieval of genes
##
import os
import sys
import time
import glob
import shelve

Maybe distribute or whatever doesn't add the path to python to files that don't end in .py?

I stuck the -E on the end-- that ignores environment variables, so if the user has some wonky PYTHONPATH set or PYTHONHOME set that is pointing to the wrong MISO installation or what not, this will make it so python only uses the site-libraries from the specific python the top points to. If that behavior isn't what you are looking for removing it works as well.

roryk commented 10 years ago

Congraulations on your defense. :)

roryk commented 10 years ago

Just a note, the index_gff file doesn't get overwritten if you already installed MISO, so you have to manually remove it and install it if you want to see the that the /usr/bin/env is adding the path at the top. Python distribution FTL.

yarden commented 10 years ago

python setup.py install is evil! You're not actually using distribute with that as far as I know, which is why it doesn't install binaries as it should. When I install it using distribute's easy_install or using pip, the scripts get placed in a bin directory of Python packages (in my case ~/local/bin/) and then the header looks like this:

$ head ~/.local/bin/run_events_analysis.py 
#!/usr/local/bin/python2.7
# EASY-INSTALL-DEV-SCRIPT: 'misopy==0.5.0','run_events_analysis.py'
__requires__ = 'misopy==0.5.0'
from pkg_resources import require; require('misopy==0.5.0')
del require
__file__ = '/lab/solexa_jaenisch/solexa_jaenisch2/yarden/MISO/misopy/run_events_analysis.py'
execfile(__file__)

That's all automatically generated by the package installer. On some Unix systems, /usr/bin/env does not even exist, so this is why the paths are not hard coded. The Python package managers are supposed to get around this problem by dynamically using the Python version you used to install the package as the path in the shebang, but unfortunately it can be counterintuitive. If you install with distribute or pip, I think this issue should go away, as long as you invoke the bin/ version of the script (i.e. the installed, executable version) rather than the source / repository version of the script.

roryk commented 10 years ago

Hi Yarden,

Thanks for responding, sorry to be a pain in the neck. The repository on pip is a version behind and I think the 0.5.0 version uses the index_gff file with the index_gff.py file being deprecated:

https://github.com/yarden/MISO/blob/fastmiso/misopy/index_gff.py

Using setup.py and pip, without the patch on the 0.4.9 version does set the flag on index_gff.py correctly but using either setup.py or pip with the 0.5.0 version doesn't set it on the index_gff (not index_gff.py as that is deprecated) file. I blew away the old version and reinstalled this one via pip:

pip install -U --force-reinstall git+git://github.com/yarden/MISO.git#egg=misopy
(miso)vagrant@vagrant-ubuntu-precise-64:~/tmp/MISO$ head `which index_gff`
# -*- mode: python; -*-
##
## Script to build an indexed representation of a GFF file for efficient
## retrieval of genes
##
import os
import sys
import time
yarden commented 10 years ago

Hi Rory,

Thanks for this info. So 5.0 is not released yet - I'll see if I can reproduce this issue with index_gff and then fix it. But can you confirm that with pip and 0.4.9, the scripts (like index_gff.py, before it got deprecated) do get the proper shebang headers? Or was that not working for you? I was unclear on whether that worked for you once you used pip/distribute easy_install. Thanks. Best, --Yarden

roryk commented 10 years ago

Hi Yarden,

Confirmed, index_gff.py got the shebang, just index_gff was not getting it set properly.

yarden commented 10 years ago

Hi Rory,

You can try out a 'pre-release' of miso 0.5.0 from the 'dev' branch of GitHub. The manual for it is here:

https://miso.readthedocs.org/en/dev

It has several improvements but more to the point here it should now fully take care of the executable v. non-executable issue you had. If you do end up trying it, would love to hear your feedback. Thanks very much. Best, Yarden

yarden commented 10 years ago

If you try it, try it with latest release, we've had some minor issues in misopy-0.5.0 release.