'Return converted dataset(s) if they exist, along with a dict of dependencies.
If not converted yet, do so and return None (the first time). If unconvertible, raise exception.'

def get_converted_dataset(self, trans, target_ext, target_context=None, history=None):

    if (target_ext not in self.get_converter_types()):
        raise NoConverterException(("Conversion    from    '%s'    to    '%s'    not    possible" % (self.extension, target_ext)))
    deps = {}
    try:
        depends_list = trans.app.datatypes_registry.converter_deps[self.extension][target_ext]
    except KeyError:
        depends_list = []
    converted_dataset = self.get_metadata_dataset(target_ext)
    if converted_dataset:
        return converted_dataset
    converted_dataset = self.get_converted_files_by_type(target_ext)
    if converted_dataset:
        return converted_dataset
    try:
        for dependency in depends_list:
            dep_dataset = self.get_converted_dataset(trans, dependency)
            if (dep_dataset is None):
                return None
            elif (dep_dataset.state == Job.states.ERROR):
                raise ConverterDependencyException(('A    dependency    (%s)    was    in    an    error    state.' % dependency))
            elif (dep_dataset.state != Job.states.OK):
                return None
            deps[dependency] = dep_dataset
    except NoConverterException:
        raise NoConverterException(('A    dependency    (%s)    is    missing    a    converter.' % dependency))
    except KeyError:
        pass
    new_dataset = next(iter(self.datatype.convert_dataset(trans, self, target_ext, return_output=True, visible=False, deps=deps, target_context=target_context, history=history).values()))
    new_dataset.name = self.name
    self.copy_attributes(new_dataset)
    assoc = ImplicitlyConvertedDatasetAssociation(parent=self, file_type=target_ext, dataset=new_dataset, metadata_safe=False)
    session = trans.sa_session
    session.add(new_dataset)
    session.add(assoc)
    session.flush()
    return new_dataset
