FROM ubuntu:14.04

ENV PACKAGES make gcc wget libc6-dev zlib1g-dev ca-certificates xz-utils

RUN apt-get update --fix-missing -y && apt-get install -y --no-install-recommends ${PACKAGES}

RUN apt-get install python -y

RUN apt-get update --fix-missing

RUN apt-get install git -y

RUN apt-get install build-essential -y

# Locations for biobox file validator
ENV VALIDATOR /bbx/validator/
ENV BASE_URL https://s3-us-west-1.amazonaws.com/bioboxes-tools/validate-biobox-file
ENV VERSION  0.x.y
RUN mkdir -p ${VALIDATOR}

# download the validate-biobox-file binary and extract it to the directory $VALIDATOR
RUN wget \
      --quiet \
      --output-document -\
      ${BASE_URL}/${VERSION}/validate-biobox-file.tar.xz \
    | tar xJf - \
      --directory ${VALIDATOR} \
      --strip-components=1

ENV PATH ${PATH}:${VALIDATOR}

#ENV CONVERT https://github.com/bronze1man/yaml2json/raw/master/builds/linux_386/yaml2json
# download yaml2json and make it executable
#RUN cd /usr/local/bin && wget --quiet ${CONVERT} && chmod 700 yaml2json
ADD yaml2json /usr/local/bin
ENV JQ http://stedolan.github.io/jq/download/linux64/jq
# download jq and make it executable
RUN cd /usr/local/bin && wget --quiet ${JQ} && chmod 700 jq

# chmod so it can be run by non root
RUN chmod go+x /usr/local/bin/jq
#RUN chmod go+x /usr/local/bin/yaml2json

RUN wget https://bitbucket.org/biobakery/metaphlan2/get/default.zip

RUN apt-get install zip -y

RUN apt-get install bowtie2

RUN apt-get install -y python3-pip python-pip
RUN pip3 install --upgrade pip
RUN pip2 install --upgrade pip
RUN pip3 install numpy
RUN pip3 install scipy
RUN pip3 install pandas
RUN pip3 install ete3
RUN pip3 install biopython
RUN pip3 install dendropy
#RUN pip3 install matplotlib
RUN pip2 install biopython

WORKDIR /

RUN unzip /default.zip || true

RUN cp -r /biobakery-metaphlan2-* /metaphlan2

RUN ls -l /metaphlan2/utils

ENV MP2_DIR /metaphlan2

WORKDIR /metaphlan2

ENV PATH ${PATH}:${VALIDATOR}:$MP2_DIR

RUN pip2 install -Iv https://pypi.python.org/packages/source/b/biom-format/biom-format-1.3.0.tar.gz


RUN ls /metaphlan2 -lhtr

ADD fake.fastq .

RUN python metaphlan2.py fake.fastq --input_type fastq || true

RUN python3 -c "from ete3 import NCBITaxa;NCBITaxa();"
RUN cp -r /root/.etetoolkit /.etetoolkit
RUN rm -r /root/.etetoolkit
RUN chmod 777 /.etetoolkit -R

# Add Taskfile to /
ADD Taskfile /
# Add schema
ADD schema.yaml /
# Add python code
ADD prepare_results.py /

# Add assemble script to the directory /usr/local/bin inside the container.
# /usr/local/bin is appended to the $PATH variable what means that every script
# in that directory will be executed in the shell  without providing the path.
ADD entry /usr/local/bin/

WORKDIR /bbx/tmp

ENTRYPOINT ["entry"]
