def test_pdbfix_templates(): template1_pdb_gz_filepath = get_installed_resource_filename(os.path.join('resources', 'KC1D_HUMAN_D0_4KB8_D.pdb.gz')) template1_pdb_filepath = os.path.join(ensembler.core.default_project_dirnames.templates_structures_resolved, 'KC1D_HUMAN_D0_4KB8_D.pdb') template2_pdb_gz_filepath = get_installed_resource_filename(os.path.join('resources', 'KC1D_HUMAN_D0_3UYS_D.pdb.gz')) template2_pdb_filepath = os.path.join(ensembler.core.default_project_dirnames.templates_structures_resolved, 'KC1D_HUMAN_D0_3UYS_D.pdb') with ensembler.utils.enter_temp_dir(): ensembler.utils.create_dir(ensembler.core.default_project_dirnames.templates_structures_resolved) ensembler.utils.create_dir(ensembler.core.default_project_dirnames.templates_structures_modeled_loops) with gzip.open(template1_pdb_gz_filepath) as template1_pdb_gz_file: with open(template1_pdb_filepath, 'w') as template1_pdb_file: contents = template1_pdb_gz_file.read() if type(contents) == bytes: contents = contents.decode('utf-8') template1_pdb_file.write(contents) with gzip.open(template2_pdb_gz_filepath) as template2_pdb_gz_file: with open(template2_pdb_filepath, 'w') as template2_pdb_file: contents = template2_pdb_gz_file.read() if type(contents) == bytes: contents = contents.decode('utf-8') template2_pdb_file.write(contents) template1 = Mock() template1.id = 'KC1D_HUMAN_D0_4KB8_D' template1.seq = 'LRVGNRYRLGRKIGSGSFGDIYLGTDIAAGEEVAIKLECVKTKHPQLHIESKIYKMMQGGVGIPTIRWCGAEGDYNVMVMELLGPSLEDLFNFCSRKFSLKTVLLLADQMISRIEYIHSKNFIHRDVKPDNFLMGLGKKGNLVYIIDFGLAKKYRDARTHQHIPYRENKNLTGTARYASINTHLGIEQSRRDDLESLGYVLMYFNLGSLPWQGLKAATKRQKYERISEKKMSTPIEVLCKGYPSEFATYLNFCRSLRFDDKPDYSYLRQLFRNLFHRQGFSYDYVFDWNMLKFGASRAADDAERERRDREERLRH' template2 = Mock() template2.id = 'KC1D_HUMAN_D0_3UYS_D' template2.seq = 'MELRVGNRYRLGRKIGSGSFGDIYLGTDIAAGEEVAIKLECVKTKHPQLHIESKIYKMMQGGVGIPTIRWCGAEGDYNVMVMELLGPSLEDLFNFCSRKFSLKTVLLLADQMISRIEYIHSKNFIHRDVKPDNFLMGLGKKGNLVYIIDFGLAKKYRDARTHQHIPYRENKNLTGTARYASINTHLGIEQSRRDDLESLGYVLMYFNLGSLPWQGLKAATKRQKYERISEKKMSTPIEVLCKGYPSEFATYLNFCRSLRFDDKPDYSYLRQLFRNLFHRQGFSYDYVFDWNMLK' templates = [template1, template2] missing_residues_list = pdbfix_templates(templates)
def _copy_modeling_files(self, target_level_files=None, template_level_files=None): for target in self.targets_list: for filename in target_level_files: shutil.copy( get_installed_resource_filename(os.path.join('example_project', default_project_dirnames.models, target, filename)), os.path.join(self.project_dir, default_project_dirnames.models, target) ) for template in self.templates_list: for filename in template_level_files: shutil.copy( get_installed_resource_filename(os.path.join('example_project', default_project_dirnames.models, target, template, filename)), os.path.join(self.project_dir, default_project_dirnames.models, target, template) )
def test_align_command(): ref_resources_dirpath = get_installed_resource_filename('example_project') with integrationtest_context(set_up_project_stage='templates_modeled_loops'): targets = ['KC1D_HUMAN_D0', 'EGFR_HUMAN_D0'] templates = ['KC1D_HUMAN_D0_4KB8_D', 'KC1D_HUMAN_D0_4HNF_A'] args = { '--targets': ','.join(targets), '--targetsfile': False, '--templates': ','.join(templates), '--templatesfile': False, '--verbose': False, } ensembler.cli_commands.align.dispatch(args) for target in targets: naln_files = 0 for dir, subdirs, files in os.walk(os.path.join(ensembler.core.default_project_dirnames.models, target)): for file in files: if file == 'alignment.pir': naln_files += 1 assert naln_files == len(templates) for target in targets: seqid_filepath = os.path.join(ensembler.core.default_project_dirnames.models, target, 'sequence-identities.txt') ref_seqid_filepath = os.path.join(ref_resources_dirpath, seqid_filepath) with open(seqid_filepath) as seqid_file: seqid_file_text = seqid_file.read() with open(ref_seqid_filepath) as ref_seqid_file: ref_seqid_file_text = ref_seqid_file.read() print(seqid_file_text) print(ref_seqid_file_text) assert seqid_file_text == ref_seqid_file_text
def templates_modeled_loops(self): self.templates_resolved() distutils.dir_util.copy_tree( get_installed_resource_filename( os.path.join('example_project', default_project_dirnames.templates_structures_modeled_loops) ), os.path.join(self.project_dir, default_project_dirnames.templates_structures_modeled_loops) )
def test_extract_residues_by_resnum_from_4CFE(): # 4CFE contains a 'TPO' residue pdb_input_filepath = get_installed_resource_filename(os.path.join('resources', '4CFE.pdb.gz')) template = Mock() template.chainid= 'A' template.resolved_pdbresnums = [str(x) for x in range(16, 269)] ofile = StringIO() ensembler.pdb.extract_residues_by_resnum(ofile, pdb_input_filepath, template) ofile.close()
def test_extract_residues_by_resnum_from_3HLL(): # 3HLL contains resnums '56A' and '93B' pdb_input_filepath = get_installed_resource_filename(os.path.join('resources', '3HLL.pdb.gz')) template = Mock() template.chainid = 'A' template.resolved_pdbresnums = [str(x) for x in range(24, 172) + range(183, 309)] template.resolved_pdbresnums[template.resolved_pdbresnums.index('56')] = '56A' template.resolved_pdbresnums[template.resolved_pdbresnums.index('93')] = '93B' ofile = StringIO() ensembler.pdb.extract_residues_by_resnum(ofile, pdb_input_filepath, template) ofile.close()
def test_extract_residues_by_resnum_output(): pdb_input_filepath = get_installed_resource_filename(os.path.join('resources', '3HLL.pdb.gz')) template = Mock() template.chainid = 'A' template.resolved_pdbresnums = [str(x) for x in range(24, 172) + range(183, 309)] template.resolved_pdbresnums[template.resolved_pdbresnums.index('56')] = '56A' template.resolved_pdbresnums[template.resolved_pdbresnums.index('93')] = '93B' ofile = StringIO() ensembler.pdb.extract_residues_by_resnum(ofile, pdb_input_filepath, template) ofile_text = ofile.getvalue() first_line = ofile_text[0: ofile_text.index('\n')] assert first_line == 'ATOM 175 N TYR A 24 50.812 43.410 19.390 1.00 38.55 N ' ofile.close()
def test_build_model(): template_filepath = get_installed_resource_filename(os.path.join('resources', 'mock_template.pdb')) aln_filepath = get_installed_resource_filename(os.path.join('resources', 'mock_template-alignment.pir')) with enter_temp_dir(): target = Mock() template = Mock() target_setup_data = Mock() target.id = 'mock_target' target.seq = 'YILGDTLGVGGKVKVGKH' template.id = 'mock_template' template.seq = 'YQNLSPVGSGGSVCAAFD' target_setup_data.target_starttime = datetime.datetime.utcnow() target_setup_data.models_target_dir = os.path.join(ensembler.core.default_project_dirnames.models, target.id) os.mkdir(ensembler.core.default_project_dirnames.models) model_dir = os.path.join(ensembler.core.default_project_dirnames.models, 'mock_target', 'mock_template') os.makedirs(model_dir) os.mkdir(ensembler.core.default_project_dirnames.templates) os.mkdir(ensembler.core.default_project_dirnames.templates_structures_resolved) shutil.copy(template_filepath, ensembler.core.default_project_dirnames.templates_structures_resolved) shutil.copy(aln_filepath, os.path.join(model_dir, 'alignment.pir')) ensembler.modeling.build_model(target, template, target_setup_data=target_setup_data) # Example model.pdb.gz contents (not testing this as it may be dependent # upon Modeller version as well as modelling stochasticity): # # ..EXPDTA THEORETICAL MODEL, MODELLER 9.12 2014/08/26 13:15:44 # REMARK 6 MODELLER OBJECTIVE FUNCTION: 326.6798 # REMARK 6 MODELLER BEST TEMPLATE % SEQ ID: 27.778 # ATOM 1 N TYR 1 48.812 50.583 13.949 1.00110.28 N # ATOM 2 CA TYR 1 49.070 50.334 15.387 1.00110.28 C model_filepath = os.path.join(target_setup_data.models_target_dir, template.id, 'model.pdb.gz') assert os.path.exists(model_filepath) assert os.path.getsize(model_filepath) > 0
def templates_resolved(self): self.targets() shutil.copy( get_installed_resource_filename( os.path.join('example_project', default_project_dirnames.templates, 'meta0.yaml') ), os.path.join(self.project_dir, default_project_dirnames.templates)) shutil.copy( get_installed_resource_filename( os.path.join('example_project', default_project_dirnames.templates, 'templates-resolved-seq.fa') ), os.path.join(self.project_dir, default_project_dirnames.templates)) shutil.copy( get_installed_resource_filename( os.path.join('example_project', default_project_dirnames.templates, 'templates-full-seq.fa') ), os.path.join(self.project_dir, default_project_dirnames.templates) ) distutils.dir_util.copy_tree( get_installed_resource_filename( os.path.join('example_project', default_project_dirnames.templates_structures_resolved) ), os.path.join(self.project_dir, default_project_dirnames.templates_structures_resolved) )
def test_pdbfix_ABL1_HUMAN_D0_2E2B_B(): template_pdb_gz_filepath = get_installed_resource_filename(os.path.join('resources', 'ABL1_HUMAN_D0_2E2B_B.pdb.gz')) template_pdb_filepath = os.path.join(ensembler.core.default_project_dirnames.templates_structures_resolved, 'ABL1_HUMAN_D0_2E2B_B.pdb') with ensembler.utils.enter_temp_dir(): ensembler.utils.create_dir(ensembler.core.default_project_dirnames.templates_structures_resolved) ensembler.utils.create_dir(ensembler.core.default_project_dirnames.templates_structures_modeled_loops) with gzip.open(template_pdb_gz_filepath) as template_pdb_gz_file: with open(template_pdb_filepath, 'w') as template_pdb_file: contents = template_pdb_gz_file.read() if type(contents) == bytes: contents = contents.decode('utf-8') template_pdb_file.write(contents) template = Mock() template.id = 'ABL1_HUMAN_D0_2E2B_B' template.seq = 'ITMKHKLGGGQYGEVYEGVWKKYSLTVAVKTLKEDTMEVEEFLKEAAVMKEIKHPNLVQLLGVCTREPPFYIITEFMTYGNLLDYLRECNRQEVNAVVLLYMATQISSAMEYLEKKNFIHRDLAARNCLVGENHLVKVADFGLSRLMTGDTYTAHAGAKFPIKWTAPESLAYNKFSIKSDVWAFGVLLWEIATYGMSPYPGIDLSQVYELLEKDYRMERPEGCPEKVYELMRACWQWNPSDRPSFAEIHQAFETMFQESSISDEVEKELGKQ' missing_residues = pdbfix_template(template) assert (0, 271) not in missing_residues assert missing_residues == { (0, 32): ['LYS', 'GLU', 'ASP', 'THR', 'MET'], (0, 139): ['ARG', 'LEU', 'MET', 'THR', 'GLY', 'ASP'], }
def targets(self): self.init() distutils.dir_util.copy_tree( get_installed_resource_filename(os.path.join('example_project', default_project_dirnames.targets)), os.path.join(self.project_dir, default_project_dirnames.targets) )
def init(self): ensembler.initproject.InitProject(self.project_dir) shutil.copy(get_installed_resource_filename(os.path.join('example_project', 'meta0.yaml')), self.project_dir)