def calcSquareSum(self, ctx, params):
        """
        :param params: instance of type "CalcSquareSumParams"
           (===================== main =====================) -> structure:
           parameter "n" of Long
        :returns: instance of type "CalcSquareSumInputOutput" -> structure:
           parameter "square_sum" of Long
        """
        # ctx is the context object
        # return variables are: returnVal
        #BEGIN calcSquareSum
        kbp = KBParallel(os.environ['SDK_CALLBACK_URL'], token=ctx['token'])
        returnVal = kbp.run({
            'prepare_method': {
                'module_name': 'ParallelSquareSum',
                'method_name': 'calcSquareSumPrepare',
                'service_ver': 'dev'
            },
            'is_local': 1,
            'global_params': params,
            'time_limit': 1000000
        })
        #END calcSquareSum

        # At some point might do deeper type checking...
        if not isinstance(returnVal, dict):
            raise ValueError('Method calcSquareSum return value ' +
                             'returnVal is not type dict as required.')
        # return the results
        return [returnVal]
Beispiel #2
0
    def __init__(self, scratch_dir, workspace_url, callback_url, srv_wiz_url, provenance):
        self.workspace_url = workspace_url
        self.callback_url = callback_url
        self.srv_wiz_url = srv_wiz_url
        self.au = AssemblyUtil(self.callback_url)
        self.dfu = DataFileUtil(self.callback_url, service_ver='beta')
        self.scratch = scratch_dir
        self.working_dir = scratch_dir
        self.prog_runner = Program_Runner(self.STAR_BIN, self.scratch)
        self.provenance = provenance
        self.ws_client = Workspace(self.workspace_url)

        self.parallel_runner = KBParallel(self.callback_url)
        self.qualimap = kb_QualiMap(self.callback_url, service_ver='dev')
        self.set_api_client = SetAPI(self.srv_wiz_url, service_ver='dev')
        self.eu = ExpressionUtils(self.callback_url, service_ver='beta')
Beispiel #3
0
    def manyHellos(self, ctx, input_params):
        """
        :param input_params: instance of type "ManyHellosInputParams"
           (hello_msg - what to print as the message, time_limit - how long
           the program will run, in seconds, workspace - used to store
           report(s).) -> structure: parameter "hello_msg" of String,
           parameter "num_jobs" of Long, parameter "time_limit" of Long,
           parameter "workspace" of String
        :returns: instance of type "ManyHellos_globalResult" -> structure:
           parameter "output" of String, parameter "jobs" of list of tuple of
           size 2: parameter "job_number" of Long, parameter "message" of
           String
        """
        # ctx is the context object
        # return variables are: returnVal
        #BEGIN manyHellos
        print("Hi this is manyHellos()!")
        print("hello_mesg is ", input_params["hello_msg"])
        print("time_limit is ", input_params["time_limit"])
        print("num_jobs is ", input_params["num_jobs"])
        print("workspace is ", input_params["workspace"])

        kbp = KBParallel(os.environ['SDK_CALLBACK_URL'], token=ctx['token'])
        returnVal = kbp.run({
            'method': {
                'module_name': 'ManyHellos',
                'method_name': 'manyHellos',
                'service_ver': 'dev'
            },
            'is_local': 1,
            'global_params': {
                'msg': input_params["hello_msg"],
                'num_jobs': input_params["num_jobs"],
                'workspace': input_params["workspace"]
            },
            'time_limit': input_params["time_limit"]
        })
        print("this is manyHellos(), signing off!  Bye!")
        #END manyHellos

        # At some point might do deeper type checking...
        if not isinstance(returnVal, dict):
            raise ValueError('Method manyHellos return value ' +
                             'returnVal is not type dict as required.')
        # return the results
        return [returnVal]
Beispiel #4
0
    def __init__(self, scratch_dir, workspace_url, callback_url, srv_wiz_url,
                 provenance):
        self.scratch_dir = scratch_dir
        self.workspace_url = workspace_url
        self.callback_url = callback_url
        self.srv_wiz_url = srv_wiz_url
        self.provenance = provenance

        # from the provenance, extract out the version to run by exact hash if possible
        self.my_version = 'release'
        if len(provenance) > 0:
            if 'subactions' in provenance[0]:
                self.my_version = self.get_version_from_subactions(
                    'kb_BatchApp', provenance[0]['subactions'])
        print('Running kb_BatchApp version = ' + self.my_version)

        self.ws = Workspace(self.workspace_url)
        self.parallel_runner = KBParallel(self.callback_url)
