Ejemplo n.º 1
0
    def _create_search_report(self, wsname, id_to_similarity, id_to_link, ttlcount):

        outdir = os.path.join(self.tmp, 'search_report')
        self._mkdir_p(outdir)

        self._write_search_results(
            os.path.join(outdir, 'index.html'), id_to_similarity, id_to_link, ttlcount)

        log('Saving Sourmash search report')

        dfu = _DFUClient(self.callbackURL)
        try:
            dfuout = dfu.file_to_shock({'file_path': outdir, 'make_handle': 0, 'pack': 'zip'})
        except _DFUError as dfue:
            # not really any way to test this block
            log('Logging exception loading results to shock')
            log(str(dfue))
            raise
        log('saved report to shock node ' + dfuout['shock_id'])
        try:
            kbr = KBaseReport(self.callbackURL)
            return kbr.create_extended_report(
                {'direct_html_link_index': 0,
                 'html_links': [{'shock_id': dfuout['shock_id'],
                                 'name': 'index.html',
                                 'label': 'Sourmash search results'}
                                ],
                 'report_object_name': 'kb_sourmash_report_' + str(uuid.uuid4()),
                 'workspace_name': wsname
                 })
        except _RepError as re:
            log('Logging exception from creating report object')
            log(str(re))
            # TODO delete shock node
            raise
Ejemplo n.º 2
0
 def __init__(self, config):
     self.scratch = os.path.abspath(config['scratch'])
     self.tmp = os.path.join(self.scratch, str(uuid.uuid4()))
     self._mkdir_p(self.tmp)
     self.callbackURL = os.environ['SDK_CALLBACK_URL']
     self.ws_url = config['workspace-url']
     self.dfu = _DFUClient(self.callbackURL)
Ejemplo n.º 3
0
    def _generate_compare_report(self, compare_outfile, workspace_name):
        """
        _generate_compare_report: uses the basename to add the pngs to the html report
        """
        output_directory = os.path.join(self.scratch, str(uuid.uuid4()))
        self._mkdir_p(output_directory)

        report_html_file = os.path.join(output_directory, 'index.html')

        shutil.copy(compare_outfile, output_directory)
        shutil.copy(compare_outfile + '.labels.txt', output_directory)
        shutil.copy(compare_outfile + '.dendro.png', output_directory)
        shutil.copy(compare_outfile + '.hist.png', output_directory)
        shutil.copy(compare_outfile + '.matrix.png', output_directory)

        base = os.path.basename(compare_outfile)

        html_file = open(report_html_file, 'w')

        html_file.write('<HTML><BODY>')
        html_file.write('<img src="{}"><img src="{}"><img src="{}">'.format(
            base + '.dendro.png', base + '.hist.png', base + '.matrix.png'))
        html_file.write('</BODY></HTML>')

        html_file.close()

        dfu = _DFUClient(self.callbackURL)
        shock = dfu.file_to_shock({
            'file_path': output_directory,
            'make_handle': 0,
            'pack': 'zip'
        })

        report_params = {
            'message':
            '',
            'workspace_name':
            workspace_name,
            'html_links': [{
                'path': report_html_file,
                'shock_id': shock['shock_id'],
                'name': os.path.basename(report_html_file),
                'label': os.path.basename(report_html_file),
                'description': 'HTML report for sourmash compare'
            }],
            'direct_html_link_index':
            0,
            'html_window_height':
            266,
            'report_object_name':
            'kb_sourmash_compare_report_' + str(uuid.uuid4())
        }

        kbase_report_client = KBaseReport(self.callbackURL)
        output = kbase_report_client.create_extended_report(report_params)

        return output
Ejemplo n.º 4
0
    def create_search_report(self, wsname, id_to_similarity, search_db):

        outdir = os.path.join(self.tmp, 'search_report')
        self._mkdir_p(outdir)

        id_to_link = self._create_link_mapping(search_db, id_to_similarity.keys())

        self._write_search_results(
            os.path.join(outdir, 'index.html'), id_to_similarity, id_to_link)

        log('Saving Mash search report')

        dfu = _DFUClient(self.callbackURL)
        try:
            dfuout = dfu.file_to_shock({'file_path': outdir, 'make_handle': 0, 'pack': 'zip'})
        except _DFUError as dfue:
            # not really any way to test this block
            log('Logging exception loading results to shock')
            log(str(dfue))
            raise
        log('saved report to shock node ' + dfuout['shock_id'])
        try:
            kbr = KBaseReport(self.callbackURL)
            return kbr.create_extended_report(
                {'direct_html_link_index': 0,
                 'html_links': [{'shock_id': dfuout['shock_id'],
                                 'name': 'index.html',
                                 'label': 'Sourmash search results'}
                                ],
                 'report_object_name': 'kb_sourmash_report_' + str(uuid.uuid4()),
                 'workspace_name': wsname
                 })
        except _RepError as re:
            log('Logging exception from creating report object')
            log(str(re))
            # TODO delete shock node
            raise
