# Path: bipy/toolbox/rseqc.py
# def program_exists(path):
# def _results_dir(config, prefix=""):
#     def _make_dir(base):
# def _fetch_chrom_sizes(config):
# def bam2bigwig(in_file, config, out_prefix=None):
# def wig2bigwig(wiggle_file, chrom_size_file, out_file):
# def bam_stat(in_file, config, out_prefix=None):
# def clipping_profile(in_file, config, out_prefix=None):
# def genebody_coverage(in_file, config, out_prefix=None):
# def genebody_coverage2(in_file, config, out_prefix=None):
# def junction_annotation(in_file, config, out_prefix=None):
# def junction_saturation(in_file, config, out_prefix=None):
# def RPKM_count(in_file, config, out_prefix=None):
# def merge_RPKM(in_dir):
# def fix_RPKM_count_file(in_file, out_file=None):
# def RPKM_saturation(in_file, config, out_prefix=None):
# def _get_out_dir(in_file, config, out_prefix, prefix):
# def _get_out_prefix(in_file, config, out_prefix, prefix):
# def _get_gtf(config):
# def _gtf2bed(gtf):
#     def __init__(self, base_dir):
#     def get_rseqc_graphs(self):
#     def __init__(self):
#     def template(self):
#     def _add_captions(self, figures):
#     def clean_figures(self, figures):
#     def generate_report(self, name, figures=None):
#     def __init__(self, config):
#     def out_file(self, in_file):
#     def __call__(self, in_file):
#     PROGRAM = "fetchChromSizes"
#     PROGRAM = "bam2wig.py"
#     PROGRAM = "wigToBigWig"
#     PROGRAM = "bam_stat.py"
#     PROGRAM = "clipping_profile.py"
#     PROGRAM = "geneBody_coverage.py"
#     PROGRAM = "geneBody_coverage2.py"
#     PROGRAM = "junction_annotation.py"
#     PROGRAM = "junction_saturation.py"
#     PROGRAM = "RPKM_count.py"
#     HEADER = ["chrom", "st", "end", "accession" "score",
#               "gene_strand", "tag_count", "RPKM"]
#     NAME_COL = 3
#     HEADER_START = 0
#     HEADER_END = 5
#     RPKM_COLUMN = 6
#     COUNT_COLUMN = 5
#     PROGRAM = "RPKM_saturation.py"
#     DIRS = ["bam_sta", "clipping", "coverage", "junction",
#             "saturation", "RPKM_count", "RPKM_saturation"]
#     GRAPHS = ((os.path.join("RPKM_saturation", "RPKM_saturation.pdf"),
#                "", 1.0),
#               (os.path.join("clipping", "clipping.pdf"), "", 1.0),
#               (os.path.join("coverage", "coverage.geneBodyCoverage.pdf"),
#                "", 1.0),
#               (os.path.join("saturation", "junction_saturation.pdf"),
#                "", 1.0),
#               (os.path.join("junction", "junction.splice_junction.pdf"),
#                "", 1.0))
#     INFO = (os.path.join("bam_stat", "bam_stat.txt"),
#             os.path.join("RPKM_count", "RPKM_count.txt"))
#     CAPTIONS = {"RPKM_saturation.pdf": "",
#                 "coverage.geneBodyCoverage.pdf": "",
#                 "clipping.pdf": "",
#                 "coverage.pdf": "",
#                 "junction_saturation.pdf": "",
#                 "splice_events.pdf": ""}
# class RseqcParser(object):
# class RseqcReport(LatexReport):
# class RNASeqMetrics(AbstractStage):
# 
# Path: bipy/toolbox/reporting.py
# def safe_latex(to_fix):
#     def generate_pdf(self, sections=None, out_file=None):
#     def template(self):
#     def generate_report(self, *args, **kwargs):
# def make_latex_table_header(length):
# def panda_to_latex(table, caption=""):
#     def _panda_row_to_latex_row(row):
# class LatexPdf(object):
# class LatexReport(object):


import yaml
import unittest
import os
from bipy.toolbox import rseqc
from bcbio.utils import safe_makedir, file_exists
from bipy.toolbox import reporting

class TestRseqc(unittest.TestCase):

    def setUp(self):
        self.config_file = os.path.join("test", STAGENAME,
                                        "test_" + STAGENAME + ".yaml")
        with open(self.config_file) as in_handle:
            self.config = yaml.load(in_handle)

        self.input_file = self.config["input"]
        self.gtf = self.config["annotation"]["file"]
        self.stage_config = self.config["stage"][STAGENAME]

    ## def test_documentation(self):
    ##     self.test_genebody_coverage()
    ##     self.test_RPKM_saturation()
    ##     base_file = os.path.basename(self.config["input"])
    ##     base_dir = os.path.join(self.config["dir"]["results"],
    ##                             "rseqc",
    ##                             base_file)
    ##     parser = rseqc.RseqcParser(base_dir)
    ##     figures = parser.get_rseqc_graphs()
    ##     report = rseqc.RseqcReport()
    ##     section = report.generate_report(base_file, figures)
    ##     print section
    ##     out_file = os.path.join(base_dir, "rseqc_report.pdf")
    ##     reporting.LatexPdf.generate_pdf([section], out_file)
    ##     self.assertTrue(file_exists(out_file))

    def test_bam2bigwig(self):

