# Path: egasub/submission/submittable/base.py
# class Analysis(Submittable):
#     __metaclass__ = ABCMeta
# 
#     def __init__(self, path):
#         super(Analysis, self).__init__(path)
# 
#         try:
#             self._parse_meta()
# 
#             self._sample = Sample.from_dict(self.metadata.get('sample'))
#             self.restore_latest_object_status('sample')
# 
#             self._analysis = EAnalysis.from_dict(self.metadata.get('analysis'))
#             self.restore_latest_object_status('analysis')
# 
#             self._analysis.files = [EFile.from_dict(file_) for file_ in self.metadata.get('files')]
# 
#             # not sure for what reason, EGA validation expect to have at least one attribute
#             self.analysis.attributes = [
#                 Attribute('_submitted_using', 'egasub %s' % ver)
#             ]
#         except Exception, err:
#             raise Exception("Can not create submission from this directory: %s. Please verify it's content. Error: %s" % (self._path, err))
# 
# 
#     @property
#     def status(self):
#         if self.analysis.status:
#             return self.analysis.status
#         else:
#             return 'NEW'  # hardcoded for now
# 
#     @property
#     def type(self):
#         return self.__class__.__bases__[0].__name__.lower()
# 
#     @property
#     def files(self):
#         return self.analysis.files
# 
#     @property
#     def sample(self):
#         return self._sample
# 
#     @property
#     def analysis(self):
#         return self._analysis
# 
#     def local_validate(self, ega_enums):
#         super(Analysis, self).local_validate(ega_enums)
# 
#         # Reference genomes type validation
#         if not any(cc['tag'] == str(self.analysis.genome_id) for cc in ega_enums.lookup("reference_genomes")):
#             self._add_local_validation_error("analysis",self.analysis.alias,"genomeId","Invalid value '%s'" % self.analysis.genome_id)
# 
#         # experimentTypeId type validation
#         if not isinstance(self.analysis.experiment_type_id, list):
#             self._add_local_validation_error("analysis",self.analysis.alias,"experimentTypes","Invalid value: experimentTypeId must be a list.")
# 
#         for e_type in self.analysis.experiment_type_id:
#             if not any(cc['tag'] == str(e_type) for cc in ega_enums.lookup("experiment_types")):
#                 self._add_local_validation_error("analysis",self.analysis.alias,"experimentTypes","Invalid value '%s' in experimentTypeId." % e_type)
# 
#         # Analysis titile validation
#         if not self.analysis.title:
#             self._add_local_validation_error("analysis",self.analysis.alias,"title","Invalid value: analysis title must be provided.")
# 
#         # Analysis description validation
#         if not self.analysis.description:
#             self._add_local_validation_error("analysis",self.analysis.alias,"description","Invalid value: analysis description must be provided.")
# 
#         # Chromosome references validation
#         # for some reason EGA only excepts this for variant file submission, not alignment
#         # but let's put it here, so it's required for both
#         if not isinstance(self.analysis.chromosome_references, list):
#             self._add_local_validation_error("analysis",self.analysis.alias,"chromosomeReferences","Invalid value: chromosomeReferences must be a list.")
# 
#         for chr_ref in self.analysis.chromosome_references:
#             if not any(cc['tag'] == str(chr_ref.value) for cc in ega_enums.lookup("reference_chromosomes")):
#                 self._add_local_validation_error("analysis",self.analysis.alias,"chromosomeReferences","Invalid value '%s' in chromosomeReferences" % chr_ref.value)


import re
from .base import Analysis


class Alignment(Analysis):
    def __init__(self, path):
        super(Alignment, self).__init__(path)

        if not re.match(r'^[a-zA-Z0-9_\-]+(\.[a-zA-Z0-9_\-]+){0,1}$', self.submission_dir):
            raise Exception("Submission directory should be named as <sample alias> or <sample alias>.<lane label>, sample alias and lane label may only contain letter, digit, underscore (_) or dash (-)")


    def local_validate(self, ega_enums):