Ejemplo n.º 5
0
    def run_QUAST(self, ctx, params):
        """
        Run QUAST and return a shock node containing the zipped QUAST output.
        :param params: instance of type "QUASTParams" (Input for running
           QUAST. assemblies - the list of assemblies upon which QUAST will
           be run. -OR- files - the list of FASTA files upon which QUAST will
           be run. Optional arguments: make_handle - create a handle for the
           new shock node for the report. force_glimmer - running '--glimmer'
           option regardless of file/assembly object size) -> structure:
           parameter "assemblies" of list of type "assembly_ref" (An X/Y/Z
           style reference to a workspace object containing an assembly,
           either a KBaseGenomes.ContigSet or
           KBaseGenomeAnnotations.Assembly.), parameter "files" of list of
           type "FASTAFile" (A local FASTA file. path - the path to the FASTA
           file. label - the label to use for the file in the QUAST output.
           If missing, the file name will be used.) -> structure: parameter
           "path" of String, parameter "label" of String, parameter
           "make_handle" of type "boolean" (A boolean - 0 for false, 1 for
           true. @range (0, 1)), parameter "force_glimmer" of type "boolean"
           (A boolean - 0 for false, 1 for true. @range (0, 1))
        :returns: instance of type "QUASTOutput" (Ouput of the run_quast
           function. shock_id - the id of the shock node where the zipped
           QUAST output is stored. handle - the new handle for the shock
           node, if created. node_file_name - the name of the file stored in
           Shock. size - the size of the file stored in shock. quast_path -
           the directory containing the quast output and the zipfile of the
           directory.) -> structure: parameter "shock_id" of String,
           parameter "handle" of type "Handle" (A handle for a file stored in
           Shock. hid - the id of the handle in the Handle Service that
           references this shock node id - the id for the shock node url -
           the url of the shock server type - the type of the handle. This
           should always be shock. file_name - the name of the file
           remote_md5 - the md5 digest of the file.) -> structure: parameter
           "hid" of String, parameter "file_name" of String, parameter "id"
           of String, parameter "url" of String, parameter "type" of String,
           parameter "remote_md5" of String, parameter "node_file_name" of
           String, parameter "size" of String, parameter "quast_path" of
           String
        """
        # ctx is the context object
        # return variables are: output
        #BEGIN run_QUAST
        self.log('Starting QUAST run. Parameters:')
        self.log(str(params))
        assemblies = params.get('assemblies')
        files = params.get('files')
        if not self.xor(assemblies, files):
            raise ValueError(
                'One and only one of a list of assembly references or files is required'
            )
        tdir = _os.path.join(self.scratch, str(_uuid.uuid4()))
        self.mkdir_p(tdir)
        if assemblies:
            if type(assemblies) != list:
                raise ValueError('assemblies must be a list')
            info = self.get_assembly_object_info(assemblies, ctx['token'])
            filepaths = self.get_assemblies(tdir, info)
            labels = [i.name for i in info]
        else:
            if type(files) != list:
                raise ValueError('files must be a list')
            filepaths = []
            labels = []
            for i, lp in enumerate(files):
                l = lp.get('label')
                p = lp.get('path')
                if not _os.path.isfile(p):
                    raise ValueError('File entry {}, {}, is not a file'.format(
                        i + 1, p))
                l = l if l else _os.path.basename(p)
                filepaths.append(p)
                labels.append(l)

        if params.get('force_glimmer'):
            skip_glimmer = False
        else:
            skip_glimmer = self.check_large_input(filepaths)

        out = _os.path.join(tdir, 'quast_results')
        # TODO check for name duplicates in labels and do something about it
        self.run_quast_exec(out, filepaths, labels, skip_glimmer)
        dfu = _DFUClient(self.callback_url)
        try:
            mh = params.get('make_handle')
            output = dfu.file_to_shock({
                'file_path': out,
                'make_handle': 1 if mh else 0,
                'pack': 'zip'
            })
        except _DFUError as dfue:
            # not really any way to test this block
            self.log('Logging exception loading results to shock')
            self.log(str(dfue))
            raise
        output['quast_path'] = out
        #END run_QUAST

        # At some point might do deeper type checking...
        if not isinstance(output, dict):
            raise ValueError('Method run_QUAST return value ' +
                             'output is not type dict as required.')
        # return the results
        return [output]