"""This directory is setup with configurations to run the main functional test.

It exercises a full analysis pipeline on a smaller subset of data.

Use 'install_required' mark to skip tests that cannot be run on Travis CI,
because they require installation of additional dependencies (e.g. GATK)
"""
import glob
import os
import subprocess

import pytest


@pytest.mark.speed3
@pytest.mark.xfail(reason='Multiplexing not supporting in latest versions', run=False)
def test_full_pipeline_with_multiplexing(install_test_files, data_dir, global_config):
    fc_dir = os.path.join(data_dir, os.pardir, '110106_FC70BUKAAXX')
    run_config = os.path.join(data_dir, 'run_info.yaml')
    subprocess.check_call(['bcbio_nextgen.py', global_config, fc_dir, run_config])


@pytest.mark.speed3
@pytest.mark.xfail(reason='Multiplexing not supporting in latest versions', run=False)
def test_handle_empty_fastq_inputs_from_failed_runs(install_test_files, data_dir, global_config):
    fc_dir = os.path.join(data_dir, os.pardir, '110221_empty_FC12345AAXX')
    run_config = os.path.join(data_dir, 'run_info-empty.yaml')
    subprocess.check_call(['bcbio_nextgen.py', global_config, fc_dir, run_config])


@pytest.mark.speed1
@pytest.mark.rnaseq
@pytest.mark.stranded
@pytest.mark.install_required
def test_stranded(install_test_files, data_dir, global_config):
    """Run an RNA-seq analysis with TopHat and generate gene-level counts"""
    fc_dir = os.path.join(data_dir, os.pardir, 'test_stranded')
    run_config = os.path.join(data_dir, 'run_info-stranded.yaml')
    subprocess.check_call(['bcbio_nextgen.py', global_config, fc_dir, run_config])


@pytest.mark.rnaseq
@pytest.mark.tophat
@pytest.mark.rnaseq_vc
@pytest.mark.install_required
@pytest.mark.skip(reason="tophat is no longer supported.")
def test_rnaseq_with_tophat(install_test_files, data_dir, global_config):
    fc_dir = os.path.join(data_dir, os.pardir, '110907_ERP000591')
    run_config = os.path.join(data_dir, 'run_info-rnaseq.yaml')
    subprocess.check_call(['bcbio_nextgen.py', global_config, fc_dir, run_config])


@pytest.mark.fusion
def test_rnaseq_fusion_genes(install_test_files, data_dir, global_config):
    fc_dir = os.path.join(data_dir, os.pardir, 'test_fusion')
    run_config = os.path.join(data_dir, 'run_info-fusion.yaml')
    subprocess.check_call(['bcbio_nextgen.py', global_config, fc_dir, run_config])


@pytest.mark.star
@pytest.mark.rnaseq
@pytest.mark.rnaseq_standard
def test_rnaseq_with_star(install_test_files, data_dir, global_config):
    fc_dir = os.path.join(data_dir, os.pardir, 'test_fusion')
    run_config = os.path.join(data_dir, 'run_info-star.yaml')
    subprocess.check_call(['bcbio_nextgen.py', global_config, fc_dir, run_config])


@pytest.mark.fastrnaseq
@pytest.mark.rnaseq
def test_fast_rnaseq(install_test_files, data_dir, global_config):
    fc_dir = os.path.join(data_dir, os.pardir, 'test_fusion')
    run_config = os.path.join(data_dir, 'run_info-fastrnaseq.yaml')
    subprocess.check_call(['bcbio_nextgen.py', global_config, fc_dir, run_config])


@pytest.mark.rnaseq
@pytest.mark.scrnaseq
def test_scrnaseq(install_test_files, data_dir, global_config):
    fc_dir = os.path.join(data_dir, os.pardir, 'Harvard-inDrop')
    run_config = os.path.join(data_dir, 'run_info-scrnaseq.yaml')
    subprocess.check_call(['bcbio_nextgen.py', global_config, fc_dir, run_config])


@pytest.mark.rnaseq
@pytest.mark.rnaseq_standard
@pytest.mark.hisat2
def test_rnaseq_with_hisat2(install_test_files, data_dir, global_config):
    fc_dir = os.path.join(data_dir, os.pardir, '110907_ERP000591')
    run_config = os.path.join(data_dir, 'run_info-hisat2.yaml')
    subprocess.check_call(['bcbio_nextgen.py', global_config, fc_dir, run_config])


@pytest.mark.rnaseq
@pytest.mark.singleend
@pytest.mark.explant
def test_explant_with_tophat(install_test_files, data_dir, global_config):
    fc_dir = os.path.join(data_dir, os.pardir, '1_explant')
    run_config = os.path.join(data_dir, 'run_info-explant.yaml')
    subprocess.check_call(['bcbio_nextgen.py', global_config, fc_dir, run_config])


@pytest.mark.srnaseq