Ejemplo n.º 1
0
 def setUpClass(cls):
     token = environ.get('KB_AUTH_TOKEN', None)
     config_file = environ.get('KB_DEPLOYMENT_CONFIG', None)
     cls.cfg = {}
     config = ConfigParser()
     config.read(config_file)
     for nameval in config.items('kb_Msuite'):
         cls.cfg[nameval[0]] = nameval[1]
     # Getting username from Auth profile for token
     authServiceUrl = cls.cfg['auth-service-url']
     auth_client = _KBaseAuth(authServiceUrl)
     user_id = auth_client.get_user(token)
     # WARNING: don't call any logging methods on the context object,
     # it'll result in a NoneType error
     cls.ctx = MethodContext(None)
     cls.ctx.update({
         'token':
         token,
         'user_id':
         user_id,
         'provenance': [{
             'service': 'kb_Msuite',
             'method': 'please_never_use_it_in_production',
             'method_params': []
         }],
         'authenticated':
         1
     })
     cls.wsURL = cls.cfg['workspace-url']
     cls.wsClient = workspaceService(cls.wsURL)
     cls.serviceImpl = kb_Msuite(cls.cfg)
     cls.scratch = cls.cfg['scratch']
     cls.callback_url = os.environ['SDK_CALLBACK_URL']
     cls.checkm_runner = CheckMUtil(cls.cfg)
Ejemplo n.º 2
0
    def test_output_plotting(self):

        cmu = CheckMUtil(self.cfg, self.ctx)
        plots_dir = os.path.join(self.scratch, 'plots_1')
        html_dir = os.path.join(self.scratch, 'html_1')
        tetra_file = os.path.join(self.scratch, 'tetra_1.tsv')

        cmu.build_checkM_lineage_wf_plots(self.input_dir, self.output_dir,
                                          plots_dir, self.all_seq_fasta,
                                          tetra_file)
        self.assertTrue(os.path.isdir(plots_dir))
        self.assertTrue(
            os.path.isfile(os.path.join(plots_dir, 'bin_qa_plot.png')))
        self.assertTrue(
            os.path.isfile(
                os.path.join(plots_dir, 'NewBins.001.ref_dist_plots.png')))
        self.assertTrue(
            os.path.isfile(
                os.path.join(plots_dir, 'NewBins.002.ref_dist_plots.png')))
        self.assertTrue(os.path.isfile(tetra_file))

        ob = OutputBuilder(self.output_dir, plots_dir, self.scratch,
                           self.callback_url)
        os.makedirs(html_dir)
        res = ob.build_html_output_for_lineage_wf(html_dir, 'MyCheckMOutput')
        self.assertIn('shock_id', res)
        self.assertIn('name', res)
        self.assertIn('description', res)
        self.assertEqual(res['name'], 'CheckM_Plot.html')
Ejemplo n.º 3
0
    def run_checkM_lineage_wf(self, ctx, params):
        """
        :param params: instance of type "CheckMLineageWfParams" (input_ref -
           reference to the input Assembly or BinnedContigs data (could be
           expanded to include Genome objects as well)) -> structure:
           parameter "input_ref" of String, parameter "workspace_name" of
           String, parameter "save_output_dir" of type "boolean" (A boolean -
           0 for false, 1 for true. @range (0, 1)), parameter
           "save_plots_dir" of type "boolean" (A boolean - 0 for false, 1 for
           true. @range (0, 1))
        :returns: instance of type "CheckMLineageWfResult" -> structure:
           parameter "report_name" of String, parameter "report_ref" of String
        """
        # ctx is the context object
        # return variables are: result
        #BEGIN run_checkM_lineage_wf
        print('--->\nRunning kb_Msuite.run_checkM_lineage_wf\nparams:')
        print(json.dumps(params, indent=1))

        cmu = CheckMUtil(self.config)
        result = cmu.run_checkM_lineage_wf(params)

        #END run_checkM_lineage_wf

        # At some point might do deeper type checking...
        if not isinstance(result, dict):
            raise ValueError('Method run_checkM_lineage_wf return value ' +
                             'result is not type dict as required.')
        # return the results
        return [result]
