Пример #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_hisat2'):
            cls.cfg[nameval[0]] = nameval[1]
        # Getting username from Auth profile for token
        auth_url = cls.cfg['auth-service-url']
        auth_client = _KBaseAuth(auth_url)
        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_hisat2',
                'method': 'please_never_use_it_in_production',
                'method_params': []
            }],
            'authenticated':
            1
        })
        cls.wsURL = cls.cfg['workspace-url']
        cls.ws_client = workspaceService(cls.wsURL)
        cls.serviceImpl = kb_hisat2(cls.cfg)
        cls.scratch = cls.cfg['scratch']
        cls.callback_url = os.environ['SDK_CALLBACK_URL']
        cls.srv_wiz_url = cls.cfg['srv-wiz-url']

        # set up the test workspace
        cls.ws_name = "test_kb_hisat2_{}".format(int(time.time() * 1000))
        cls.ws_client.create_workspace({"workspace": cls.ws_name})

        cls.dfu = DataFileUtil(cls.callback_url)

        # Upload test genome
        gbk_file = os.path.join(cls.scratch, os.path.basename(TEST_GBK_FILE))
        shutil.copy(TEST_GBK_FILE, gbk_file)
        cls.genome_ref = load_genbank_file(cls.callback_url, cls.ws_name,
                                           gbk_file, "my_test_genome")
        # Upload test reads - SingleEnd
        reads_file = os.path.join(cls.scratch,
                                  os.path.basename(TEST_READS_WT_1_FILE))
        shutil.copy(TEST_READS_WT_1_FILE, reads_file)
        cls.single_end_ref_wt_1 = load_reads(cls.callback_url, cls.ws_name,
                                             "Illumina", reads_file, None,
                                             "reads_wt_1")
        reads_file = os.path.join(cls.scratch,
                                  os.path.basename(TEST_READS_WT_2_FILE))
        shutil.copy(TEST_READS_WT_2_FILE, reads_file)
        cls.single_end_ref_wt_2 = load_reads(cls.callback_url, cls.ws_name,
                                             "Illumina", reads_file, None,
                                             "reads_wt_2")
        # reads_file = os.path.join(cls.scratch, os.path.basename(TEST_READS_HY5_1_FILE))
        # shutil.copy(TEST_READS_HY5_1_FILE, reads_file)
        # cls.single_end_ref_hy5_1 = load_reads(
        #     cls.callback_url, cls.ws_name, "Illumina", reads_file, None, "reads_hy5_1"
        # )
        # reads_file = os.path.join(cls.scratch, os.path.basename(TEST_READS_HY5_2_FILE))
        # shutil.copy(TEST_READS_HY5_2_FILE, reads_file)
        # cls.single_end_ref_hy5_2 = load_reads(
        #     cls.callback_url, cls.ws_name, "Illumina", reads_file, None, "reads_hy5_2"
        # )
        # Upload test reads - PairedEnd

        # Upload test ReadsSet of single end reads
        reads_set = [{
            "ref": cls.single_end_ref_wt_1,
            "label": "rs_wt1"
        }, {
            "ref": cls.single_end_ref_wt_2,
            "label": "rs_wt2"
        }]
        cls.single_end_reads_set = load_reads_set(cls.srv_wiz_url, cls.ws_name,
                                                  reads_set, "se_reads_set")

        # Upload test SampleSet of single end reads
        cls.reads_refs = [cls.single_end_ref_wt_1, cls.single_end_ref_wt_2]
        conditions = ["ss_wt1", "ss_wt2"]
        cls.single_end_sampleset = load_sample_set(cls.wsURL, cls.ws_name,
                                                   cls.reads_refs, conditions,
                                                   "SingleEnd", "se_sampleset")
