def test_from_pdb_file(self, bgl3_pdb_filename, amino_acid_list): pdb_s = PDBStructure.from_pdb_file(str(bgl3_pdb_filename)) with open(bgl3_pdb_filename) as f: pdb_f = PDBStructure.from_pdb_file(f) pdb_p = PDBStructure.from_pdb_file(bgl3_pdb_filename) pdb = PDBStructure(amino_acid_list) assert pdb.seq == pdb_s.seq assert pdb.seq == pdb_f.seq assert pdb.seq == pdb_p.seq
def get_PDB(self) -> None: """Construct from ParentAlignment using BLAST and PDB. The best structure is found by using BLAST to download candidate PDB sequences, then the sequence with the largest minimum identity to the parents is selected and set to the parent_alignment attribute. Parameters: parent_aln: Parent alignment used to query the PDB. Note that parent_aln[0] is used in the query and PDBStructure alignment. Raises: ValueError: If no matching PDB structure could be found. """ query_str = str(self.records[0].seq) pdb_srs = list(query_blast(query_str, 'pdbaa', 100)) # Find the PDB struct with largest minimum identity to the parents. pdb_min_map = {} for pdb_sr in pdb_srs: min_iden = min( calc_identity(parent, pdb_sr) for parent in self.records) pdb_min_map[pdb_sr.id] = min_iden try: best_id = max(pdb_min_map, key=lambda pdbid: pdb_min_map[pdbid]) except ValueError: raise RuntimeError('No best PDB could be found.') # Get the pdb_structure from rcsb. _, acc, chain = best_id.split('|') url = 'https://files.rcsb.org/view/' + acc + '.pdb' with urlopen(url) as f: pdb_structure = PDBStructure.from_pdb_file(f, chain=chain) self.pdb_structure = pdb_structure
return hash(repr(self)) def __repr__(self): in_edges = [e.in_node.index for e in self.in_edges] out_edges = [e.out_node.index for e in self.out_edges] ret = f'Node({self.col}, {self.index}, {self.breakpoint}, ' \ f'{in_edges=}, {out_edges=})' return ret if __name__ == '__main__': import sys loc = '../../tests/bgl3_sample/' pa = ParentAlignment.from_fasta(loc + 'bgl3_sequences.fasta') pdb = PDBStructure.from_pdb_file(loc + '1GNX.pdb') pa.pdb_structure = pdb sys.exit() ''' loc = '../tests/bgl3_sample/truncated/' pa = ParentAlignment.from_fasta(loc+'trunc.fasta') pdb = PDBStructure.from_pdb_file(loc+'trunc.pdb') ''' loc = '../../tests/bgl3_sample/' pa = ParentAlignment.from_fasta(loc + 'bgl3_sequences.fasta') pdb = PDBStructure.from_pdb_file(loc + '1GNX.pdb') pa.pdb_structure = pdb vector_overhangs = [(0, 'TATG'), (3, 'TGAG')] n = 4
def bgl3_PDBStructure(bgl3_pdb_filename): return PDBStructure.from_pdb_file(bgl3_pdb_filename)