Ejemplo n.º 4
0
    def setUpClass(cls):
        token = environ.get('KB_AUTH_TOKEN', None)
        config_file = environ.get('KB_DEPLOYMENT_CONFIG', None)
        cls.cfg = {}
        config = ConfigParser()
        config.read(config_file)
        for nameval in config.items('kb_Msuite'):
            cls.cfg[nameval[0]] = nameval[1]
        # Getting username from Auth profile for token
        authServiceUrl = cls.cfg['auth-service-url']
        auth_client = _KBaseAuth(authServiceUrl)
        user_id = auth_client.get_user(token)
        # WARNING: don't call any logging methods on the context object,
        # it'll result in a NoneType error
        cls.ctx = MethodContext(None)
        cls.ctx.update({
            'token':
            token,
            'user_id':
            user_id,
            'provenance': [{
                'service': 'kb_Msuite',
                'method': 'please_never_use_it_in_production',
                'method_params': []
            }],
            'authenticated':
            1
        })
        cls.wsURL = cls.cfg['workspace-url']
        cls.wsClient = workspaceService(cls.wsURL)
        cls.serviceImpl = kb_Msuite(cls.cfg)
        cls.scratch = cls.cfg['scratch']
        cls.callback_url = os.environ['SDK_CALLBACK_URL']
        cls.checkm_runner = CheckMUtil(cls.cfg, cls.ctx)

        suffix = int(time.time() * 1000)
        cls.wsName = "test_kb_Msuite_" + str(suffix)
        cls.ws_info = cls.wsClient.create_workspace({'workspace': cls.wsName})
        cls.au = AssemblyUtil(os.environ['SDK_CALLBACK_URL'])
        cls.setAPI = SetAPI(url=cls.cfg['srv-wiz-url'], token=cls.ctx['token'])
        cls.gfu = GenomeFileUtil(os.environ['SDK_CALLBACK_URL'],
                                 service_ver='dev')
        cls.mu = MetagenomeUtils(os.environ['SDK_CALLBACK_URL'])

        # stage an input and output directory
        """
        cls.input_dir = os.path.join(cls.scratch, 'input_1')
        cls.output_dir = os.path.join(cls.scratch, 'output_1')
        cls.all_seq_fasta = os.path.join(cls.scratch, 'all_seq.fna')
        shutil.copytree(os.path.join('data', 'example_out', 'input'), cls.input_dir)
        shutil.copytree(os.path.join('data', 'example_out', 'output'), cls.output_dir)
        shutil.copy(os.path.join('data', 'example_out', 'all_seq.fna'), cls.all_seq_fasta)
        """

        # prepare WS data
        cls.prepare_data()
Ejemplo n.º 5
0
    def setUpClass(cls):
        token = environ.get('KB_AUTH_TOKEN', None)
        config_file = environ.get('KB_DEPLOYMENT_CONFIG', None)
        test_time_stamp = int(time.time() * 1000)

        cls.cfg = {}
        config = ConfigParser()
        config.read(config_file)
        for nameval in config.items('kb_Msuite'):
            cls.cfg[nameval[0]] = nameval[1]
        # Getting username from Auth profile for token
        authServiceUrl = cls.cfg['auth-service-url']
        auth_client = _KBaseAuth(authServiceUrl)
        user_id = auth_client.get_user(token)
        # WARNING: don't call any logging methods on the context object,
        # it'll result in a NoneType error
        cls.ctx = MethodContext(None)
        cls.ctx.update({
            'token':
            token,
            'user_id':
            user_id,
            'provenance': [{
                'service': 'kb_Msuite',
                'method': 'please_never_use_it_in_production',
                'method_params': []
            }],
            'authenticated':
            1
        })
        cls.wsURL = cls.cfg['workspace-url']
        cls.wsClient = Workspace(cls.wsURL)
        cls.serviceImpl = kb_Msuite(cls.cfg)
        cls.callback_url = os.environ['SDK_CALLBACK_URL']
        cls.scratch = cls.cfg['scratch']
        cls.appdir = cls.cfg['appdir']

        cls.test_data_dir = os.path.join(cls.scratch, 'test_data')
        cls.suffix = test_time_stamp
        cls.checkm_runner = CheckMUtil(cls.cfg, cls.ctx)

        cls.wsName = "test_kb_Msuite_" + str(cls.suffix)
        cls.ws_info = cls.wsClient.create_workspace({'workspace': cls.wsName})

        cls.au = AssemblyUtil(os.environ['SDK_CALLBACK_URL'])
        cls.gfu = GenomeFileUtil(os.environ['SDK_CALLBACK_URL'],
                                 service_ver='dev')
        cls.mu = MetagenomeUtils(os.environ['SDK_CALLBACK_URL'])
        cls.setAPI = SetAPI(url=cls.cfg['srv-wiz-url'], token=cls.ctx['token'])
        cls.kr = KBaseReport(os.environ['SDK_CALLBACK_URL'])

        cls.data_loaded = False