# Path: egasub/submission/submittable/base.py
# class Analysis(Submittable):
#     __metaclass__ = ABCMeta
# 
#     def __init__(self, path):
#         super(Analysis, self).__init__(path)
# 
#         try:
#             self._parse_meta()
# 
#             self._sample = Sample.from_dict(self.metadata.get('sample'))
#             self.restore_latest_object_status('sample')
# 
#             self._analysis = EAnalysis.from_dict(self.metadata.get('analysis'))
#             self.restore_latest_object_status('analysis')
# 
#             self._analysis.files = [EFile.from_dict(file_) for file_ in self.metadata.get('files')]
# 
#             # not sure for what reason, EGA validation expect to have at least one attribute
#             self.analysis.attributes = [
#                 Attribute('_submitted_using', 'egasub %s' % ver)
#             ]
#         except Exception, err:
#             raise Exception("Can not create submission from this directory: %s. Please verify it's content. Error: %s" % (self._path, err))
# 
# 
#     @property
#     def status(self):
#         if self.analysis.status:
#             return self.analysis.status
#         else:
#             return 'NEW'  # hardcoded for now
# 
#     @property
#     def type(self):
#         return self.__class__.__bases__[0].__name__.lower()
# 
#     @property
#     def files(self):
#         return self.analysis.files
# 
#     @property
#     def sample(self):
#         return self._sample
# 
#     @property
#     def analysis(self):
#         return self._analysis
# 
#     def local_validate(self, ega_enums):
#         super(Analysis, self).local_validate(ega_enums)
# 
#         # Reference genomes type validation
#         if not any(cc['tag'] == str(self.analysis.genome_id) for cc in ega_enums.lookup("reference_genomes")):
#             self._add_local_validation_error("analysis",self.analysis.alias,"genomeId","Invalid value '%s'" % self.analysis.genome_id)
# 
#         # experimentTypeId type validation
#         if not isinstance(self.analysis.experiment_type_id, list):
#             self._add_local_validation_error("analysis",self.analysis.alias,"experimentTypes","Invalid value: experimentTypeId must be a list.")
# 
#         for e_type in self.analysis.experiment_type_id:
#             if not any(cc['tag'] == str(e_type) for cc in ega_enums.lookup("experiment_types")):
#                 self._add_local_validation_error("analysis",self.analysis.alias,"experimentTypes","Invalid value '%s' in experimentTypeId." % e_type)
# 
#         # Analysis titile validation
#         if not self.analysis.title:
#             self._add_local_validation_error("analysis",self.analysis.alias,"title","Invalid value: analysis title must be provided.")
# 
#         # Analysis description validation
#         if not self.analysis.description:
#             self._add_local_validation_error("analysis",self.analysis.alias,"description","Invalid value: analysis description must be provided.")
# 
#         # Chromosome references validation
#         # for some reason EGA only excepts this for variant file submission, not alignment
#         # but let's put it here, so it's required for both
#         if not isinstance(self.analysis.chromosome_references, list):
#             self._add_local_validation_error("analysis",self.analysis.alias,"chromosomeReferences","Invalid value: chromosomeReferences must be a list.")
# 
#         for chr_ref in self.analysis.chromosome_references:
#             if not any(cc['tag'] == str(chr_ref.value) for cc in ega_enums.lookup("reference_chromosomes")):
#                 self._add_local_validation_error("analysis",self.analysis.alias,"chromosomeReferences","Invalid value '%s' in chromosomeReferences" % chr_ref.value)


# Path: egasub/submission/submittable/alignment.py
import re
from .base import Analysis



class Alignment(Analysis):
    def __init__(self, path):
        super(Alignment, self).__init__(path)

        if not re.match(r'^[a-zA-Z0-9_\-]+(\.[a-zA-Z0-9_\-]+){0,1}$', self.submission_dir):
            raise Exception("Submission directory should be named as <sample alias> or <sample alias>.<lane label>, sample alias and lane label may only contain letter, digit, underscore (_) or dash (-)")


    def local_validate(self, ega_enums):

        super(Alignment, self).local_validate(ega_enums)