# Path: ob_pipelines/s3.py
# SCRATCH_DIR = os.environ.get('SCRATCH_DIR') or '/tmp'
# def csv_to_s3(df, s3_path, **kwargs):
# def create_tmp_from_key(key): 
# def path_to_bucket_and_key(path):
# def key_exists(bucket, key):
# def download_folder(bucket, prefix, folder):
# def upload_folder(folder, bucket, prefix):
# def upload_prefix(local_prefix, s3_prefix, fpath_templates):
# def download_file_or_folder(s3_path, local_path):
# def upload_file_or_folder(s3_path, local_path):
# def remove_file_or_folder(fpath):
# def swap_args(args, rm_local_outpath=False):
# def s3args(rm_local_outpath=False):
#     def s3args_decorator(f):
#         def local_fn(*args, **kwargs):
# def s3wrap():
#     def sync_and_run(*cmds):


import os.path as op
import logging
import shutil
import click
from subprocess import check_output
from tempfile import mkdtemp
from ob_pipelines.s3 import (
    s3, download_file_or_folder, remove_file_or_folder, SCRATCH_DIR, path_to_bucket_and_key
)



logger = logging.getLogger('ob-pipelines')


@click.command()
@click.argument('fq1')
@click.argument('fq2')
@click.argument('out_dir')
@click.argument('name')
def fastqc(fq1, fq2, out_dir, name):
    """Run FastQC"""

    out_dir = out_dir if out_dir.endswith('/') else out_dir + '/'

    temp_dir = mkdtemp(dir=SCRATCH_DIR)
    fq1_local = op.join(temp_dir, name + '_1.fastq.gz')
    fq2_local = op.join(temp_dir, name + '_2.fastq.gz')

    if fq1.startswith('s3://'):
        # Assume that if fq1 is in S3, so is fq2
        download_file_or_folder(fq1, fq1_local)

# Path: ob_pipelines/s3.py
# SCRATCH_DIR = os.environ.get('SCRATCH_DIR') or '/tmp'
# def csv_to_s3(df, s3_path, **kwargs):
# def create_tmp_from_key(key): 
# def path_to_bucket_and_key(path):
# def key_exists(bucket, key):
# def download_folder(bucket, prefix, folder):
# def upload_folder(folder, bucket, prefix):
# def upload_prefix(local_prefix, s3_prefix, fpath_templates):
# def download_file_or_folder(s3_path, local_path):
# def upload_file_or_folder(s3_path, local_path):
# def remove_file_or_folder(fpath):
# def swap_args(args, rm_local_outpath=False):
# def s3args(rm_local_outpath=False):
#     def s3args_decorator(f):
#         def local_fn(*args, **kwargs):
# def s3wrap():
#     def sync_and_run(*cmds):


# Path: ob_pipelines/apps/fastqc/fastqc.py
import os.path as op
import logging
import shutil
import click
from subprocess import check_output
from tempfile import mkdtemp
from ob_pipelines.s3 import (
    s3, download_file_or_folder, remove_file_or_folder, SCRATCH_DIR, path_to_bucket_and_key
)




logger = logging.getLogger('ob-pipelines')


@click.command()
@click.argument('fq1')
@click.argument('fq2')
@click.argument('out_dir')
@click.argument('name')
def fastqc(fq1, fq2, out_dir, name):
    """Run FastQC"""

    out_dir = out_dir if out_dir.endswith('/') else out_dir + '/'

    temp_dir = mkdtemp(dir=SCRATCH_DIR)
    fq1_local = op.join(temp_dir, name + '_1.fastq.gz')
    fq2_local = op.join(temp_dir, name + '_2.fastq.gz')

    if fq1.startswith('s3://'):
        # Assume that if fq1 is in S3, so is fq2
        download_file_or_folder(fq1, fq1_local)

        download_file_or_folder(fq2, fq2_local)