# Path: ratatosk/job.py
# class JobTask(BaseJobTask):
#     def job_runner(self):
#         return DefaultShellJobRunner()
# 
#     def args(self):
#         return []
# 
# Path: ratatosk/log.py
# def get_logger():
#     logger = logging.getLogger('ratatosk-interface')
#     if not logger.handlers:
#         setup_logging()
#     return logger
# 
# Path: ratatosk/report/utils.py
# def group_samples(samples, grouping="sample"):
#     """Group samples by sample or sample run.
# 
#     :param samples: list of :class:`ISample <ratatosk.experiment.ISample>` objects
#     :param grouping: what to group by
# 
#     :returns: dictionary of grouped items
#     """
#     groups = OrderedDict()
#     if grouping == "sample":
#         for k,g in itertools.groupby(samples, key=lambda x:x.sample_id()):
#             groups[k] = list(g)
#     elif grouping == "samplerun":
#         for k,g in itertools.groupby(samples, key=lambda x:x.prefix("samplerun")):
#             groups[k] = list(g)
#     return groups


import os
import luigi
import re
import texttable as tt
import cPickle as pickle
from mako.template import Template
from ratatosk.job import JobTask
from ratatosk.log import get_logger
from ratatosk.report.utils import group_samples
    'pickled_samples':None,
    }

def make_rst_table(data):
    """Make rst table with :py:mod:`Texttable`"""
    if data is None:
        return ""
    else:
        tab_tt = tt.Texttable()
        tab_tt.set_precision(2)
        tab_tt.add_rows(data)
        return tab_tt.draw()

class SphinxReport(JobTask):
    """Make sphinx report"""
    indir = luigi.Parameter(description="Analysis input directory", default=None)
    outdir = luigi.Parameter(description="Documentation directory", default="doc")
    sample = luigi.Parameter(default=[], description="Samples to process.", is_list=True)
    flowcell = luigi.Parameter(default=[], description="Flowcells to process.", is_list=True)
    lane = luigi.Parameter(default=[], description="Lanes to process.", is_list=True)
    # Add metrics types and parameters to be parsed here here
    samples = []
    
    def _setup(self):
        kw['docroot'] = self.outdir
        # List requirements for completion, consisting of classes above
        if self.indir is None:
            logger.error("Need input directory to run")
            self.targets = []
        self.samples = sorted([tgt for tgt in self.target_iterator()], key=lambda x:x.sample_id())

# Path: ratatosk/job.py
# class JobTask(BaseJobTask):
#     def job_runner(self):
#         return DefaultShellJobRunner()
# 
#     def args(self):
#         return []
# 
# Path: ratatosk/log.py
# def get_logger():
#     logger = logging.getLogger('ratatosk-interface')
#     if not logger.handlers:
#         setup_logging()
#     return logger
# 
# Path: ratatosk/report/utils.py
# def group_samples(samples, grouping="sample"):
#     """Group samples by sample or sample run.
# 
#     :param samples: list of :class:`ISample <ratatosk.experiment.ISample>` objects
#     :param grouping: what to group by
# 
#     :returns: dictionary of grouped items
#     """
#     groups = OrderedDict()
#     if grouping == "sample":
#         for k,g in itertools.groupby(samples, key=lambda x:x.sample_id()):
#             groups[k] = list(g)
#     elif grouping == "samplerun":
#         for k,g in itertools.groupby(samples, key=lambda x:x.prefix("samplerun")):
#             groups[k] = list(g)
#     return groups


# Path: ratatosk/report/sphinx.py
import os
import luigi
import re
import texttable as tt
import cPickle as pickle
from mako.template import Template
from ratatosk.job import JobTask
from ratatosk.log import get_logger
from ratatosk.report.utils import group_samples

    'pickled_samples':None,
    }

def make_rst_table(data):
    """Make rst table with :py:mod:`Texttable`"""
    if data is None:
        return ""
    else:
        tab_tt = tt.Texttable()
        tab_tt.set_precision(2)
        tab_tt.add_rows(data)
        return tab_tt.draw()

class SphinxReport(JobTask):
    """Make sphinx report"""
    indir = luigi.Parameter(description="Analysis input directory", default=None)
    outdir = luigi.Parameter(description="Documentation directory", default="doc")
    sample = luigi.Parameter(default=[], description="Samples to process.", is_list=True)
    flowcell = luigi.Parameter(default=[], description="Flowcells to process.", is_list=True)
    lane = luigi.Parameter(default=[], description="Lanes to process.", is_list=True)
    # Add metrics types and parameters to be parsed here here
    samples = []
    
    def _setup(self):
        kw['docroot'] = self.outdir
        # List requirements for completion, consisting of classes above
        if self.indir is None:
            logger.error("Need input directory to run")
            self.targets = []
        self.samples = sorted([tgt for tgt in self.target_iterator()], key=lambda x:x.sample_id())

        grouped_samples = group_samples(self.samples)