before_install:
  - if test -e $HOME/miniconda/bin; then
      echo "miniconda already installed.";
      export PATH="$HOME/miniconda/bin:$PATH";
    else
      if [[ "$TRAVIS_PYTHON_VERSION" == "2.7" ]]; then
        wget https://repo.continuum.io/miniconda/Miniconda2-latest-Linux-x86_64.sh -O miniconda.sh;
      else
        wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh;
      fi;

      rm -rf $HOME/miniconda;
      bash miniconda.sh -b -p $HOME/miniconda;
      export PATH="$HOME/miniconda/bin:$PATH";
      hash -r;

      conda config --add channels defaults;
      conda config --add channels bioconda;
      conda config --add channels conda-forge;

      conda config --set always_yes yes --set changeps1 no;

      conda update -q -n base conda;

      conda info -a;
    fi

  - export TEST_ENV="test";

  - if test -e $HOME/miniconda/envs/$TEST_ENV/lib/R/library/reticulate; then
      echo "test env already created.";
    else
      conda config --add channels defaults;
      conda config --add channels bioconda;
      conda config --add channels conda-forge;
      conda create -q -y -n $TEST_ENV r-reticulate anndata loompy;
      conda install -q -y -n $TEST_ENV bioconductor-singlecellexperiment bioconductor-loomexperiment r-seurat=4 "r-deldir>=1.0.2" r-monocle3;
    fi;

install:
  - source activate "$TEST_ENV"
  - R CMD INSTALL .

before_script:
  - mkdir -p data
  - wget http://seurat.nygenome.org/src/contrib/pbmc3k.SeuratData_3.1.4.tar.gz
  - tar xzvf pbmc3k.SeuratData_3.1.4.tar.gz

script:
  - Rscript -e 'load("pbmc3k.SeuratData/data/pbmc3k.rda")'
            -e 'library(sceasy)'
            -e 'srt <- pbmc3k'
            -e 'dir.create("data")'
            -e 'sceasy::convertFormat(srt, from="seurat", to="anndata", outFile="data/pbmc3k_seurat_anndata.h5ad")'
            -e 'sce <- sceasy::convertFormat(srt, from="seurat", to="sce", outFile="data/pbmc3k_seurat_sce.rds")'
            -e 'sceasy::convertFormat(sce, from="sce", to="anndata", outFile="data/pbmc3k_seurat_sce_anndata.h5ad")'
            -e 'sceasy::convertFormat("data/pbmc3k_seurat_anndata.h5ad", from="anndata", to="cds", outFile="data/pbmc3k_seurat_anndata_cds.rds")'
            -e 'sceasy::convertFormat(sce, from="sce", to="loom", outFile="data/pbmc3k_seurat_sce_loom.loom")'
            -e 'sceasy::convertFormat("data/pbmc3k_seurat_sce_loom.loom", from="loom", to="anndata", outFile="data/pbmc3k_seurat_sce_loom_anndata.h5ad")'
            -e 'sceasy::convertFormat("data/pbmc3k_seurat_sce_loom.loom", from="loom", to="sce", outFile="data/pbmc3k_seurat_sce_loom_sce.rds", main_layer_name="scaled")'

cache:
  directories:
    - $HOME/miniconda

before_cache:
  - if ! [[ $TRAVIS_TAG ]]; then rm -rf $HOME/miniconda/conda-bld; fi
  - Rscript -e 'remove.packages("sceasy")'
  - rm -rf $HOME/miniconda/locks $HOME/miniconda/pkgs $HOME/miniconda/var $HOME/miniconda/conda-meta/history
