# Path: ob_pipelines/batch.py
# class BatchTask(luigi.Task):
#     """
#     Base class for an Amazon Batch job
# 
#     Amazon Batch requires you to register "jobs", which are JSON descriptions
#     for how to issue the ``docker run`` command. This Luigi Task can either
#     run a pre-registered Batch jobDefinition, OR you can register the job on 
#     the fly from a Python dict.
# 
#     :param job_definition: pre-registered job definition ARN (Amazon Resource
#         Name), of the form::
# 
#             arn:aws:batch:<region>:<user_id>:job-definition/<job-name>:<version>
# 
#     """
#     job_name = None
# 
#     def run(self):
#         bc = BatchClient()
#         job_id = bc.submit_job(self.job_definition, self.parameters,
#                                job_name=self.job_name)
#         bc.wait_on_job(job_id)
# 
# class LoggingTaskWrapper(luigi.Task):
# 
#     task_priority = luigi.Parameter(default=50)
# 
#     @property
#     def priority(self):
#         return self.task_priority
# 
#     @property
#     def task_key(self):
#         return getattr(self, "__task_key", None)
# 
#     @task_key.setter
#     def task_key(self, value):
#         setattr(self, "__task_key", value)
# 
# Path: ob_pipelines/config.py
# AWS_PROFILE = os.environ.get('AWS_PROFILE', 'default')
# CONFIG_FILE = op.join(op.dirname(op.dirname(ob_pipelines.__file__)), 'config.yaml')
# class ConfigManager:
#     def __init__(self, config):
#     def get(self, option, default=None):
#     def get_source_bucket(self):
#     def get_target_bucket(self):
# 
# Path: ob_pipelines/entities/sample.py
# class Sample(object):
#     sample_id = Parameter()
# 
#     def __init__(self, *args, **kwargs):
# 
#         if 'id' in kwargs:
#             self.key = kwargs['id']
# 
#         if 'fields' in kwargs:
#             self._sample = kwargs['fields']
# 
#         if 'createdTime' in kwargs:
#             self._created_at = kwargs['createdTime']
#         else:
#             self._created_at = datetime.utcnow()
# 
# 
#     @property
#     def sample(self):
#         # TODO: remove fallback init
#         if not hasattr(self, '_sample'):
#             from ob_pipelines.entities.persistence import get_sample_by_name
#             self._sample = get_sample_by_name(self.sample_id)
#         return self._sample
# 
#     @property
#     def sample_folder(self) -> str:
#         return '{expt}/{sample}'.format(
#             bucket=settings.get_target_bucket(),
#             expt=self.experiment.name,
#             sample=self.sample_id)
# 
#     @property
#     def experiment(self):
#         # TODO: remove fallback init
#         if not hasattr(self, '_experiment'):
#             expt_key = self.sample.sample['Experiment'][0]
#             from ob_pipelines.entities.persistence import get_experiment_by_key
#             self._experiment = get_experiment_by_key(expt_key)
#         return self._experiment
# 
#     @experiment.setter
#     def experiment(self, value):
#         self._experiment = value
# 
# Path: ob_pipelines/pipelines/xenograft/tasks/star_by_species.py
# class StarBySpecies(Star):
# 
#     def requires(self):
#         return Skewer(sample_id=self.sample_id)
# 
#     def prefix(self):
#         return '{}/{}/star/{}.{}.'.format(
#             cfg['S3_BUCKET'], self.sample_folder, self.sample_id, self.species)


from luigi.contrib.s3 import S3Target
from ob_pipelines.batch import BatchTask, LoggingTaskWrapper
from ob_pipelines.config import cfg
from ob_pipelines.entities.sample import Sample
from ob_pipelines.pipelines.xenograft.tasks.star_by_species import StarBySpecies



