# Path: ratatosk/config.py
# def get_config():
#     return RatatoskConfigParser.instance()
# 
# def get_custom_config():
#     """Get separate parser for custom config; else custom config
#     parent_task setting will override config file settings"""
#     return RatatoskCustomConfigParser.instance()


import os
import re
import unittest
import luigi
import logging
import ratatosk.lib.files.fastq
import ratatosk.lib.tools.samtools
import ratatosk.lib.tools.picard
import ratatosk.lib.tools.gatk
import ratatosk.lib.tools.fastqc
import ratatosk.lib.utils.cutadapt
import ratatosk.lib.utils.misc
import ratatosk.lib.annotation.snpeff
import ratatosk.lib.annotation.annovar
import ratatosk.lib.align.bwa
        import ratatosk.lib.variation.htslib
        import ratatosk.lib.variation.tabix
from luigi.mock import MockFile
from ratatosk.config import get_config, get_custom_config

sai1 = os.path.join(indir, sample + read1_suffix + ".sai")
sai2 = os.path.join(indir, sample + read2_suffix + ".sai")

sam = os.path.join(indir, sample + ".sam")
bam = os.path.join(indir, sample + ".bam")
sortbam = os.path.join(indir, sample + ".sort.bam")

localconf = "pipeconf.yaml"
local_scheduler = '--local-scheduler'
process = os.popen("ps x -o pid,args | grep ratatoskd | grep -v grep").read() #sometimes have to use grep -v grep

if process:
    local_scheduler = None

def _luigi_args(args):
    if local_scheduler:
        return [local_scheduler] + args
    return args

def _prune_luigi_tmp(args):
    """Remove luigi tmp string from file names"""
    return [re.sub(r'-luigi-tmp-[0-9]+(\.gz)?', '', x) for x in args]

def setUpModule():
    global cnf, custom_cnf
    cnf = get_config()
    cnf.clear()
    cnf.add_config_path(os.path.join(os.path.dirname(__file__), os.pardir, "config", "ratatosk.yaml"))
    cnf.add_config_path(localconf)

# Path: ratatosk/config.py
# def get_config():
#     return RatatoskConfigParser.instance()
# 
# def get_custom_config():
#     """Get separate parser for custom config; else custom config
#     parent_task setting will override config file settings"""
#     return RatatoskCustomConfigParser.instance()


# Path: test/test_wrapper.py
import os
import re
import unittest
import luigi
import logging
import ratatosk.lib.files.fastq
import ratatosk.lib.tools.samtools
import ratatosk.lib.tools.picard
import ratatosk.lib.tools.gatk
import ratatosk.lib.tools.fastqc
import ratatosk.lib.utils.cutadapt
import ratatosk.lib.utils.misc
import ratatosk.lib.annotation.snpeff
import ratatosk.lib.annotation.annovar
import ratatosk.lib.align.bwa
        import ratatosk.lib.variation.htslib
        import ratatosk.lib.variation.tabix
from luigi.mock import MockFile
from ratatosk.config import get_config, get_custom_config


sai1 = os.path.join(indir, sample + read1_suffix + ".sai")
sai2 = os.path.join(indir, sample + read2_suffix + ".sai")

sam = os.path.join(indir, sample + ".sam")
bam = os.path.join(indir, sample + ".bam")
sortbam = os.path.join(indir, sample + ".sort.bam")

localconf = "pipeconf.yaml"
local_scheduler = '--local-scheduler'
process = os.popen("ps x -o pid,args | grep ratatoskd | grep -v grep").read() #sometimes have to use grep -v grep

if process:
    local_scheduler = None

def _luigi_args(args):
    if local_scheduler:
        return [local_scheduler] + args
    return args

def _prune_luigi_tmp(args):
    """Remove luigi tmp string from file names"""
    return [re.sub(r'-luigi-tmp-[0-9]+(\.gz)?', '', x) for x in args]

def setUpModule():
    global cnf, custom_cnf
    cnf = get_config()
    cnf.clear()
    cnf.add_config_path(os.path.join(os.path.dirname(__file__), os.pardir, "config", "ratatosk.yaml"))
    cnf.add_config_path(localconf)

    custom_cnf = get_custom_config()