def setUpClass(cls): token = os.environ.get('KB_AUTH_TOKEN', None) # WARNING: don't call any logging methods on the context object, # it'll result in a NoneType error cls.ctx = MethodContext(None) cls.ctx['token'] = token cls.ctx.update({ 'token': token, 'provenance': [{ 'service': 'GenomeFileUtil', 'method': 'please_never_use_it_in_production', 'method_params': [] }], 'authenticated': 1 }) config_file = os.environ.get('KB_DEPLOYMENT_CONFIG', None) cls.cfg = {} config = ConfigParser() config.read(config_file) for nameval in config.items('GenomeFileUtil'): cls.cfg[nameval[0]] = nameval[1] cls.wsURL = cls.cfg['workspace-url'] cls.wsClient = workspaceService(cls.wsURL, token=token) cls.serviceImpl = GenomeFileUtil(cls.cfg)
def setUpClass(cls): token = os.environ.get('KB_AUTH_TOKEN', None) # 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, 'provenance': [ {'service': 'GenomeFileUtil', 'method': 'please_never_use_it_in_production', 'method_params': [] }], 'authenticated': 1}) config_file = os.environ.get('KB_DEPLOYMENT_CONFIG', None) cls.cfg = {} config = ConfigParser() config.read(config_file) for nameval in config.items('GenomeFileUtil'): cls.cfg[nameval[0]] = nameval[1] cls.wsURL = cls.cfg['workspace-url'] cls.wsClient = workspaceService(cls.wsURL, token=token) cls.serviceImpl = GenomeFileUtil(cls.cfg) suffix = int(time.time() * 1000) cls.wsName = "test_GenomeFileUtil_" + str(suffix) ret = cls.wsClient.create_workspace({'workspace': cls.wsName}) cls.genome_ref = 'KBaseExampleData/Escherichia_coli_K-12_MG1655'
def setUpClass(cls): token = environ.get('KB_AUTH_TOKEN', None) # 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, 'provenance': [{ 'service': 'GenomeFileUtil', 'method': 'please_never_use_it_in_production', 'method_params': [] }], 'authenticated': 1 }) config_file = environ.get('KB_DEPLOYMENT_CONFIG', None) cls.cfg = {} config = ConfigParser() config.read(config_file) for nameval in config.items('GenomeFileUtil'): cls.cfg[nameval[0]] = nameval[1] cls.wsURL = cls.cfg['workspace-url'] cls.ws = workspaceService(cls.wsURL, token=token) cls.gaa = GenomeAnnotationAPI(os.environ['SDK_CALLBACK_URL']) cls.serviceImpl = GenomeFileUtil(cls.cfg) # create one WS for all tests suffix = int(time.time() * 1000) wsName = "test_GenomeAnnotationAPI_" + str(suffix) ret = cls.ws.create_workspace({'workspace': wsName}) cls.wsName = wsName
def setUpClass(cls): print('setting up class') token = environ.get('KB_AUTH_TOKEN', None) # 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, 'provenance': [{ 'service': 'GenomeFileUtil', 'method': 'please_never_use_it_in_production', 'method_params': [] }], 'authenticated': 1 }) config_file = environ.get('KB_DEPLOYMENT_CONFIG', None) cls.cfg = {} config = ConfigParser() config.read(config_file) for nameval in config.items('GenomeFileUtil'): cls.cfg[nameval[0]] = nameval[1] cls.wsURL = cls.cfg['workspace-url'] cls.ws = workspaceService(cls.wsURL, token=token) cls.impl = GenomeFileUtil(cls.cfg) cls.MINIMAL_TEST_FILE = os.path.join(cls.cfg['scratch'], 'minimal.gbff') shutil.copy('data/minimal.gbff', cls.MINIMAL_TEST_FILE)
def setUpClass(cls): cls.token = environ.get('KB_AUTH_TOKEN', None) config_file = environ.get('KB_DEPLOYMENT_CONFIG', None) cls.cfg = {} config = ConfigParser() config.read(config_file) # type: ignore for nameval in config.items('GenomeFileUtil'): cls.cfg[nameval[0]] = nameval[1] authServiceUrl = cls.cfg.get( 'auth-service-url', "https://kbase.us/services/authorization/Sessions/Login") auth_client = _KBaseAuth(authServiceUrl) cls.user_id = auth_client.get_user(cls.token) cls.ctx = MethodContext(None) cls.ctx.update({ 'token': cls.token, 'user_id': cls.user_id, 'provenance': [{ 'service': 'GenomeFileUtil', 'method': 'please_never_use_it_in_production', 'method_params': [] }], 'authenticated': 1 }) cls.wsURL = cls.cfg['workspace-url'] cls.wsClient = workspaceService(cls.wsURL, token=cls.token) cls.serviceImpl = GenomeFileUtil(cls.cfg) cls.dfu = DataFileUtil(os.environ['SDK_CALLBACK_URL'], token=cls.token) cls.scratch = cls.cfg['scratch'] cls.shockURL = cls.cfg['shock-url'] cls.gfu_cfg = SDKConfig(cls.cfg) cls.prepare_data()
def setUpClass(cls): token = os.environ.get('KB_AUTH_TOKEN', None) # 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, 'provenance': [ {'service': 'GenomeFileUtil', 'method': 'please_never_use_it_in_production', 'method_params': [] }], 'authenticated': 1}) config_file = os.environ.get('KB_DEPLOYMENT_CONFIG', None) cls.cfg = {} config = ConfigParser() config.read(config_file) for nameval in config.items('GenomeFileUtil'): cls.cfg[nameval[0]] = nameval[1] cls.wsURL = cls.cfg['workspace-url'] cls.wsClient = workspaceService(cls.wsURL, token=token) cls.serviceImpl = GenomeFileUtil(cls.cfg) gff_path = "data/fasta_gff/RefSeq/Bacterial_Data/NC_021490.gff.gz" fasta_path = "data/fasta_gff/RefSeq/Bacterial_Data/NC_021490.fasta.gz" ws_obj_name = 'fungal_model' suffix = int(time.time() * 1000) cls.wsName = "test_GenomeFileUtil_" + str(suffix) ret = cls.wsClient.create_workspace({'workspace': cls.wsName}) print('Uploading GFF file') result = cls.serviceImpl.fasta_gff_to_genome( cls.ctx, { 'workspace_name': cls.wsName, 'genome_name': 'MyGenome', 'fasta_file': {'path': fasta_path}, 'gff_file': {'path': gff_path}, 'source': 'GFF', 'type': 'Reference' })[0] data_file_cli = DataFileUtil(os.environ['SDK_CALLBACK_URL']) cls.genome_orig = data_file_cli.get_objects( {'object_refs': [result['genome_ref']]})['data'][0]['data'] print('testing GFF download by building the file') down_result = cls.serviceImpl.genome_to_gff( cls.ctx, {'genome_ref': result['genome_ref']})[0] print('Reuploading GFF file') new_result = cls.serviceImpl.fasta_gff_to_genome( cls.ctx, { 'workspace_name': cls.wsName, 'genome_name': 'MyGenome', 'fasta_file': {'path': fasta_path}, 'gff_file': {'path': down_result['file_path']}, 'source': 'GFF', 'type': 'Reference' })[0] cls.genome_new = data_file_cli.get_objects({'object_refs': [new_result['genome_ref']]})['data'][0]['data']
def setUpClass(cls): token = os.environ.get('KB_AUTH_TOKEN', None) # 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, 'provenance': [ {'service': 'GenomeFileUtil', 'method': 'please_never_use_it_in_production', 'method_params': [] }], 'authenticated': 1}) config_file = os.environ.get('KB_DEPLOYMENT_CONFIG', None) cls.cfg = {} config = ConfigParser() config.read(config_file) for nameval in config.items('GenomeFileUtil'): cls.cfg[nameval[0]] = nameval[1] cls.wsURL = cls.cfg['workspace-url'] cls.wsClient = workspaceService(cls.wsURL, token=token) cls.serviceImpl = GenomeFileUtil(cls.cfg) # gbk_path = "data/Cyanidioschyzon/Cyanidioschyzon_merolae.ASM9120v1.30.gbff" gbk_path = "data/Cyanidioschyzon/Cyanidioschyzon_merolae_one_locus.gbff" ws_obj_name = 'Cyanidioschyzon_merolae_duplicate_test_orig' suffix = int(time.time() * 1000) cls.wsName = "test_GenomeFileUtil_" + str(suffix) cls.wsClient.create_workspace({'workspace': cls.wsName}) result = cls.serviceImpl.genbank_to_genome(cls.ctx, { 'file': {'path': gbk_path}, 'workspace_name': cls.wsName, 'genome_name': ws_obj_name, 'generate_ids_if_needed': 1, 'taxon_id': '511145', 'source': "Ensembl user" })[0] data_file_cli = DataFileUtil( os.environ['SDK_CALLBACK_URL'], token=cls.ctx['token'], service_ver='dev' ) cls.genome_orig = data_file_cli.get_objects({'object_refs': [result['genome_ref']]})['data'][0]['data'] print('testing Genbank download by building the file') cls.serviceImpl.export_genome_as_genbank(cls.ctx, { 'input_ref': result['genome_ref']}) new_gbk_path = "/kb/module/work/tmp/Cyanidioschyzon_merolae_duplicate_test_orig/KBase_derived_Cyanidioschyzon_merolae_duplicate_test_orig.gbff" new_ws_obj_name = 'Cyanidioschyzon_merolae_duplicate_test_new' new_result = cls.serviceImpl.genbank_to_genome(cls.ctx, { 'file': {'path': new_gbk_path}, 'workspace_name': cls.wsName, 'genome_name': new_ws_obj_name, 'generate_ids_if_needed': 1, 'taxon_id': '511145', 'source': "Ensembl user" })[0] cls.genome_new = data_file_cli.get_objects({'object_refs': [new_result['genome_ref']]})['data'][0]['data']
def setUpClass(cls): token = os.environ.get('KB_AUTH_TOKEN', None) # 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, 'provenance': [{ 'service': 'GenomeFileUtil', 'method': 'please_never_use_it_in_production', 'method_params': [] }], 'authenticated': 1 }) config_file = os.environ.get('KB_DEPLOYMENT_CONFIG', None) cls.cfg = {} config = ConfigParser() config.read(config_file) for nameval in config.items('GenomeFileUtil'): cls.cfg[nameval[0]] = nameval[1] cls.wsURL = cls.cfg['workspace-url'] cls.wsClient = workspaceService(cls.wsURL, token=token) cls.serviceImpl = GenomeFileUtil(cls.cfg) gbk_path = "data/Arabidopsis_gbff/A_thaliana_Ensembl_TAIR10_38_chr4_minus_xref.gbff" ws_obj_name = 'Yeast_chromosome1' suffix = int(time.time() * 1000) cls.wsName = "test_GenomeFileUtil_" + str(suffix) ret = cls.wsClient.create_workspace({'workspace': cls.wsName}) result = cls.serviceImpl.genbank_to_genome( cls.ctx, { 'file': { 'path': gbk_path }, 'workspace_name': cls.wsName, 'genome_name': ws_obj_name, 'generate_ids_if_needed': 1, 'source': "Ensembl" })[0] # print("HERE IS THE RESULT:") data_file_cli = DataFileUtil(os.environ['SDK_CALLBACK_URL'], token=cls.ctx['token'], service_ver='dev') cls.genome = data_file_cli.get_objects( {'object_refs': [result['genome_ref']]})['data'][0]['data'] json.dump( cls.genome, open(cls.cfg['scratch'] + "/relationship_test_genome.json", 'w')) cls.gene_ids = set((x['id'] for x in cls.genome['features'])) cls.nc_feat_ids = set( (x['id'] for x in cls.genome['non_coding_features'])) cls.mrna_ids = set((x['id'] for x in cls.genome['mrnas'])) cls.cds_ids = set((x['id'] for x in cls.genome['cdss']))
def setUpClass(cls): token = os.environ.get('KB_AUTH_TOKEN', None) # 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, 'provenance': [{ 'service': 'GenomeFileUtil', 'method': 'please_never_use_it_in_production', 'method_params': [] }], 'authenticated': 1 }) config_file = os.environ['KB_DEPLOYMENT_CONFIG'] cls.cfg = {} config = ConfigParser() config.read(config_file) for nameval in config.items('GenomeFileUtil'): cls.cfg[nameval[0]] = nameval[1] cls.wsURL = cls.cfg['workspace-url'] cls.wsClient = workspaceService(cls.wsURL, token=token) cls.serviceImpl = GenomeFileUtil(cls.cfg) gff_path = "data/e_coli/NC_000913.3.gff3" fna_path = "data/e_coli/NC_000913.3.fasta" # fna_path = "data/e_coli/GCF_000005845.2_ASM584v2.fasta" ws_obj_name = 'ecoli_contigs' suffix = int(time.time() * 1000) cls.wsName = "test_GenomeFileUtil_" + str(suffix) cls.wsClient.create_workspace({'workspace': cls.wsName}) result = cls.serviceImpl.fasta_gff_to_genome( cls.ctx, { 'gff_file': { 'path': gff_path }, 'fasta_file': { 'path': fna_path }, 'taxon_id': 511145, 'workspace_name': cls.wsName, 'genome_name': ws_obj_name, 'generate_missing_genes': 1, 'generate_ids_if_needed': 1 })[0] data_file_cli = DataFileUtil(os.environ['SDK_CALLBACK_URL'], token=cls.ctx['token'], service_ver='dev') dfu_result = data_file_cli.get_objects( {'object_refs': [result['genome_ref']]}) cls.genome = dfu_result['data'][0]['data']
def setUpClass(cls): token = environ.get('KB_AUTH_TOKEN', None) # 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, 'provenance': [ {'service': 'GenomeFileUtil', 'method': 'please_never_use_it_in_production', 'method_params': [] }], 'authenticated': 1}) config_file = environ.get('KB_DEPLOYMENT_CONFIG', None) cls.cfg = {} config = ConfigParser() config.read(config_file) for nameval in config.items('GenomeFileUtil'): cls.cfg[nameval[0]] = nameval[1] cls.wsURL = cls.cfg['workspace-url'] cls.ws = workspaceService(cls.wsURL, token=token) cls.serviceImpl = GenomeFileUtil(cls.cfg) gi_config = SDKConfig(cls.cfg) cls.genome_interface = GenomeInterface(gi_config) # create one WS for all tests suffix = int(time.time() * 1000) wsName = "test_GenomeAnnotationAPI_" + str(suffix) cls.ws.create_workspace({'workspace': wsName}) cls.wsName = wsName # save new genome assembly_file_path = os.path.join(cls.cfg['scratch'], 'Rhodo_SPAdes_assembly.fa') shutil.copy('data/Rhodo_SPAdes_assembly.fa', assembly_file_path) au = AssemblyUtil(os.environ['SDK_CALLBACK_URL']) cls.assembly_ref = au.save_assembly_from_fasta({ 'workspace_name': cls.wsName, 'assembly_name': 'ecoli.assembly', 'file': {'path': assembly_file_path} }) rhodobacter_contigs = json.load(open('data/rhodobacter_contigs.json')) save_info = { 'workspace': cls.wsName, 'objects': [{ 'type': 'KBaseGenomes.ContigSet', 'data': rhodobacter_contigs, 'name': 'rhodobacter_contigs' }] } cls.contigset_ref = cls.ws.save_objects(save_info)
def setUpClass(cls): token = os.environ.get('KB_AUTH_TOKEN', None) # 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, 'provenance': [{ 'service': 'GenomeFileUtil', 'method': 'please_never_use_it_in_production', 'method_params': [] }], 'authenticated': 1 }) config_file = os.environ.get('KB_DEPLOYMENT_CONFIG', None) cls.cfg = {} config = ConfigParser() config.read(config_file) for nameval in config.items('GenomeFileUtil'): cls.cfg[nameval[0]] = nameval[1] cls.wsURL = cls.cfg['workspace-url'] cls.wsClient = workspaceService(cls.wsURL, token=token) cls.serviceImpl = GenomeFileUtil(cls.cfg) gbk_path = "data/e_coli/GCF_000005845.2_ASM584v2_genomic.gbff" ws_obj_name = 'ecoli_genome' suffix = int(time.time() * 1000) cls.wsName = "test_GenomeFileUtil_" + str(suffix) ret = cls.wsClient.create_workspace({'workspace': cls.wsName}) result = cls.serviceImpl.genbank_to_genome( cls.ctx, { 'file': { 'path': gbk_path }, 'workspace_name': cls.wsName, 'genome_name': ws_obj_name, 'generate_ids_if_needed': 1, 'source': "RefSeq Reference" })[0] # print("HERE IS THE RESULT:") data_file_cli = DataFileUtil(os.environ['SDK_CALLBACK_URL'], token=cls.ctx['token'], service_ver='dev') genome = data_file_cli.get_objects( {'object_refs': [result['genome_ref']]})['data'][0]['data'] cls.assembly_ref = genome["assembly_ref"]
def setUpClass(cls): token = os.environ.get('KB_AUTH_TOKEN', None) # 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, 'provenance': [ {'service': 'GenomeFileUtil', 'method': 'please_never_use_it_in_production', 'method_params': [] }], 'authenticated': 1}) config_file = os.environ.get('KB_DEPLOYMENT_CONFIG', None) cls.cfg = {} config = ConfigParser() config.read(config_file) for nameval in config.items('GenomeFileUtil'): cls.cfg[nameval[0]] = nameval[1] cls.wsURL = cls.cfg['workspace-url'] cls.wsClient = workspaceService(cls.wsURL, token=token) cls.serviceImpl = GenomeFileUtil(cls.cfg) gbk_path = "data/Arabidopsis_gbff/Arab_Chloro_Modified.gbff" ws_obj_name = 'ArabidopsisChloro' suffix = int(time.time() * 1000) cls.wsName = "test_GenomeFileUtil_" + str(suffix) ret = cls.wsClient.create_workspace({'workspace': cls.wsName}) result = cls.serviceImpl.genbank_to_genome( cls.ctx, { 'file': { 'path': gbk_path}, 'workspace_name': cls.wsName, 'genome_name': ws_obj_name, 'generate_ids_if_needed': 1, 'source': "RefSeq Latest" })[0] data_file_cli = DataFileUtil(os.environ['SDK_CALLBACK_URL'], token=cls.ctx['token'], service_ver='dev') cls.genome = data_file_cli.get_objects({'object_refs': [result['genome_ref']]})['data'][0]['data'] json.dump(cls.genome, open(cls.cfg['scratch']+"/test_genome.json", 'w'))
def setUpClass(cls): token = environ.get('KB_AUTH_TOKEN', None) # 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, 'provenance': [ {'service': 'GenomeFileUtil', 'method': 'please_never_use_it_in_production', 'method_params': [] }], 'authenticated': 1}) config_file = environ.get('KB_DEPLOYMENT_CONFIG', None) cls.cfg = {} config = ConfigParser() config.read(config_file) for nameval in config.items('GenomeFileUtil'): cls.cfg[nameval[0]] = nameval[1] cls.wsURL = cls.cfg['workspace-url'] cls.wsClient = workspaceService(cls.wsURL, token=token) cls.serviceImpl = GenomeFileUtil(cls.cfg) cls.TEST_ECOLI_FILE_FTP = 'ftp://ftp.ncbi.nlm.nih.gov/genomes/refseq/bacteria/Escherichia_coli/reference/GCF_000005845.2_ASM584v2/GCF_000005845.2_ASM584v2_genomic.gbff.gz'
def setUpClass(cls): token = os.environ.get('KB_AUTH_TOKEN', None) # 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, 'provenance': [ {'service': 'GenomeFileUtil', 'method': 'please_never_use_it_in_production', 'method_params': [] }], 'authenticated': 1}) config_file = os.environ.get('KB_DEPLOYMENT_CONFIG', None) cls.cfg = {} config = ConfigParser() config.read(config_file) for nameval in config.items('GenomeFileUtil'): cls.cfg[nameval[0]] = nameval[1] cls.wsURL = cls.cfg['workspace-url'] cls.wsClient = workspaceService(cls.wsURL, token=token) cls.serviceImpl = GenomeFileUtil(cls.cfg) # get metagenome data. cls.gff_path = "data/metagenomes/ebi/59111.assembled.gff" cls.fasta_path = "data/metagenomes/ebi/59111.assembled.fna" if not os.path.isfile(cls.fasta_path) or not os.path.isfile(cls.gff_path): raise InputError(f'Files {cls.gff_path} and/or {cls.fasta_path} not in test directory ') suffix = int(time.time() * 1000) cls.wsName = "test_GenomeFileUtil_" + str(suffix) cls.wsClient.create_workspace({'workspace': cls.wsName}) print('Uploading GFF file') result = cls.serviceImpl.fasta_gff_to_metagenome(cls.ctx, { 'workspace_name': cls.wsName, 'genome_name': 'MyGenome', 'fasta_file': {'path': cls.fasta_path}, 'gff_file': {'path': cls.gff_path}, 'source': 'GFF', 'taxon_id': '3702', 'type': 'Reference', 'genome_type': 'Metagenome', 'is_metagenome': True, 'generate_missing_genes': True })[0] data_file_cli = DataFileUtil(os.environ['SDK_CALLBACK_URL']) cls.metagenome_ref = result['metagenome_ref'] cls.genome_orig = data_file_cli.get_objects( {'object_refs': [result['metagenome_ref']]})['data'][0]['data'] print('testing GFF download by building the file') down_result = cls.serviceImpl.metagenome_to_gff( cls.ctx, {'metagenome_ref': result['metagenome_ref']})[0] print('Reuploading GFF file') new_result = cls.serviceImpl.fasta_gff_to_metagenome(cls.ctx, { 'workspace_name': cls.wsName, 'genome_name': 'MyGenome', 'fasta_file': {'path': cls.fasta_path}, 'gff_file': {'path': down_result['file_path']}, 'source': 'GFF', 'type': 'Reference', 'genome_type': 'Metagenome', 'is_metagenome': True, 'generate_missing_genes': True, 'taxon_id': '3702', })[0] cls.genome_new = data_file_cli.get_objects({'object_refs': [new_result['metagenome_ref']]})['data'][0]['data']
def setUpClass(cls): token = environ.get('KB_AUTH_TOKEN', None) # 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, 'provenance': [{ 'service': 'GenomeFileUtil', 'method': 'please_never_use_it_in_production', 'method_params': [] }], 'authenticated': 1 }) config_file = environ.get('KB_DEPLOYMENT_CONFIG', None) cls.cfg = {} config = ConfigParser() config.read(config_file) for nameval in config.items('GenomeFileUtil'): cls.cfg[nameval[0]] = nameval[1] cls.wsURL = cls.cfg['workspace-url'] cls.ws = workspaceService(cls.wsURL, token=token) cls.serviceImpl = GenomeFileUtil(cls.cfg) # create one WS for all tests suffix = int(time.time() * 1000) wsName = "test_GenomeAnnotationAPI_" + str(suffix) ret = cls.ws.create_workspace({'workspace': wsName}) cls.wsName = wsName # preload with reference data with open('data/rhodobacter.json', 'r') as file: data_str = file.read() data = json.loads(data_str) # save to ws save_info = { 'workspace': wsName, 'objects': [{ 'type': 'KBaseGenomes.Genome', 'data': data, 'name': 'rhodobacter' }] } result = cls.ws.save_objects(save_info) info = result[0] cls.rhodobacter_ref = str(info[6]) + '/' + str(info[0]) + '/' + str( info[4]) print('created rhodobacter test genome: ' + cls.rhodobacter_ref) # save a GFF file to shock, preload a genome pointing to it dfu = DataFileUtil(os.environ['SDK_CALLBACK_URL']) shutil.copy('data/rhodobacter.gtf', cls.cfg['scratch']) shock_file = dfu.file_to_shock({ 'file_path': os.path.join(cls.cfg['scratch'], 'rhodobacter.gtf'), 'make_handle': 1 }) data['gff_handle_ref'] = shock_file['handle']['hid'] # save to ws save_info['objects'][0]['name'] = 'rhodobacter_with_gff' result = cls.ws.save_objects(save_info) info = result[0] cls.rhodobacter_ref_with_gff = str(info[6]) + '/' + str( info[0]) + '/' + str(info[4]) print('created rhodobacter test genome with handle: ' + cls.rhodobacter_ref_with_gff)
def setUpClass(cls): 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('GenomeFileUtil'): cls.cfg[nameval[0]] = nameval[1] # Getting username from Auth profile for token authServiceUrl = cls.cfg['auth-service-url'] auth_client = _KBaseAuth(authServiceUrl) cls.user_id = auth_client.get_user(cls.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': cls.token, 'user_id': cls.user_id, 'provenance': [ {'service': 'kb_ke_util', 'method': 'please_never_use_it_in_production', 'method_params': [] }], 'authenticated': 1}) cls.shockURL = cls.cfg['shock-url'] cls.wsURL = cls.cfg['workspace-url'] cls.wsClient = workspaceService(cls.wsURL) cls.serviceImpl = GenomeFileUtil(cls.cfg) cls.scratch = cls.cfg['scratch'] cls.callback_url = os.environ['SDK_CALLBACK_URL'] cls.dfu = DataFileUtil(cls.callback_url) cls.cfg['KB_AUTH_TOKEN'] = cls.token # build genome interface instance gi_config = SDKConfig(cls.cfg) cls.genome_interface = GenomeInterface(gi_config) # second user test_cfg_file = '/kb/module/work/test.cfg' test_cfg_text = "[test]\n" with open(test_cfg_file, "r") as f: test_cfg_text += f.read() config = ConfigParser() config.readfp(io.StringIO(test_cfg_text)) test_cfg_dict = dict(config.items("test")) if ('test_token2' not in test_cfg_dict): raise ValueError("Configuration in <module>/test_local/test.cfg file should " + "include second user credentials ('test_token2')") token2 = test_cfg_dict['test_token2'] user2 = auth_client.get_user(token2) cls.ctx2 = MethodContext(None) cls.ctx2.update({'token': token2, 'user_id': user2, 'provenance': [ {'service': 'NarrativeService', 'method': 'please_never_use_it_in_production', 'method_params': [] }], 'authenticated': 1}) suffix = int(time.time() * 1000) cls.wsName = "test_SaveGenomeTest_" + str(suffix) cls.wsClient.create_workspace({'workspace': cls.wsName}) cls.nodes_to_delete = [] cls.prepare_data()
def setUpClass(cls): token = environ.get('KB_AUTH_TOKEN', None) # 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, 'provenance': [{ 'service': 'GenomeFileUtil', 'method': 'please_never_use_it_in_production', 'method_params': [] }], 'authenticated': 1 }) config_file = environ.get('KB_DEPLOYMENT_CONFIG', None) cls.cfg = {} config = ConfigParser() config.read(config_file) for nameval in config.items('GenomeFileUtil'): cls.cfg[nameval[0]] = nameval[1] cls.wsURL = cls.cfg['workspace-url'] cls.ws = workspaceService(cls.wsURL, token=token) cls.gaa = GenomeAnnotationAPI(os.environ['SDK_CALLBACK_URL']) cls.serviceImpl = GenomeFileUtil(cls.cfg) # create one WS for all tests suffix = int(time.time() * 1000) wsName = "test_GenomeAnnotationAPI_" + str(suffix) ret = cls.ws.create_workspace({'workspace': wsName}) cls.wsName = wsName cls.ara_ref = cls.serviceImpl.genbank_to_genome( cls.ctx, { 'file': { 'path': 'data/Arabidopsis_gbff/A_thaliana_Ensembl_TAIR10_38_chr4_minus_xref.gbff' }, 'workspace_name': cls.wsName, 'genome_name': "arab", 'source': 'Ensembl', })[0]['genome_ref'] # preload with reference data data = json.load(open('data/rhodobacter.json')) # save to ws save_info = {'workspace': wsName, 'data': data, 'name': 'rhodobacter'} info = cls.gaa.save_one_genome_v1(save_info)['info'] cls.rhodobacter_ref = str(info[6]) + '/' + str(info[0]) + '/' + str( info[4]) print(('created rhodobacter test genome: ' + cls.rhodobacter_ref)) # save new genome assembly_file_path = os.path.join(cls.cfg['scratch'], 'e_coli_assembly.fasta') shutil.copy('data/e_coli/e_coli_assembly.fasta', assembly_file_path) au = AssemblyUtil(os.environ['SDK_CALLBACK_URL']) assembly_ref = au.save_assembly_from_fasta({ 'workspace_name': cls.wsName, 'assembly_name': 'ecoli.assembly', 'file': { 'path': assembly_file_path } }) data = json.load(open('data/e_coli/new_ecoli_genome.json')) data['assembly_ref'] = assembly_ref # save to ws save_info = { 'workspace': wsName, 'objects': [{ 'type': 'KBaseGenomes.Genome', 'data': data, 'name': 'new_ecoli' }] } result = cls.ws.save_objects(save_info) info = result[0] cls.ecoli_ref = str(info[6]) + '/' + str(info[0]) + '/' + str(info[4]) print(('created ecoli test genome: ' + cls.rhodobacter_ref)) # save a GFF file to shock, preload a genome pointing to it dfu = DataFileUtil(os.environ['SDK_CALLBACK_URL']) shutil.copy('data/rhodobacter.gtf', cls.cfg['scratch']) shock_file = dfu.file_to_shock({ 'file_path': os.path.join(cls.cfg['scratch'], 'rhodobacter.gtf'), 'make_handle': 1 }) data['gff_handle_ref'] = shock_file['handle']['hid'] # save to ws save_info['objects'][0]['name'] = 'rhodobacter_with_gff' result = cls.ws.save_objects(save_info) info = result[0] cls.rhodobacter_ref_with_gff = str(info[6]) + '/' + str( info[0]) + '/' + str(info[4]) print(('created rhodobacter test genome with handle: ' + cls.rhodobacter_ref_with_gff))