Example #1
0
 def validate_source(self, source):
     """
     Does the given source have both the methods `seek` and `read`?
     :raises InvalidDataProviderSource: if not.
     """
     source = super(ChunkDataProvider, self).validate_source(source)
     if ((not hasattr(source, 'seek')) or (not hasattr(source, 'read'))):
         raise exceptions.InvalidDataProviderSource(source)
     return source
Example #2
0
    def validate_source( self, source ):
        """
        Is this a valid source for this provider?

        :raises InvalidDataProviderSource: if the source is considered invalid.

        Meant to be overridden in subclasses.
        """
        if not source or not hasattr( source, '__iter__' ):
            # that's by no means a thorough check
            raise exceptions.InvalidDataProviderSource( source )
        return source
Example #3
0
    def __init__(self, dataset, **kwargs):
        """
        :param dataset: the Galaxy dataset whose file will be the source
        :type dataset: model.DatasetInstance

        :raises exceptions.InvalidDataProviderSource: if not a DatsetInstance
        """
        if not isinstance(dataset, galaxy.model.DatasetInstance):
            raise exceptions.InvalidDataProviderSource(
                "Data provider can only be used with a DatasetInstance")
        self.dataset = dataset
        # this dataset file is obviously the source
        #TODO: this might be a good place to interface with the object_store...
        super(DatasetDataProvider, self).__init__(open(dataset.file_name,
                                                       'rb'))
Example #4
0
    def __init__(self,
                 dataset,
                 options_string='',
                 options_dict=None,
                 regions=None,
                 **kwargs):
        """
        :param options_string: samtools options in string form (flags separated
            by spaces)
            Optional: defaults to ''
        :type options_string: str
        :param options_dict: dictionary of samtools options
            Optional: defaults to None
        :type options_dict: dict or None
        :param regions: list of samtools regions strings
            Optional: defaults to None
        :type regions: list of str or None
        """
        #TODO: into validate_source

        #TODO: have to import these here due to circular ref in model/datatypes
        import galaxy.datatypes.binary
        import galaxy.datatypes.tabular
        if (not (isinstance(dataset.datatype, galaxy.datatypes.tabular.Sam) or
                 isinstance(dataset.datatype, galaxy.datatypes.binary.Bam))):
            raise exceptions.InvalidDataProviderSource(
                'dataset must be a Sam or Bam datatype: %s' %
                (str(dataset.datatype)))
        self.dataset = dataset

        options_dict = options_dict or {}
        # ensure regions are strings
        regions = [str(r) for r in regions] if regions else []

        #TODO: view only for now
        #TODO: not properly using overriding super's validate_opts, command here
        subcommand = 'view'
        #TODO:?? do we need a path to samtools?
        subproc_args = self.build_command_list(subcommand, options_string,
                                               options_dict, regions)
        #TODO: the composition/inheritance here doesn't make a lot sense
        subproc_provider = external.SubprocessDataProvider(*subproc_args)
        super(SamtoolsDataProvider, self).__init__(subproc_provider, **kwargs)