class DisambiguateHumanMouse(BatchTask, LoggingTaskWrapper, Sample):
    job_definition = 'disambiguate'

    @property
    def parameters(self):
        outdir = '{}/{}/disambiguate/'.format(cfg['S3_BUCKET'], self.sample_folder)
        return {
            'outdir': outdir,
            'sample': self.sample_id,
            'aligner': 'star',
            'A': self.input()['human']['bam'].path,
            'B': self.input()['mouse']['bam'].path
        }

    def requires(self):
        return {
            'human': StarBySpecies(sample_id=self.sample_id, species='human'),

# Path: ob_pipelines/batch.py
# class BatchTask(luigi.Task):
#     """
#     Base class for an Amazon Batch job
# 
#     Amazon Batch requires you to register "jobs", which are JSON descriptions
#     for how to issue the ``docker run`` command. This Luigi Task can either
#     run a pre-registered Batch jobDefinition, OR you can register the job on 
#     the fly from a Python dict.
# 
#     :param job_definition: pre-registered job definition ARN (Amazon Resource
#         Name), of the form::
# 
#             arn:aws:batch:<region>:<user_id>:job-definition/<job-name>:<version>
# 
#     """
#     job_name = None
# 
#     def run(self):
#         bc = BatchClient()
#         job_id = bc.submit_job(self.job_definition, self.parameters,
#                                job_name=self.job_name)
#         bc.wait_on_job(job_id)
# 
# class LoggingTaskWrapper(luigi.Task):
# 
#     task_priority = luigi.Parameter(default=50)
# 
#     @property
#     def priority(self):
#         return self.task_priority
# 
#     @property
#     def task_key(self):
#         return getattr(self, "__task_key", None)
# 
#     @task_key.setter
#     def task_key(self, value):
#         setattr(self, "__task_key", value)
# 
# Path: ob_pipelines/config.py
# AWS_PROFILE = os.environ.get('AWS_PROFILE', 'default')
# CONFIG_FILE = op.join(op.dirname(op.dirname(ob_pipelines.__file__)), 'config.yaml')
# class ConfigManager:
#     def __init__(self, config):
#     def get(self, option, default=None):
#     def get_source_bucket(self):
#     def get_target_bucket(self):
# 
# Path: ob_pipelines/entities/sample.py
# class Sample(object):
#     sample_id = Parameter()
# 
#     def __init__(self, *args, **kwargs):
# 
#         if 'id' in kwargs:
#             self.key = kwargs['id']
# 
#         if 'fields' in kwargs:
#             self._sample = kwargs['fields']
# 
#         if 'createdTime' in kwargs:
#             self._created_at = kwargs['createdTime']
#         else:
#             self._created_at = datetime.utcnow()
# 
# 
#     @property
#     def sample(self):
#         # TODO: remove fallback init
#         if not hasattr(self, '_sample'):
#             from ob_pipelines.entities.persistence import get_sample_by_name
#             self._sample = get_sample_by_name(self.sample_id)
#         return self._sample
# 
#     @property
#     def sample_folder(self) -> str:
#         return '{expt}/{sample}'.format(
#             bucket=settings.get_target_bucket(),
#             expt=self.experiment.name,
#             sample=self.sample_id)
# 
#     @property
#     def experiment(self):
#         # TODO: remove fallback init
#         if not hasattr(self, '_experiment'):
#             expt_key = self.sample.sample['Experiment'][0]
#             from ob_pipelines.entities.persistence import get_experiment_by_key
#             self._experiment = get_experiment_by_key(expt_key)
#         return self._experiment
# 
#     @experiment.setter
#     def experiment(self, value):
#         self._experiment = value
# 
# Path: ob_pipelines/pipelines/xenograft/tasks/star_by_species.py
# class StarBySpecies(Star):
# 
#     def requires(self):
#         return Skewer(sample_id=self.sample_id)
# 
#     def prefix(self):
#         return '{}/{}/star/{}.{}.'.format(
#             cfg['S3_BUCKET'], self.sample_folder, self.sample_id, self.species)


# Path: ob_pipelines/pipelines/xenograft/tasks/disambiguate_human_mouse.py
from luigi.contrib.s3 import S3Target
from ob_pipelines.batch import BatchTask, LoggingTaskWrapper
from ob_pipelines.config import cfg
from ob_pipelines.entities.sample import Sample
from ob_pipelines.pipelines.xenograft.tasks.star_by_species import StarBySpecies




class DisambiguateHumanMouse(BatchTask, LoggingTaskWrapper, Sample):
    job_definition = 'disambiguate'

    @property
    def parameters(self):
        outdir = '{}/{}/disambiguate/'.format(cfg['S3_BUCKET'], self.sample_folder)
        return {
            'outdir': outdir,
            'sample': self.sample_id,
            'aligner': 'star',
            'A': self.input()['human']['bam'].path,
            'B': self.input()['mouse']['bam'].path
        }

    def requires(self):
        return {
            'human': StarBySpecies(sample_id=self.sample_id, species='human'),

            'mouse': StarBySpecies(sample_id=self.sample_id, species='mouse')