Beispiel #1
0
    def test_json(self, amino_acid_list, bgl3_fasta_filename):
        in_pdb = PDBStructure(amino_acid_list)
        json_str = in_pdb.to_json()
        assert json_str
        out_pdb = PDBStructure.from_json(json_str)
        assert in_pdb.seq == out_pdb.seq
        with pytest.raises(AttributeError):
            out_pdb.unrenumbered_amino_acids
        with pytest.raises(AttributeError):
            out_pdb.renumbering_seq

        p1 = str(list(SeqIO.parse(bgl3_fasta_filename, 'fasta'))[0].seq)
        p1_short = p1[:400]
        renum_pdb = PDBStructure(amino_acid_list)
        renum_pdb.renumber(p1_short)
        json_str2 = renum_pdb.to_json()
        assert json_str2
        out_pdb2 = PDBStructure.from_json(json_str2)
        assert renum_pdb.seq == out_pdb2.seq
        assert renum_pdb.renumbering_seq == out_pdb2.renumbering_seq
Beispiel #2
0
    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
Beispiel #3
0
    def test_renumbering(self, bgl3_fasta_filename, amino_acid_list):
        # TODO: Probably want to do this one with multiple PDBs.
        assert amino_acid_list

        # Test PDBStructure init.
        pdb = PDBStructure(amino_acid_list)
        assert pdb.amino_acids
        with pytest.raises(AttributeError):
            pdb.unrenumbered_amino_acids
        with pytest.raises(AttributeError):
            pdb.renumbering_seq
        assert pdb.seq
        assert pdb.contacts

        renum_pdb = copy.deepcopy(pdb)
        p1 = str(list(SeqIO.parse(bgl3_fasta_filename, 'fasta'))[0].seq)
        renum_pdb.renumber(p1)
        assert len(pdb.amino_acids) == len(renum_pdb.amino_acids) \
            + len(renum_pdb.unrenumbered_amino_acids)
        # Technically this could be true, but not for this PDB.
        assert pdb.seq != renum_pdb.seq
        assert renum_pdb.renumbering_seq == p1
        assert pdb.contacts
        # Most important!
        assert all(aa == p1[i] for i, aa in enumerate(renum_pdb.seq)
                   if aa != '-')

        renum_pdb.derenumber()
        with pytest.raises(AttributeError):
            pdb.unrenumbered_amino_acids
        with pytest.raises(AttributeError):
            pdb.renumbering_seq
        assert pdb.seq == renum_pdb.seq
        assert len(pdb.contacts) == len(renum_pdb.contacts)
        pdb_contacts = set(pdb.contacts)
        for contact in renum_pdb.contacts:
            assert contact in pdb_contacts

        # Derenumbering when not renumbered.
        with pytest.raises(AttributeError):
            pdb.derenumber()
Beispiel #4
0
    def test_double_renum(self, bgl3_fasta_filename, amino_acid_list):
        """Same as test_renumbering but double renum with two reduced p1."""
        pdb = PDBStructure(amino_acid_list)
        p1 = str(list(SeqIO.parse(bgl3_fasta_filename, 'fasta'))[0].seq)

        renum_pdb = copy.deepcopy(pdb)
        p1_short = p1[:400]
        renum_pdb.renumber(p1_short)
        assert renum_pdb.unrenumbered_amino_acids  # Should be occupied now.
        assert len(pdb.amino_acids) == len(renum_pdb.amino_acids) \
            + len(renum_pdb.unrenumbered_amino_acids)
        assert pdb.seq != renum_pdb.seq
        assert renum_pdb.renumbering_seq == p1_short
        assert all(aa == p1_short[i] for i, aa in enumerate(renum_pdb.seq)
                   if aa != '-')

        # Renumber again.
        p1_middle_removed = p1_short[:150] + p1_short[250:]
        renum_pdb.renumber(p1_middle_removed)
        assert renum_pdb.unrenumbered_amino_acids
        assert len(pdb.amino_acids) == len(renum_pdb.amino_acids) \
            + len(renum_pdb.unrenumbered_amino_acids)
        assert pdb.seq != renum_pdb.seq
        assert renum_pdb.renumbering_seq == p1_middle_removed
        assert all(aa == p1_middle_removed[i] for i, aa
                   in enumerate(renum_pdb.seq) if aa != '-')

        renum_pdb.derenumber()
        with pytest.raises(AttributeError):
            pdb.unrenumbered_amino_acids
        with pytest.raises(AttributeError):
            pdb.renumbering_seq
        assert pdb.seq == renum_pdb.seq
        assert len(pdb.contacts) == len(renum_pdb.contacts)
        # pdb_contacts = set(pdb.contacts)
        for contact in renum_pdb.contacts:
            assert contact in pdb.contacts
Beispiel #5
0
    def invalid_init(self, bgl3_fasta_filename, amino_acid_list):
        p1 = str(list(SeqIO.parse(bgl3_fasta_filename, 'fasta'))[0].seq)
        with pytest.raises(ValueError):
            PDBStructure(amino_acid_list, None, p1)

        p1_short = p1[:400]
        renum_pdb = PDBStructure(amino_acid_list)
        renum_pdb.renumber(p1_short)
        amino_acids = renum_pdb.amino_acids
        unrenum = renum_pdb.unrenumbered_amino_acids
        with pytest.raises(ValueError):
            PDBStructure(amino_acids, unrenum, None)

        # Empty unrenumbered_amino_acids.
        with pytest.raises(ValueError):
            PDBStructure(amino_acids, [], p1_short)

        # p1 too short.
        with pytest.raises(ValueError):
            PDBStructure(amino_acids, unrenum, p1_short[:200])

        # p1 too long.
        with pytest.raises(ValueError):
            PDBStructure(amino_acids, unrenum, p1)