Ejemplo n.º 6
0
    def run_checkM(self, ctx, params):
        """
        :param params: instance of type "CheckMInputParams" (Runs CheckM as a
           command line local function. subcommand - specify the subcommand
           to run; supported options are lineage_wf, tetra, bin_qa_plot,
           dist_plot bin_folder - folder with fasta files representing each
           contig (must end in .fna) out_folder - folder to store output
           plots_folder - folder to save plots to seq_file - the full
           concatenated FASTA file (must end in .fna) of all contigs in your
           bins, used just for running the tetra command tetra_File - specify
           the output/input tetra nucleotide frequency file (generated with
           the tetra command) dist_value - when running dist_plot, set this
           to a value between 0 and 100 threads -  number of threads
           reduced_tree - if set to 1, run checkM with the reduced_tree flag,
           which will keep memory limited to less than 16gb (otherwise needs
           40+ GB, which NJS worker nodes do have) quiet - pass the --quiet
           parameter to checkM, but doesn't seem to work for all subcommands)
           -> structure: parameter "subcommand" of String, parameter
           "bin_folder" of String, parameter "out_folder" of String,
           parameter "plots_folder" of String, parameter "seq_file" of
           String, parameter "tetra_file" of String, parameter "dist_value"
           of Long, parameter "threads" of Long, parameter "reduced_tree" of
           type "boolean" (A boolean - 0 for false, 1 for true. @range (0,
           1)), parameter "quiet" of type "boolean" (A boolean - 0 for false,
           1 for true. @range (0, 1))
        """
        # ctx is the context object
        #BEGIN run_checkM
        print('--->\nRunning kb_Msuite.run_checkM\nparams:')
        print(json.dumps(params, indent=1))

        for key, value in list(params.items()):
            if isinstance(value, str):
                params[key] = value.strip()

        if 'subcommand' not in params:
            raise ValueError(
                '"subcommand" parameter field must be specified ' +
                '(to one of lineage_wf, tetra, bin_qa_plot, dist_plot, etc)')

        checkM_runner = CheckMUtil(self.config, ctx)
        checkM_runner.run_checkM(params['subcommand'], params)

        #END run_checkM
        pass
Ejemplo n.º 7
0
    def run_checkM_lineage_wf_withFilter(self, ctx, params):
        """
        :param params: instance of type "CheckMLineageWf_withFilter_Params"
           (input_ref - reference to the input BinnedContigs data) ->
           structure: parameter "input_ref" of String, parameter
           "workspace_name" of String, parameter "reduced_tree" of type
           "boolean" (A boolean - 0 for false, 1 for true. @range (0, 1)),
           parameter "save_output_dir" of type "boolean" (A boolean - 0 for
           false, 1 for true. @range (0, 1)), parameter "save_plots_dir" of
           type "boolean" (A boolean - 0 for false, 1 for true. @range (0,
           1)), parameter "completeness_perc" of Double, parameter
           "contamination_perc" of Double, parameter
           "output_filtered_binnedcontigs_obj_name" of String, parameter
           "threads" of Long
        :returns: instance of type "CheckMLineageWf_withFilter_Result" ->
           structure: parameter "report_name" of String, parameter
           "report_ref" of String, parameter "binned_contig_obj_ref" of type
           "obj_ref" ("WS_ID/OBJ_ID/VER")
        """
        # ctx is the context object
        # return variables are: result
        #BEGIN run_checkM_lineage_wf_withFilter
        print(
            '--->\nRunning kb_Msuite.run_checkM_lineage_wf_withFilter\nparams:'
        )
        print(json.dumps(params, indent=1))

        cmu = CheckMUtil(self.config, ctx)
        result = cmu.run_checkM_lineage_wf(params)

        #END run_checkM_lineage_wf_withFilter

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