def setUp(self): super(TestChainSequence, self).setUp() from csb.bio.structure import ProteinResidue, Chain chain = Chain('A', name='desc', accession='accn') for rank, char in enumerate('AB-CD', start=1): chain.residues.append(ProteinResidue(rank, char)) self.sequence = sequence.ChainSequence.create(chain) self.sequence.header = '>id desc' self.sequence.id = 'id'
def write_ensemble(X, filename, mol_ranges=None, center=True): """Writes a structure ensemble to a PDB file. :param X: coordinates of a structure ensemble :type X: :class:`numpy.ndarray` :param filename: file name of output PDB file :type filename: str :param mol_ranges: if writing structures consisting of several molecules, this specifies start and end beads of the single molecules. Example: [0, 9, 19] for two molecules of 10 beads each :type mol_ranges: :class:`numpy.ndarray` :param center: if True, aligns the centers of mass of all structures :type center: bool """ from csb.bio.structure import Atom, ProteinResidue, Chain, Structure, Ensemble from csb.bio.sequence import ProteinAlphabet if center: X -= X.mean(1)[:, None, :] if mol_ranges is None: mol_ranges = np.array([0, X.shape[1]]) ensemble = Ensemble() for i, x in enumerate(X): structure = Structure('') structure.model_id = i + 1 mol_coordinates = np.array([ x[start:end] for start, end in zip(mol_ranges[:-1], mol_ranges[1:]) ]) for j, mol in enumerate(mol_coordinates): structure.chains.append(Chain(chr(65 + j))) for k, y in enumerate(mol): atom = Atom(k + 1, 'CA', 'C', y) residue = ProteinResidue(k, 'ALA') residue.atoms.append(atom) structure.chains[chr(65 + j)].residues.append(residue) ensemble.models.append(structure) ensemble.to_pdb(filename)
def test(type): self.layer.residue = ProteinResidue(1, type=type)
def build_hmm(): hmm = ProfileHMM(units=ScoreUnits.Probability) factory = StateFactory() background = OrderedDict([(ProteinAlphabet.ALA, 0.02457563), (ProteinAlphabet.CYS, 0.00325358), (ProteinAlphabet.GLU, 0.01718016)]) emission = dict((aa, 1.0 / i) for i, aa in enumerate(background, start=1)) # States # Start / End hmm.start = State(States.Start) hmm.start_insertion = factory.create_insertion(background) hmm.end = State(States.End) # L1 match1 = factory.create_match(emission, background) insertion1 = factory.create_insertion(background) deletion1 = factory.create_deletion() states = { States.Match: match1, States.Insertion: insertion1, States.Deletion: deletion1 } layer1 = HMMLayer(1, ProteinResidue(1, ProteinAlphabet.ALA), states) hmm.layers.append(layer1) # L2 match2 = factory.create_match(emission, background) insertion2 = factory.create_insertion(background) deletion2 = factory.create_deletion() states = { States.Match: match2, States.Insertion: insertion2, States.Deletion: deletion2 } layer2 = HMMLayer(2, ProteinResidue(2, ProteinAlphabet.CYS), states) hmm.layers.append(layer2) # Transitions # start hmm.start.transitions.append(Transition(hmm.start, match1, 0.8)) hmm.start.transitions.append(Transition(hmm.start, deletion1, 0.1)) hmm.start.transitions.append( Transition(hmm.start, hmm.start_insertion, 0.1)) hmm.start_insertion.transitions.append( Transition(hmm.start_insertion, hmm.start_insertion, 0.5)) hmm.start_insertion.transitions.append( Transition(hmm.start_insertion, match1, 0.5)) # L1 match1.transitions.append(Transition(match1, match2, 0.8)) match1.transitions.append(Transition(match1, insertion1, 0.1)) match1.transitions.append(Transition(match1, deletion2, 0.1)) insertion1.transitions.append(Transition(insertion1, insertion1, 0.5)) insertion1.transitions.append(Transition(insertion1, match2, 0.5)) deletion1.transitions.append(Transition(deletion1, deletion2, 0.5)) deletion1.transitions.append(Transition(deletion1, match2, 0.5)) # L2 match2.transitions.append(Transition(match2, hmm.end, 0.9)) match2.transitions.append(Transition(match2, insertion2, 0.1)) insertion2.transitions.append(Transition(insertion2, insertion2, 0.5)) insertion2.transitions.append(Transition(insertion2, hmm.end, 0.5)) deletion2.transitions.append(Transition(deletion2, hmm.end, 1.0)) hmm.effective_matches = 10 hmm.version = 1.5 hmm.name = 'name' hmm.id = 'id' hmm.family = 'fam' hmm.length = ProfileLength(2, 2) return hmm