Beispiel #5
0
    def __init__(self, config, provenance):
        self.config = config
        self.workspace_url = config['workspace-url']
        self.callback_url = os.environ['SDK_CALLBACK_URL']
        self.scratch = config['scratch']
        self.srv_wiz_url = config['srv-wiz-url']
        self.parallel_runner = KBParallel(self.callback_url)
        self.provenance = provenance
        self.star_utils = STARUtils(self.scratch, self.workspace_url,
                                    self.callback_url, self.srv_wiz_url,
                                    provenance)
        self.set_api_client = SetAPI(self.srv_wiz_url, service_ver='dev')
        self.qualimap = kb_QualiMap(self.callback_url, service_ver='dev')
        self.star_idx_dir = None
        self.star_out_dir = None

        # from the provenance, extract out the version to run by exact hash if possible
        self.my_version = 'release'
        if len(provenance) > 0:
            if 'subactions' in provenance[0]:
                self.my_version = self.get_version_from_subactions(
                    'kb_STAR', provenance[0]['subactions'])
        print('Running kb_STAR version = ' + self.my_version)
Beispiel #6
0
    def __init__(self, scratch_dir, workspace_url, callback_url, srv_wiz_url,
                 context):
        self.scratch_dir = scratch_dir
        self.workspace_url = workspace_url
        self.callback_url = callback_url
        self.srv_wiz_url = srv_wiz_url
        self.provenance = context.provenance()
        self.job_id = None
        rpc_context = context.get('rpc_context')
        if rpc_context is not None and hasattr(rpc_context, 'get'):
            current_call_ctx = rpc_context.get('call_stack')
            if len(current_call_ctx):
                self.job_id = current_call_ctx[0].get('job_id')

        # from the provenance, extract out the version to run by exact hash if possible
        self.my_version = 'release'
        if len(self.provenance) > 0:
            if 'subactions' in self.provenance[0]:
                self.my_version = self.get_version_from_subactions(
                    'kb_BatchApp', self.provenance[0]['subactions'])
        print('Running kb_BatchApp version = ' + self.my_version)

        self.ws = Workspace(self.workspace_url)
        self.parallel_runner = KBParallel(self.callback_url, service_ver='dev')
Beispiel #7
0
    def run_batch(self, reads_refs, params):
        """
        Runs HISAT2 in batch mode.
        reads_refs should be a list of dicts, where each looks like the following:
        {
            "ref": reads object reference,
            "condition": condition for that ref (string)
        }
        """
        # build task list and send it to KBParallel
        tasks = list()
        set_name = get_object_names(
            [params["sampleset_ref"]],
            self.workspace_url)[params["sampleset_ref"]]
        for idx, reads_ref in enumerate(reads_refs):
            single_param = dict(params)  # need a copy of the params
            single_param["build_report"] = 0
            single_param["sampleset_ref"] = reads_ref["ref"]
            if "condition" in reads_ref:
                single_param["condition"] = reads_ref["condition"]
            else:
                single_param["condition"] = "unspecified"

            tasks.append({
                "module_name": "kb_hisat2",
                "function_name": "run_hisat2",
                "version": self.my_version,
                "parameters": single_param
            })
        # UNCOMMENT BELOW FOR LOCAL TESTING
        batch_run_params = {
            "tasks": tasks,
            "runner": "parallel",
            # "concurrent_local_tasks": 3,
            # "concurrent_njsw_tasks": 0,
            "max_retries": 2
        }
        parallel_runner = KBParallel(self.callback_url)
        results = parallel_runner.run_batch(batch_run_params)["results"]
        alignment_items = list()
        alignments = dict()
        for idx, result in enumerate(results):
            # idx of the result is the same as the idx of the inputs AND reads_refs
            if result["is_error"] != 0:
                raise RuntimeError(
                    "Failed a parallel run of HISAT2! {}".format(
                        result["result_package"]["error"]))
            reads_ref = tasks[idx]["parameters"]["sampleset_ref"]
            alignment_items.append({
                "ref":
                result["result_package"]["result"][0]["alignment_objs"]
                [reads_ref]["ref"],
                "label":
                reads_refs[idx].get("condition",
                                    params.get("condition", "unspecified"))
            })
            alignments[reads_ref] = result["result_package"]["result"][0][
                "alignment_objs"][reads_ref]
        # build the final alignment set
        output_ref = self.upload_alignment_set(
            alignment_items, set_name + params["alignmentset_suffix"],
            params["ws_name"])
        return (alignments, output_ref)