1

I have been struggling this for a while and i don't know what i am doing wrong. I am trying to run a shell script inside a container and the shell script reads a python script from the directory where the shell script is located. But i am getting this error saying `python: can't open file 'get_gene_length_filter.py': [Errno 2] No such file or directory'.

Here is my Dockerfile:

FROM ubuntu:14.04.3
RUN apt-get update && apt-get install -y g++ \
                make \
                git \
                zlib1g-dev \
                python \
                wget \
                curl \
                python-matplotlib \
                python-numpy \
                python-pandas

ENV BINPATH /usr/bin
ENV EVO2GIT https://upendra_35@bitbucket.org/upendra_35/evolinc_docker.git
RUN git clone $EVO2GIT
WORKDIR /evolinc_docker
RUN chmod +x evolinc-part-I.sh && cp evolinc-part-I.sh $BINPATH

RUN wget -O- http://cole-trapnell-lab.github.io/cufflinks/assets/downloads/cufflinks-2.2.1.Linux_x86_64.tar.gz | tar xzvf -
RUN wget -O- https://github.com/TransDecoder/TransDecoder/archive/2.0.1.tar.gz | tar xzvf -

ENV PATH /evolinc_docker/cufflinks-2.2.1.Linux_x86_64/:$PATH
ENV PATH /evolinc_docker/TransDecoder-2.0.1/:$PATH
ENTRYPOINT ["/usr/bin/evolinc-part-I.sh"]
CMD ["-h"]

Here is my git repo code:

#!/bin/bash
# Create a directory to move all the output files
mkdir output
# Extracting classcode u transcripts, making fasta file, removing transcripts > 200 and selecting protein coding transcripts
grep '"u"' $comparefile | gffread -w transcripts_u.fa -g $referencegenome - && python get_gene_length_filter.py transcripts_u.fa \
    transcripts_u_filter.fa && TransDecoder.LongOrfs -t transcripts_u_filter.fa

And this is how i'm running it:

docker run --rm -v $(pwd):/working-dir -w /working-dir ubuntu/evolinc -c AthalianaslutteandluiN30merged.gtf -g TAIR10_chr.fasta  
upendra
  • 2,141
  • 9
  • 39
  • 64

2 Answers2

5

I'm going to take a guess and assume that get_gene_length_filter.py is in /evolinc_docker, the working directory declared in the Dockerfile. Unfortunately, when you run docker run ... -w /working-dir ..., the working directory will be /working-dir, and so Python will be looking for get_gene_length_filter.py in /working-dir, where it apparently is not found. Edit your shell script to refer to get_gene_length_filter.py by its full absolute path: python /evolinc_docker/get_gene_length_filter.py.

jwodder
  • 54,758
  • 12
  • 108
  • 124
  • I thought about it but for some reason never tried that way. Yes it worked and ended my misery. Thanks a lot for your tip.. – upendra Jan 11 '16 at 23:00
1

Your statement

the shell script reads a python script from the directory where the shell script is located.

is wrong.

In your shell script, when you call python get_gene_length_filter.py ,the get_gene_length_filter.py file is not assumed to be in the same directory as the shell script, but instead assumed to be in the current working directory.

To describe paths relative to the current shell script directory, use a variable set as follow:

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

and then you would call your python script with:

python $SCRIPT_DIR/get_gene_length_filter.py

This way, your shell script will work whatever the working directory is.

Community
  • 1
  • 1
Thomasleveil
  • 95,867
  • 15
  • 119
  • 113
  • Yes, now i realize that the python script is not actually in the same path as the shell script. Sure i use that – upendra Jan 11 '16 at 23:01
  • I copied the file into my script_dir which was /src, and it worked. Looks obvious, but didn't hit me. – Darpan Aug 14 '19 at 09:58