# Path: bipy/toolbox/rseqc.py
# def program_exists(path):
# def _results_dir(config, prefix=""):
#     def _make_dir(base):
# def _fetch_chrom_sizes(config):
# def bam2bigwig(in_file, config, out_prefix=None):
# def wig2bigwig(wiggle_file, chrom_size_file, out_file):
# def bam_stat(in_file, config, out_prefix=None):
# def clipping_profile(in_file, config, out_prefix=None):
# def genebody_coverage(in_file, config, out_prefix=None):
# def genebody_coverage2(in_file, config, out_prefix=None):
# def junction_annotation(in_file, config, out_prefix=None):
# def junction_saturation(in_file, config, out_prefix=None):
# def RPKM_count(in_file, config, out_prefix=None):
# def merge_RPKM(in_dir):
# def fix_RPKM_count_file(in_file, out_file=None):
# def RPKM_saturation(in_file, config, out_prefix=None):
# def _get_out_dir(in_file, config, out_prefix, prefix):
# def _get_out_prefix(in_file, config, out_prefix, prefix):
# def _get_gtf(config):
# def _gtf2bed(gtf):
#     def __init__(self, base_dir):
#     def get_rseqc_graphs(self):
#     def __init__(self):
#     def template(self):
#     def _add_captions(self, figures):
#     def clean_figures(self, figures):
#     def generate_report(self, name, figures=None):
#     def __init__(self, config):
#     def out_file(self, in_file):
#     def __call__(self, in_file):
#     PROGRAM = "fetchChromSizes"
#     PROGRAM = "bam2wig.py"
#     PROGRAM = "wigToBigWig"
#     PROGRAM = "bam_stat.py"
#     PROGRAM = "clipping_profile.py"
#     PROGRAM = "geneBody_coverage.py"
#     PROGRAM = "geneBody_coverage2.py"
#     PROGRAM = "junction_annotation.py"
#     PROGRAM = "junction_saturation.py"
#     PROGRAM = "RPKM_count.py"
#     HEADER = ["chrom", "st", "end", "accession" "score",
#               "gene_strand", "tag_count", "RPKM"]
#     NAME_COL = 3
#     HEADER_START = 0
#     HEADER_END = 5
#     RPKM_COLUMN = 6
#     COUNT_COLUMN = 5
#     PROGRAM = "RPKM_saturation.py"
#     DIRS = ["bam_sta", "clipping", "coverage", "junction",
#             "saturation", "RPKM_count", "RPKM_saturation"]
#     GRAPHS = ((os.path.join("RPKM_saturation", "RPKM_saturation.pdf"),
#                "", 1.0),
#               (os.path.join("clipping", "clipping.pdf"), "", 1.0),
#               (os.path.join("coverage", "coverage.geneBodyCoverage.pdf"),
#                "", 1.0),
#               (os.path.join("saturation", "junction_saturation.pdf"),
#                "", 1.0),
#               (os.path.join("junction", "junction.splice_junction.pdf"),
#                "", 1.0))
#     INFO = (os.path.join("bam_stat", "bam_stat.txt"),
#             os.path.join("RPKM_count", "RPKM_count.txt"))
#     CAPTIONS = {"RPKM_saturation.pdf": "",
#                 "coverage.geneBodyCoverage.pdf": "",
#                 "clipping.pdf": "",
#                 "coverage.pdf": "",
#                 "junction_saturation.pdf": "",
#                 "splice_events.pdf": ""}
# class RseqcParser(object):
# class RseqcReport(LatexReport):
# class RNASeqMetrics(AbstractStage):
# 
# Path: bipy/toolbox/reporting.py
# def safe_latex(to_fix):
#     def generate_pdf(self, sections=None, out_file=None):
#     def template(self):
#     def generate_report(self, *args, **kwargs):
# def make_latex_table_header(length):
# def panda_to_latex(table, caption=""):
#     def _panda_row_to_latex_row(row):
# class LatexPdf(object):
# class LatexReport(object):


# Path: test/rseqc/test_rseqc.py
import yaml
import unittest
import os
from bipy.toolbox import rseqc
from bcbio.utils import safe_makedir, file_exists
from bipy.toolbox import reporting


class TestRseqc(unittest.TestCase):

    def setUp(self):
        self.config_file = os.path.join("test", STAGENAME,
                                        "test_" + STAGENAME + ".yaml")
        with open(self.config_file) as in_handle:
            self.config = yaml.load(in_handle)

        self.input_file = self.config["input"]
        self.gtf = self.config["annotation"]["file"]
        self.stage_config = self.config["stage"][STAGENAME]

    ## def test_documentation(self):
    ##     self.test_genebody_coverage()
    ##     self.test_RPKM_saturation()
    ##     base_file = os.path.basename(self.config["input"])
    ##     base_dir = os.path.join(self.config["dir"]["results"],
    ##                             "rseqc",
    ##                             base_file)
    ##     parser = rseqc.RseqcParser(base_dir)
    ##     figures = parser.get_rseqc_graphs()
    ##     report = rseqc.RseqcReport()
    ##     section = report.generate_report(base_file, figures)
    ##     print section
    ##     out_file = os.path.join(base_dir, "rseqc_report.pdf")
    ##     reporting.LatexPdf.generate_pdf([section], out_file)
    ##     self.assertTrue(file_exists(out_file))

    def test_bam2bigwig(self):

        out_file = rseqc.bam2bigwig(self.input_file, self.config)