# Path: snakemakelib/bio/ngs/regexp.py
# class ReadGroup(RunRegexp):
#     """Adds formatting function for generating read group option string"""
#     _group_keys = ['ID', 'CN', 'DS', 'DT', 'FO', 'KS',
#                    'LB', 'PG', 'PI', 'PL', 'PU', 'SM']
#     _extra_keys = ['PATH']
#     _group_dict = {'ID': 'identifier', 'CN': 'center', 'DS': 'description',
#                    'DT': 'date', 'FO': 'floworder', 'KS': 'keysequence',
#                    'LB': 'library', 'PG': 'program', 'PI': 'insertsize',
#                    'PL': 'platform', 'PU': 'platform-unit', 'SM': 'sample'}
# 
#     def __init__(self, regexp=None, opt_prefix="--", *args, **kwargs):
#         super(ReadGroup, self).__init__(regexp, *args, **kwargs)
#         self._opt_prefix = opt_prefix
# 
#     def _post_process_keys(self, m):
#         self['PATH'] = os.path.dirname(m.string)
#         if 'ID' not in self.keys() or not self.get('ID', ""):
#             # inv_map = {v: k for (k, v) in list(self.re.groupindex.items())}
#             self['ID'] = os.path.basename(self.fmt.format(**self))
# 
#     def _fmt_string(self, k):
#         """Take care of date string"""
#         if k == 'DT':
#             return isoformat(self[k])
#         return self[k]
# 
#     def __str__(self):
#         """Return a generic program string"""
#         return " ".join([
#             "{dash}{key} {value}".format(dash=self._opt_prefix,
#                                          key=self._group_dict[k],
#                                          value=self._fmt_string(k))
#             for k in sorted(list(self.keys())) if not self[k] is None
#             and k in self._group_keys])


from snakemakelib.bio.ngs.regexp import ReadGroup
# Copyright (C) 2015 by Per Unneberg

# From tophat2:
# --rg-id                        <string>    (read group ID)
# --rg-sample                    <string>    (sample ID)
# --rg-library                   <string>    (library ID)
# --rg-description               <string>    (descriptive string, no tabs allowed)
# --rg-platform-unit             <string>    (e.g Illumina lane ID)
# --rg-center                    <string>    (sequencing center name)
# --rg-date                      <string>    (ISO 8601 date of the sequencing run)
# --rg-platform                  <string>    (Sequencing platform descriptor)

class TuxedoReadGroup(ReadGroup):
    _group_dict = {'ID' : 'id', 'CN' : 'center',
                   'DS' : 'description', 'DT' : 'date',
                   'FO' : 'floworder', 'KS' : 'keysequence',
                   'LB' : 'library', 'PG' : 'program',
                   'PI' : 'insertsize', 'PL': 'platform',
                   'PU' : 'platform-unit', 'SM' : 'sample'}

    def __init__(self, opt_prefix="--rg-", *args, **kwargs):

# Path: snakemakelib/bio/ngs/regexp.py
# class ReadGroup(RunRegexp):
#     """Adds formatting function for generating read group option string"""
#     _group_keys = ['ID', 'CN', 'DS', 'DT', 'FO', 'KS',
#                    'LB', 'PG', 'PI', 'PL', 'PU', 'SM']
#     _extra_keys = ['PATH']
#     _group_dict = {'ID': 'identifier', 'CN': 'center', 'DS': 'description',
#                    'DT': 'date', 'FO': 'floworder', 'KS': 'keysequence',
#                    'LB': 'library', 'PG': 'program', 'PI': 'insertsize',
#                    'PL': 'platform', 'PU': 'platform-unit', 'SM': 'sample'}
# 
#     def __init__(self, regexp=None, opt_prefix="--", *args, **kwargs):
#         super(ReadGroup, self).__init__(regexp, *args, **kwargs)
#         self._opt_prefix = opt_prefix
# 
#     def _post_process_keys(self, m):
#         self['PATH'] = os.path.dirname(m.string)
#         if 'ID' not in self.keys() or not self.get('ID', ""):
#             # inv_map = {v: k for (k, v) in list(self.re.groupindex.items())}
#             self['ID'] = os.path.basename(self.fmt.format(**self))
# 
#     def _fmt_string(self, k):
#         """Take care of date string"""
#         if k == 'DT':
#             return isoformat(self[k])
#         return self[k]
# 
#     def __str__(self):
#         """Return a generic program string"""
#         return " ".join([
#             "{dash}{key} {value}".format(dash=self._opt_prefix,
#                                          key=self._group_dict[k],
#                                          value=self._fmt_string(k))
#             for k in sorted(list(self.keys())) if not self[k] is None
#             and k in self._group_keys])


# Path: snakemakelib/bio/ngs/rnaseq/tuxedo.py
from snakemakelib.bio.ngs.regexp import ReadGroup

# Copyright (C) 2015 by Per Unneberg

# From tophat2:
# --rg-id                        <string>    (read group ID)
# --rg-sample                    <string>    (sample ID)
# --rg-library                   <string>    (library ID)
# --rg-description               <string>    (descriptive string, no tabs allowed)
# --rg-platform-unit             <string>    (e.g Illumina lane ID)
# --rg-center                    <string>    (sequencing center name)
# --rg-date                      <string>    (ISO 8601 date of the sequencing run)
# --rg-platform                  <string>    (Sequencing platform descriptor)

class TuxedoReadGroup(ReadGroup):
    _group_dict = {'ID' : 'id', 'CN' : 'center',
                   'DS' : 'description', 'DT' : 'date',
                   'FO' : 'floworder', 'KS' : 'keysequence',
                   'LB' : 'library', 'PG' : 'program',
                   'PI' : 'insertsize', 'PL': 'platform',
                   'PU' : 'platform-unit', 'SM' : 'sample'}

    def __init__(self, opt_prefix="--rg-", *args, **kwargs):

        ReadGroup.__init__(self, *args, **kwargs)