Пример #2
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_hisat2'):
            cls.cfg[nameval[0]] = nameval[1]
        # Getting username from Auth profile for token
        auth_url = cls.cfg['auth-service-url']
        auth_client = _KBaseAuth(auth_url)
        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_hisat2',
                'method': 'please_never_use_it_in_production',
                'method_params': []
            }],
            'authenticated':
            1
        })
        cls.wsURL = cls.cfg['workspace-url']
        cls.ws_client = Workspace(cls.wsURL)
        cls.serviceImpl = kb_hisat2(cls.cfg)
        cls.scratch = cls.cfg['scratch']
        cls.callback_url = os.environ['SDK_CALLBACK_URL']
        cls.srv_wiz_url = cls.cfg['srv-wiz-url']

        # set up the test workspace
        cls.ws_name = "test_kb_hisat2_{}".format(int(time.time() * 1000))
        cls.ws_client.create_workspace({"workspace": cls.ws_name})

        cls.dfu = DataFileUtil(cls.callback_url)

        # Upload test genome
        gbk_file = os.path.join(cls.scratch, os.path.basename(TEST_GBK_FILE))
        shutil.copy(TEST_GBK_FILE, gbk_file)
        cls.genome_ref = load_genbank_file(cls.callback_url, cls.ws_name,
                                           gbk_file, "my_test_genome")
        # Upload test reads - SingleEnd
        reads_file = os.path.join(cls.scratch,
                                  os.path.basename(TEST_READS_WT_1_FILE))
        shutil.copy(TEST_READS_WT_1_FILE, reads_file)
        cls.single_end_ref_wt_1 = load_reads(cls.callback_url, cls.ws_name,
                                             "Illumina", reads_file, None,
                                             "reads_wt_1")
        reads_file = os.path.join(cls.scratch,
                                  os.path.basename(TEST_READS_WT_2_FILE))
        shutil.copy(TEST_READS_WT_2_FILE, reads_file)
        cls.single_end_ref_wt_2 = load_reads(cls.callback_url, cls.ws_name,
                                             "Illumina", reads_file, None,
                                             "reads_wt_2")
        # reads_file = os.path.join(cls.scratch, os.path.basename(TEST_READS_HY5_1_FILE))
        # shutil.copy(TEST_READS_HY5_1_FILE, reads_file)
        # cls.single_end_ref_hy5_1 = load_reads(
        #     cls.callback_url, cls.ws_name, "Illumina", reads_file, None, "reads_hy5_1"
        # )
        # reads_file = os.path.join(cls.scratch, os.path.basename(TEST_READS_HY5_2_FILE))
        # shutil.copy(TEST_READS_HY5_2_FILE, reads_file)
        # cls.single_end_ref_hy5_2 = load_reads(
        #     cls.callback_url, cls.ws_name, "Illumina", reads_file, None, "reads_hy5_2"
        # )
        # Upload test reads - PairedEnd

        # Upload test ReadsSet of single end reads
        reads_set = [{
            "ref": cls.single_end_ref_wt_1,
            "label": "rs_wt1"
        }, {
            "ref": cls.single_end_ref_wt_2,
            "label": "rs_wt2"
        }]
        cls.single_end_reads_set = load_reads_set(cls.srv_wiz_url, cls.ws_name,
                                                  reads_set, "se_reads_set")

        # Upload test SampleSet of single end reads
        cls.reads_refs = [cls.single_end_ref_wt_1, cls.single_end_ref_wt_2]
        conditions = ["ss_wt1", "ss_wt2"]
        cls.single_end_sampleset = load_sample_set(cls.wsURL, cls.ws_name,
                                                   cls.reads_refs, conditions,
                                                   "SingleEnd", "se_sampleset")
        genome_obj_info = cls.ws_client.get_objects2({
            'objects': [{
                'ref': cls.genome_ref
            }],
            'no_data':
            1
        })
        # get the list of genome refs from the returned info.
        # if there are no refs (or something funky with the return), this will be an empty list.
        # this WILL fail if data is an empty list. But it shouldn't be, and we know because
        # we have a real genome reference, or get_objects2 would fail.
        genome_obj_refs = genome_obj_info.get('data', [{}])[0].get('refs', [])

        # see which of those are of an appropriate type (ContigSet or Assembly), if any.
        assembly_ref = list()
        ref_params = [{'ref': x} for x in genome_obj_refs]
        ref_info = cls.ws_client.get_object_info3({'objects': ref_params})
        for idx, info in enumerate(ref_info.get('infos')):
            if "KBaseGenomeAnnotations.Assembly" in info[
                    2] or "KBaseGenomes.ContigSet" in info[2]:
                assembly_ref.append(";".join(ref_info.get('paths')[idx]))
        cls.assembly_ref = assembly_ref[0]
Пример #3
0
def get_config():
    if not get_config_file():
        return None
    retconfig = {}
    config = ConfigParser()
    config.read(get_config_file())
    for nameval in config.items(get_service_name() or 'kb_hisat2'):
        retconfig[nameval[0]] = nameval[1]
    return retconfig


config = get_config()

from kb_hisat2.kb_hisat2Impl import kb_hisat2  # noqa @IgnorePep8
impl_kb_hisat2 = kb_hisat2(config)


class JSONObjectEncoder(json.JSONEncoder):
    def default(self, obj):
        if isinstance(obj, set):
            return list(obj)
        if isinstance(obj, frozenset):
            return list(obj)
        if hasattr(obj, 'toJSONable'):
            return obj.toJSONable()
        return json.JSONEncoder.default(self, obj)


class JSONRPCServiceCustom(JSONRPCService):
    def call(self, ctx, jsondata):